1
exercism fetch rust say

tests/say.rs

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
extern crate say;

// Note: No tests created using 'and' with numbers.
// Aparently Most American English does not use the 'and' with numbers,
// where it is common in British English to use the 'and'.

#[test]
fn test_zero() {
    assert_eq!(say::encode(0), String::from("zero"));
}

//
// If the below test is uncommented, it should not compile.
//
/*
#[test]
#[ignore]
fn test_negative() {
    assert_eq!(say::encode(-1), String::from("won't compile"));
}
*/

#[test]
#[ignore]
fn test_one() {
    assert_eq!(say::encode(1), String::from("one"));
}

#[test]
#[ignore]
fn test_fourteen() {
    assert_eq!(say::encode(14), String::from("fourteen"));
}

#[test]
#[ignore]
fn test_twenty() {
    assert_eq!(say::encode(20), String::from("twenty"));
}

#[test]
#[ignore]
fn test_twenty_two() {
    assert_eq!(say::encode(22), String::from("twenty-two"));
}

#[test]
#[ignore]
fn test_one_hundred() {
    assert_eq!(say::encode(100), String::from("one hundred"));
}

// note, using American style with no and
#[test]
#[ignore]
fn test_one_hundred_twenty() {
    assert_eq!(say::encode(120), String::from("one hundred twenty"));
}

#[test]
#[ignore]
fn test_one_hundred_twenty_three() {
    assert_eq!(say::encode(123), String::from("one hundred twenty-three"));
}

#[test]
#[ignore]
fn test_one_thousand() {
    assert_eq!(say::encode(1000), String::from("one thousand"));
}

#[test]
#[ignore]
fn test_one_thousand_two_hundred_thirty_four() {
    assert_eq!(say::encode(1234), String::from("one thousand two hundred thirty-four"));
}

// note, using American style with no and
#[test]
#[ignore]
fn test_eight_hundred_and_ten_thousand() {
    assert_eq!(say::encode(810_000), String::from("eight hundred ten thousand"));
}

#[test]
#[ignore]
fn test_one_million() {
    assert_eq!(say::encode(1_000_000), String::from("one million"));
}

// note, using American style with no and
#[test]
#[ignore]
fn test_one_million_two() {
    assert_eq!(say::encode(1_000_002), String::from("one million two"));
}

#[test]
#[ignore]
fn test_1002345() {
    assert_eq!(say::encode(1_002_345),
               String::from("one million two thousand three hundred forty-five"));
}

#[test]
#[ignore]
fn test_one_billion() {
    assert_eq!(say::encode(1_000_000_000), String::from("one billion"));
}

#[test]
#[ignore]
fn test_987654321123() {
    assert_eq!(say::encode(987_654_321_123),
               String::from("nine hundred eighty-seven billion \
                             six hundred fifty-four million \
                             three hundred twenty-one thousand \
                             one hundred twenty-three"));
}

/*
  This test is only if you implemented full parsing for u64 type.
*/
#[test]
#[ignore]
fn test_max_u64() {
    assert_eq!(say::encode(9_223_372_036_854_775_807),
               String::from("nine quintillion two hundred twenty-three \
                             quadrillion three hundred seventy-two trillion \
                             thirty-six billion eight hundred fifty-four million \
                             seven hundred seventy-five thousand eight hundred seven"));
}