diff --git a/exercises/practice/grains/.meta/test_template.tera b/exercises/practice/grains/.meta/test_template.tera new file mode 100644 index 000000000..23590743b --- /dev/null +++ b/exercises/practice/grains/.meta/test_template.tera @@ -0,0 +1,22 @@ +use grains::*; + +{% for test in cases.0.cases %} +#[test] +#[ignore] +{% if test.expected is object -%} +#[should_panic] +{% endif -%} +fn {{ test.description | make_ident }}() { + {% if test.expected is number -%} + assert_eq!(square({{ test.input.square }}), {{ test.expected | fmt_num }}); + {% else %} + square({{ test.input.square }}); + {% endif -%} +} +{% endfor -%} + +#[test] +#[ignore] +fn returns_the_total_number_of_grains_on_the_board() { + assert_eq!(grains::total(), 18_446_744_073_709_551_615); +} diff --git a/exercises/practice/grains/.meta/tests.toml b/exercises/practice/grains/.meta/tests.toml index 442dbacd9..f1ef18b9b 100644 --- a/exercises/practice/grains/.meta/tests.toml +++ b/exercises/practice/grains/.meta/tests.toml @@ -28,6 +28,8 @@ description = "square 0 raises an exception" [61974483-eeb2-465e-be54-ca5dde366453] description = "negative square raises an exception" +include = false +comment = "u64 cannot be negative" [a95e4374-f32c-45a7-a10d-ffec475c012f] description = "square greater than 64 raises an exception" diff --git a/exercises/practice/grains/tests/grains.rs b/exercises/practice/grains/tests/grains.rs index 51e08b643..ff7b18b09 100644 --- a/exercises/practice/grains/tests/grains.rs +++ b/exercises/practice/grains/tests/grains.rs @@ -1,62 +1,59 @@ -fn process_square_case(input: u32, expected: u64) { - assert_eq!(grains::square(input), expected); -} +use grains::*; #[test] -fn one() { - process_square_case(1, 1); +fn grains_on_square_1() { + assert_eq!(square(1), 1); } #[test] #[ignore] -fn two() { - process_square_case(2, 2); +fn grains_on_square_2() { + assert_eq!(square(2), 2); } #[test] #[ignore] -fn three() { - process_square_case(3, 4); +fn grains_on_square_3() { + assert_eq!(square(3), 4); } #[test] #[ignore] -fn four() { - process_square_case(4, 8); +fn grains_on_square_4() { + assert_eq!(square(4), 8); } #[test] #[ignore] -fn sixteen() { - process_square_case(16, 32_768); +fn grains_on_square_16() { + assert_eq!(square(16), 32_768); } #[test] #[ignore] -fn thirty_two() { - process_square_case(32, 2_147_483_648); +fn grains_on_square_32() { + assert_eq!(square(32), 2_147_483_648); } #[test] #[ignore] -fn sixty_four() { - process_square_case(64, 9_223_372_036_854_775_808); +fn grains_on_square_64() { + assert_eq!(square(64), 9_223_372_036_854_775_808); } #[test] #[ignore] -#[should_panic(expected = "Square must be between 1 and 64")] -fn square_0_raises_an_exception() { - grains::square(0); +#[should_panic] +fn square_0_is_invalid() { + square(0); } #[test] #[ignore] -#[should_panic(expected = "Square must be between 1 and 64")] -fn square_greater_than_64_raises_an_exception() { - grains::square(65); +#[should_panic] +fn square_greater_than_64_is_invalid() { + square(65); } - #[test] #[ignore] fn returns_the_total_number_of_grains_on_the_board() {