fix: Rename teeth in tooth
This commit is contained in:
parent
efc028fb0d
commit
144c56b517
66
src/lib.rs
66
src/lib.rs
@ -19,34 +19,34 @@ pub enum QuadrantKind {
|
|||||||
BottomRight,
|
BottomRight,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Teeth {
|
pub struct Tooth {
|
||||||
quadrant: QuadrantKind,
|
quadrant: QuadrantKind,
|
||||||
number: u8,
|
number: u8,
|
||||||
permanent: bool,
|
permanent: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Teeth {
|
impl Tooth {
|
||||||
pub fn new(number: u8, quadrant: QuadrantKind, permanent: bool) -> Result<Teeth, String> {
|
pub fn new(number: u8, quadrant: QuadrantKind, permanent: bool) -> Result<Tooth, String> {
|
||||||
if let Err(err) = Teeth::check_teeth_number(number, permanent) {
|
if let Err(err) = Tooth::check_tooth_number(number, permanent) {
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Teeth {
|
Ok(Tooth {
|
||||||
number,
|
number,
|
||||||
quadrant,
|
quadrant,
|
||||||
permanent,
|
permanent,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_teeth_number(number: u8, permanent: bool) -> Result<(), String> {
|
fn check_tooth_number(number: u8, permanent: bool) -> Result<(), String> {
|
||||||
if permanent && (number < 1 || number > 8) {
|
if permanent && (number < 1 || number > 8) {
|
||||||
Err(format!(
|
Err(format!(
|
||||||
"Permanent teeth {} should be in range [1; 8]",
|
"Permanent tooth {} should be in range [1; 8]",
|
||||||
number
|
number
|
||||||
))
|
))
|
||||||
} else if !permanent && (number < 1 || number > 5) {
|
} else if !permanent && (number < 1 || number > 5) {
|
||||||
Err(format!(
|
Err(format!(
|
||||||
"Primary teeth {} should be in range [1; 5]",
|
"Primary tooth {} should be in range [1; 5]",
|
||||||
number
|
number
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
@ -79,17 +79,17 @@ impl Teeth {
|
|||||||
x => return Err(format!("Quadrant value {} not included in range [1; 8]", x)),
|
x => return Err(format!("Quadrant value {} not included in range [1; 8]", x)),
|
||||||
};
|
};
|
||||||
|
|
||||||
let teeth_string = char_iter.next().unwrap();
|
let tooth_string = char_iter.next().unwrap();
|
||||||
let teeth_number_option = teeth_string.to_digit(10);
|
let tooth_number_option = tooth_string.to_digit(10);
|
||||||
|
|
||||||
if teeth_number_option.is_none() {
|
if tooth_number_option.is_none() {
|
||||||
return Err(format!("{} is not a number", teeth_string));
|
return Err(format!("{} is not a number", tooth_string));
|
||||||
}
|
}
|
||||||
let number = teeth_number_option.unwrap() as u8;
|
let number = tooth_number_option.unwrap() as u8;
|
||||||
if let Err(err) = Teeth::check_teeth_number(number, permanent) {
|
if let Err(err) = Tooth::check_tooth_number(number, permanent) {
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
Ok(Teeth {
|
Ok(Tooth {
|
||||||
quadrant,
|
quadrant,
|
||||||
permanent,
|
permanent,
|
||||||
number,
|
number,
|
||||||
@ -122,29 +122,29 @@ impl Teeth {
|
|||||||
|
|
||||||
if permanent && (uns < 1 || uns > 32) {
|
if permanent && (uns < 1 || uns > 32) {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"UNS permanent teeth has to be in range [1; 32] (currently {})",
|
"UNS permanent tooth has to be in range [1; 32] (currently {})",
|
||||||
uns
|
uns
|
||||||
));
|
));
|
||||||
} else if !permanent && (uns < 1 || uns > 20) {
|
} else if !permanent && (uns < 1 || uns > 20) {
|
||||||
return Err(format!("UNS primary teeth has to be in range [A; T]"));
|
return Err(format!("UNS primary tooth has to be in range [A; T]"));
|
||||||
}
|
}
|
||||||
let max = Teeth::quadrant_max(permanent);
|
let max = Tooth::quadrant_max(permanent);
|
||||||
let quadrant = match ((uns - 1) / max) + 1 {
|
let quadrant = match ((uns - 1) / max) + 1 {
|
||||||
1 => QuadrantKind::TopLeft,
|
1 => QuadrantKind::TopLeft,
|
||||||
2 => QuadrantKind::TopRight,
|
2 => QuadrantKind::TopRight,
|
||||||
3 => QuadrantKind::BottomRight,
|
3 => QuadrantKind::BottomRight,
|
||||||
4 => QuadrantKind::BottomLeft,
|
4 => QuadrantKind::BottomLeft,
|
||||||
_ => return Err(format!("UNS teeth value not in range")),
|
_ => return Err(format!("UNS tooth value not in range")),
|
||||||
};
|
};
|
||||||
let number = if quadrant == QuadrantKind::TopRight || quadrant == QuadrantKind::BottomLeft {
|
let number = if quadrant == QuadrantKind::TopRight || quadrant == QuadrantKind::BottomLeft {
|
||||||
((uns - 1) % max) + 1
|
((uns - 1) % max) + 1
|
||||||
} else {
|
} else {
|
||||||
max - ((uns - 1) % max)
|
max - ((uns - 1) % max)
|
||||||
};
|
};
|
||||||
if let Err(err) = Teeth::check_teeth_number(number, permanent) {
|
if let Err(err) = Tooth::check_tooth_number(number, permanent) {
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
Ok(Teeth {
|
Ok(Tooth {
|
||||||
quadrant,
|
quadrant,
|
||||||
number,
|
number,
|
||||||
permanent,
|
permanent,
|
||||||
@ -152,7 +152,7 @@ impl Teeth {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_uns(&self) -> String {
|
pub fn to_uns(&self) -> String {
|
||||||
let max = Teeth::quadrant_max(self.permanent);
|
let max = Tooth::quadrant_max(self.permanent);
|
||||||
let value: u8 = match (&self.quadrant, self.number) {
|
let value: u8 = match (&self.quadrant, self.number) {
|
||||||
(QuadrantKind::TopLeft, x) => max - x + 1,
|
(QuadrantKind::TopLeft, x) => max - x + 1,
|
||||||
(QuadrantKind::TopRight, x) => x + max,
|
(QuadrantKind::TopRight, x) => x + max,
|
||||||
@ -187,9 +187,9 @@ impl Teeth {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let teeth_string = &value[2..3];
|
let tooth_string = &value[2..3];
|
||||||
|
|
||||||
let (number, permanent) = match teeth_string {
|
let (number, permanent) = match tooth_string {
|
||||||
"1" => (1, true),
|
"1" => (1, true),
|
||||||
"2" => (2, true),
|
"2" => (2, true),
|
||||||
"3" => (3, true),
|
"3" => (3, true),
|
||||||
@ -210,10 +210,10 @@ impl Teeth {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Err(err) = Teeth::check_teeth_number(number, permanent) {
|
if let Err(err) = Tooth::check_tooth_number(number, permanent) {
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
Ok(Teeth {
|
Ok(Tooth {
|
||||||
quadrant,
|
quadrant,
|
||||||
permanent,
|
permanent,
|
||||||
number,
|
number,
|
||||||
@ -245,12 +245,12 @@ mod test {
|
|||||||
($name:ident, $func:ident, $quadrant:expr,$number:expr, $permanent:expr, $value:expr) => {
|
($name:ident, $func:ident, $quadrant:expr,$number:expr, $permanent:expr, $value:expr) => {
|
||||||
#[test]
|
#[test]
|
||||||
fn $name() {
|
fn $name() {
|
||||||
let teeth = Teeth {
|
let tooth = Tooth {
|
||||||
quadrant: $quadrant,
|
quadrant: $quadrant,
|
||||||
number: $number,
|
number: $number,
|
||||||
permanent: $permanent,
|
permanent: $permanent,
|
||||||
};
|
};
|
||||||
assert_eq!(teeth.$func(), $value);
|
assert_eq!(tooth.$func(), $value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -259,11 +259,11 @@ mod test {
|
|||||||
($name:ident, $func:ident, $value:expr, $quadrant:expr,$number:expr, $permanent:expr) => {
|
($name:ident, $func:ident, $value:expr, $quadrant:expr,$number:expr, $permanent:expr) => {
|
||||||
#[test]
|
#[test]
|
||||||
fn $name() {
|
fn $name() {
|
||||||
let teeth = Teeth::$func($value).unwrap();
|
let tooth = Tooth::$func($value).unwrap();
|
||||||
|
|
||||||
assert_eq!(teeth.quadrant, $quadrant);
|
assert_eq!(tooth.quadrant, $quadrant);
|
||||||
assert_eq!(teeth.number, $number);
|
assert_eq!(tooth.number, $number);
|
||||||
assert_eq!(teeth.permanent, $permanent);
|
assert_eq!(tooth.permanent, $permanent);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -272,7 +272,7 @@ mod test {
|
|||||||
($name:ident, $func:ident, $value:expr) => {
|
($name:ident, $func:ident, $value:expr) => {
|
||||||
#[test]
|
#[test]
|
||||||
fn $name() {
|
fn $name() {
|
||||||
assert!(Teeth::$func($value).is_err());
|
assert!(Tooth::$func($value).is_err());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user