Skip to content

Commit

Permalink
Add tests for domain
Browse files Browse the repository at this point in the history
  • Loading branch information
treiher committed Dec 5, 2024
1 parent a5004db commit 7c479d7
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions frontend/src/domain.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{collections::HashSet, slice::Iter};

#[derive(Clone, Copy, Eq, Hash, PartialEq)]
#[cfg_attr(test, derive(Debug))]
pub enum Muscle {
// Neck
Neck = 1,
Expand Down Expand Up @@ -143,3 +144,54 @@ impl ExerciseFilter {
self.muscles.is_empty()
}
}

#[cfg(test)]
mod tests {
use super::*;

use pretty_assertions::assert_eq;

#[test]
fn test_muscle_id() {
for muscle in Muscle::iter() {
assert_eq!(Muscle::from_repr(Muscle::id(*muscle)).unwrap(), *muscle);
}

assert_eq!(Muscle::from_repr(u8::MAX), None);
}

#[test]
fn test_muscle_name() {
let mut names = HashSet::new();

for muscle in Muscle::iter() {
let name = Muscle::name(*muscle);

assert!(!name.is_empty());
assert!(!names.contains(name));

names.insert(name);
}
}

#[test]
fn test_muscle_description() {
let mut descriptions = HashSet::new();

for muscle in Muscle::iter() {
let description = Muscle::description(*muscle);

assert!(description.is_empty() || !descriptions.contains(description));

descriptions.insert(description);
}
}

#[test]
fn test_exercise_filter_is_empty() {
assert!(ExerciseFilter {
muscles: HashSet::new()
}
.is_empty());
}
}

0 comments on commit 7c479d7

Please sign in to comment.