aboutsummaryrefslogtreecommitdiff
path: root/grains/tests/grains.rs
diff options
context:
space:
mode:
authorFederico I <git@federicoigne.com>2020-03-18 17:56:11 +0000
committerFederico Igne <git@federicoigne.com>2021-11-03 18:54:52 +0000
commit204318ac52453b7d365cf0cd60c3fbeaacf4edaa (patch)
tree50e4b0756dc51e6227d884f800701454a481f305 /grains/tests/grains.rs
parent581450f9b2bfba9d9ff9efdab6776b0d4fdbae14 (diff)
downloadexercism-204318ac52453b7d365cf0cd60c3fbeaacf4edaa.tar.gz
exercism-204318ac52453b7d365cf0cd60c3fbeaacf4edaa.zip
[rust] Grains
Diffstat (limited to 'grains/tests/grains.rs')
-rw-r--r--grains/tests/grains.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/grains/tests/grains.rs b/grains/tests/grains.rs
new file mode 100644
index 0000000..405eb4d
--- /dev/null
+++ b/grains/tests/grains.rs
@@ -0,0 +1,65 @@
1use grains;
2
3fn process_square_case(input: u32, expected: u64) {
4 assert_eq!(grains::square(input), expected);
5}
6
7#[test]
8/// 1
9fn test_1() {
10 process_square_case(1, 1);
11}
12
13#[test]
14/// 2
15fn test_2() {
16 process_square_case(2, 2);
17}
18
19#[test]
20/// 3
21fn test_3() {
22 process_square_case(3, 4);
23}
24
25#[test]
26/// 4
27fn test_4() {
28 process_square_case(4, 8);
29}
30
31//NEW
32#[test]
33/// 16
34fn test_16() {
35 process_square_case(16, 32_768);
36}
37
38#[test]
39/// 32
40fn test_32() {
41 process_square_case(32, 2_147_483_648);
42}
43
44#[test]
45/// 64
46fn test_64() {
47 process_square_case(64, 9_223_372_036_854_775_808);
48}
49
50#[test]
51#[should_panic(expected = "Square must be between 1 and 64")]
52fn test_square_0_raises_an_exception() {
53 grains::square(0);
54}
55
56#[test]
57#[should_panic(expected = "Square must be between 1 and 64")]
58fn test_square_greater_than_64_raises_an_exception() {
59 grains::square(65);
60}
61
62#[test]
63fn test_returns_the_total_number_of_grains_on_the_board() {
64 assert_eq!(grains::total(), 18_446_744_073_709_551_615);
65}