1
Fork 0
romantic/tests/custom.rs

39 lines
1.0 KiB
Rust

use romantic::Roman;
use test_case::test_case;
#[test_case(0, ""; "empty")]
#[test_case(1, "A"; "one")]
#[test_case(2, "AA"; "two")]
#[test_case(3, "AAA"; "three")]
#[test_case(4, "AB"; "four")]
#[test_case(5, "B"; "five")]
#[test_case(6, "BA"; "six")]
#[test_case(7, "BAA"; "seven")]
#[test_case(8, "BAAA"; "eight")]
#[test_case(9, "AC"; "nine")]
#[test_case(10, "C"; "ten")]
fn test_to_string<T: num::PrimInt + num::Signed + ToString>(
input: T,
expected: &str,
) {
let custom = Roman::new(&['A', 'B', 'C']);
assert_eq!(custom.to_string(input).unwrap(), expected);
}
#[test_case("", 0; "empty")]
#[test_case("A", 1; "one")]
#[test_case("AA", 2; "two")]
#[test_case("AAA", 3; "three")]
#[test_case("AB", 4; "four")]
#[test_case("B", 5; "five")]
#[test_case("BA", 6; "six")]
#[test_case("BAA", 7; "seven")]
#[test_case("BAAA", 8; "eight")]
#[test_case("AC", 9; "nine")]
#[test_case("C", 10; "ten")]
fn test_from_str(input: &str, expected: i32) {
let custom = Roman::new(&['A', 'B', 'C', 'D']);
assert_eq!(custom.from_str::<i32>(input).unwrap(), expected);
}