Add tests for from_iso & to_iso

This commit is contained in:
Guilhem 2022-06-14 18:04:18 +02:00
parent 7c3ffb7ecf
commit 51849c987e

View File

@ -11,7 +11,7 @@ pub enum TeethKind {
Premolar, Premolar,
Molar, Molar,
} }
#[derive(PartialEq, Clone, Copy)] #[derive(PartialEq, Clone, Copy, Debug)]
pub enum QuadrantKind { pub enum QuadrantKind {
TopLeft, TopLeft,
TopRight, TopRight,
@ -91,4 +91,94 @@ impl Teeth {
}; };
quadrant_number.to_string() + &self.number.to_string() quadrant_number.to_string() + &self.number.to_string()
} }
#[cfg(test)]
mod test {
use super::*;
macro_rules! to_iso {
($name:ident, $quadrant:expr,$number:expr, $permanent:expr, $iso:expr) => {
#[test]
fn $name() {
let teeth = Teeth {
quadrant: $quadrant,
number: $number,
permanent: $permanent,
};
assert_eq!(teeth.to_iso(), $iso);
}
};
}
macro_rules! from_iso {
($name:ident, $iso:expr, $quadrant:expr,$number:expr, $permanent:expr) => {
#[test]
fn $name() {
let teeth = Teeth::from_iso($iso);
assert_eq!(teeth.quadrant, $quadrant);
assert_eq!(teeth.number, $number);
assert_eq!(teeth.permanent, $permanent);
}
};
}
macro_rules! from_iso_fail {
($name:ident, $iso:expr) => {
#[test]
#[should_panic]
fn $name() {
Teeth::from_iso($iso);
}
};
}
to_iso!(to_iso_11, QuadrantKind::TopLeft, 1, true, "11");
to_iso!(to_iso_18, QuadrantKind::TopLeft, 8, true, "18");
to_iso!(to_iso_21, QuadrantKind::TopRight, 1, true, "21");
to_iso!(to_iso_28, QuadrantKind::TopRight, 8, true, "28");
to_iso!(to_iso_31, QuadrantKind::BottomRight, 1, true, "31");
to_iso!(to_iso_38, QuadrantKind::BottomRight, 8, true, "38");
to_iso!(to_iso_41, QuadrantKind::BottomLeft, 1, true, "41");
to_iso!(to_iso_48, QuadrantKind::BottomLeft, 8, true, "48");
to_iso!(to_iso_51, QuadrantKind::TopLeft, 1, false, "51");
to_iso!(to_iso_55, QuadrantKind::TopLeft, 5, false, "55");
to_iso!(to_iso_61, QuadrantKind::TopRight, 1, false, "61");
to_iso!(to_iso_65, QuadrantKind::TopRight, 5, false, "65");
to_iso!(to_iso_71, QuadrantKind::BottomRight, 1, false, "71");
to_iso!(to_iso_75, QuadrantKind::BottomRight, 5, false, "75");
to_iso!(to_iso_81, QuadrantKind::BottomLeft, 1, false, "81");
to_iso!(to_iso_85, QuadrantKind::BottomLeft, 5, false, "85");
from_iso!(from_iso_11, "11", QuadrantKind::TopLeft, 1, true);
from_iso!(from_iso_18, "18", QuadrantKind::TopLeft, 8, true);
from_iso!(from_iso_21, "21", QuadrantKind::TopRight, 1, true);
from_iso!(from_iso_28, "28", QuadrantKind::TopRight, 8, true);
from_iso!(from_iso_31, "31", QuadrantKind::BottomRight, 1, true);
from_iso!(from_iso_38, "38", QuadrantKind::BottomRight, 8, true);
from_iso!(from_iso_41, "41", QuadrantKind::BottomLeft, 1, true);
from_iso!(from_iso_48, "48", QuadrantKind::BottomLeft, 8, true);
from_iso!(from_iso_51, "51", QuadrantKind::TopLeft, 1, false);
from_iso!(from_iso_55, "55", QuadrantKind::TopLeft, 5, false);
from_iso!(from_iso_61, "61", QuadrantKind::TopRight, 1, false);
from_iso!(from_iso_65, "65", QuadrantKind::TopRight, 5, false);
from_iso!(from_iso_71, "71", QuadrantKind::BottomRight, 1, false);
from_iso!(from_iso_75, "75", QuadrantKind::BottomRight, 5, false);
from_iso!(from_iso_81, "81", QuadrantKind::BottomLeft, 1, false);
from_iso!(from_iso_85, "85", QuadrantKind::BottomLeft, 5, false);
from_iso_fail!(from_iso_fail_10, "10");
from_iso_fail!(from_iso_fail_19, "19");
from_iso_fail!(from_iso_fail_20, "20");
from_iso_fail!(from_iso_fail_29, "29");
from_iso_fail!(from_iso_fail_30, "30");
from_iso_fail!(from_iso_fail_39, "39");
from_iso_fail!(from_iso_fail_40, "40");
from_iso_fail!(from_iso_fail_49, "49");
from_iso_fail!(from_iso_fail_50, "50");
from_iso_fail!(from_iso_fail_56, "56");
from_iso_fail!(from_iso_fail_60, "60");
from_iso_fail!(from_iso_fail_66, "66");
from_iso_fail!(from_iso_fail_70, "70");
from_iso_fail!(from_iso_fail_76, "76");
from_iso_fail!(from_iso_fail_80, "80");
from_iso_fail!(from_iso_fail_86, "86");
} }