summaryrefslogtreecommitdiff
path: root/rust/grains/tests/grains.rs
blob: a2a4ba941eb48825f373c34813d068233fb1004f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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);
}