aboutsummaryrefslogtreecommitdiff
path: root/rust/grains/tests/grains.rs
blob: 405eb4de156a5988c2e62f11dddb024be92a8d13 (plain) (blame)
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
56
57
58
59
60
61
62
63
64
65
use grains;

fn process_square_case(input: u32, expected: u64) {
    assert_eq!(grains::square(input), expected);
}

#[test]
/// 1
fn test_1() {
    process_square_case(1, 1);
}

#[test]
/// 2
fn test_2() {
    process_square_case(2, 2);
}

#[test]
/// 3
fn test_3() {
    process_square_case(3, 4);
}

#[test]
/// 4
fn test_4() {
    process_square_case(4, 8);
}

//NEW
#[test]
/// 16
fn test_16() {
    process_square_case(16, 32_768);
}

#[test]
/// 32
fn test_32() {
    process_square_case(32, 2_147_483_648);
}

#[test]
/// 64
fn test_64() {
    process_square_case(64, 9_223_372_036_854_775_808);
}

#[test]
#[should_panic(expected = "Square must be between 1 and 64")]
fn test_square_0_raises_an_exception() {
    grains::square(0);
}

#[test]
#[should_panic(expected = "Square must be between 1 and 64")]
fn test_square_greater_than_64_raises_an_exception() {
    grains::square(65);
}

#[test]
fn test_returns_the_total_number_of_grains_on_the_board() {
    assert_eq!(grains::total(), 18_446_744_073_709_551_615);
}