summaryrefslogtreecommitdiff
path: root/rust/grains/tests/grains.rs
diff options
context:
space:
mode:
authorDimitri Sokolyuk <sokolyuk@gmail.com>2024-05-31 23:42:26 +0200
committerDimitri Sokolyuk <sokolyuk@gmail.com>2024-05-31 23:42:26 +0200
commit45530375a9515ac2b4091ffe277221f9380e68f2 (patch)
treeb3d65af76b52a36b86c0eee96e7f5c85963055ee /rust/grains/tests/grains.rs
parent69223c7bccc5280a3399b82794eb65d0691eece4 (diff)
Sovle grains
Diffstat (limited to 'rust/grains/tests/grains.rs')
-rw-r--r--rust/grains/tests/grains.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/rust/grains/tests/grains.rs b/rust/grains/tests/grains.rs
new file mode 100644
index 0000000..a2a4ba9
--- /dev/null
+++ b/rust/grains/tests/grains.rs
@@ -0,0 +1,55 @@
+fn process_square_case(input: u32, expected: u64) {
+ assert_eq!(grains::square(input), expected);
+}
+
+#[test]
+fn one() {
+ process_square_case(1, 1);
+}
+
+#[test]
+fn two() {
+ process_square_case(2, 2);
+}
+
+#[test]
+fn three() {
+ process_square_case(3, 4);
+}
+
+#[test]
+fn four() {
+ process_square_case(4, 8);
+}
+
+#[test]
+fn sixteen() {
+ process_square_case(16, 32_768);
+}
+
+#[test]
+fn thirty_two() {
+ process_square_case(32, 2_147_483_648);
+}
+
+#[test]
+fn sixty_four() {
+ process_square_case(64, 9_223_372_036_854_775_808);
+}
+
+#[test]
+#[should_panic(expected = "Square must be between 1 and 64")]
+fn square_0_raises_an_exception() {
+ grains::square(0);
+}
+
+#[test]
+#[should_panic(expected = "Square must be between 1 and 64")]
+fn square_greater_than_64_raises_an_exception() {
+ grains::square(65);
+}
+
+#[test]
+fn returns_the_total_number_of_grains_on_the_board() {
+ assert_eq!(grains::total(), 18_446_744_073_709_551_615);
+}