-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.rs
55 lines (46 loc) · 1.24 KB
/
config.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use std::collections::HashMap;
use std::sync::Mutex;
use once_cell::sync::Lazy;
static CONFIG: Lazy<Mutex<HashMap<String, String>>> = Lazy::new(|| Mutex::new(HashMap::new()));
pub fn init(paces: HashMap<String, String>) {
let mut config = CONFIG.lock().unwrap();
*config = paces;
}
#[cfg(not(test))]
pub fn get_pace(effort: &str) -> String {
CONFIG.lock().unwrap()[effort].clone()
}
#[cfg(not(test))]
pub fn get_intensities() -> Vec<String> {
CONFIG.lock().unwrap().keys().cloned().collect()
}
// unit tests use a hard-coded config
#[cfg(test)]
pub fn get_pace(effort: &str) -> &str {
let inline_config: HashMap<&str, &str> = HashMap::from([
("E", "6:00"),
("M", "5:00"),
("T", "4:30"),
("I", "4:00"),
("H", "4:00"),
("R", "3:30"),
("jg", "8:00"),
("jog", "8:00"),
("rst", "15:00"),
("rest", "15:00"),
]);
inline_config[effort]
}
#[cfg(test)]
pub fn get_intensities() -> Vec<String> {
let intensities = ["E", "M", "T", "I", "H", "R", "jg", "jog", "rst", "rest"];
intensities.iter().map(|s| s.to_string()).collect()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_get_pace() {
assert_eq!("4:00", get_pace("H"));
}
}