2022-04-10 14:11:14 +00:00
|
|
|
use romantic::Roman;
|
|
|
|
|
|
|
|
use test_case::test_case;
|
|
|
|
|
|
|
|
#[test_case(0, ""; "empty")]
|
|
|
|
#[test_case(3888, "MMMDCCCLXXXVIII"; "all characters")]
|
|
|
|
#[test_case(3999, "MMMCMXCIX"; "maximum")]
|
2024-01-25 12:21:29 +00:00
|
|
|
#[test_case(1, "I"; "one")]
|
|
|
|
#[test_case(2, "II"; "two")]
|
|
|
|
#[test_case(3, "III"; "three")]
|
|
|
|
#[test_case(4, "IV"; "four")]
|
|
|
|
#[test_case(5, "V"; "five")]
|
|
|
|
#[test_case(6, "VI"; "six")]
|
|
|
|
#[test_case(7, "VII"; "seven")]
|
|
|
|
#[test_case(8, "VIII"; "eight")]
|
|
|
|
#[test_case(9, "IX"; "nine")]
|
2022-04-10 14:11:14 +00:00
|
|
|
#[test_case(10, "X"; "ten")]
|
|
|
|
fn test_to_string<T: num::PrimInt + num::Signed + ToString>(
|
|
|
|
input: T,
|
|
|
|
expected: &str,
|
|
|
|
) {
|
|
|
|
assert_eq!(Roman::default().to_string(input).unwrap(), expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test_case("", 0; "empty")]
|
|
|
|
#[test_case("MMMDCCCLXXXVIII", 3888; "complicated")]
|
|
|
|
#[test_case("MMMCMXCIX", 3999; "maximum")]
|
2024-01-25 12:21:29 +00:00
|
|
|
#[test_case("I", 1; "one")]
|
|
|
|
#[test_case("II", 2; "two")]
|
|
|
|
#[test_case("III", 3; "three")]
|
|
|
|
#[test_case("IV", 4; "four")]
|
|
|
|
#[test_case("V", 5; "five")]
|
|
|
|
#[test_case("VI", 6; "six")]
|
|
|
|
#[test_case("VII", 7; "seven")]
|
|
|
|
#[test_case("VIII", 8; "eight")]
|
|
|
|
#[test_case("IX", 9; "nine")]
|
2022-04-10 14:11:14 +00:00
|
|
|
#[test_case("X", 10; "ten")]
|
|
|
|
fn test_from_str(input: &str, expected: i32) {
|
|
|
|
assert_eq!(Roman::default().from_str::<i32>(input).unwrap(), expected);
|
|
|
|
}
|