1#[allow(unused)]
7pub fn make_string(num: i32) -> String {
18 let first = String::from("1st");
19 let second = String::from("2nd");
20 let third = String::from("3rd");
21 let fourth = String::from("4th");
22 let fifth = String::from("5th");
23 let sixth = String::from("6th");
24 let seventh = String::from("7th");
25 let eighth = String::from("8th");
26 let ninth = String::from("9th");
27 let tenth = String::from("10th");
28 let eleventh = String::from("11th");
29 let twelfth = String::from("12th");
30
31 if num == 1 {
32 first
33 } else if num == 2 {
34 second
35 } else if num == 3 {
36 third
37 } else if num == 4 {
38 fourth
39 } else if num == 5 {
40 fifth
41 } else if num == 6 {
42 sixth
43 } else if num == 7 {
44 seventh
45 } else if num == 8 {
46 eighth
47 } else if num == 9 {
48 ninth
49 } else if num == 10 {
50 tenth
51 } else if num == 11 {
52 eleventh
53 } else if num == 12 {
54 twelfth
55 }else {
56 num.to_string()
57 }
58}
59pub fn match_num(num: i32) -> String {
70 match num {
71 1 => String::from("1st"),
72 2 => String::from("2nd"),
73 3 => String::from("3rd"),
74 4 => String::from("4th"),
75 5 => String::from("5th"),
76 6 => String::from("6th"),
77 7 => String::from("7th"),
78 8 => String::from("8th"),
79 9 => String::from("9th"),
80 10 => String::from("10th"),
81 11 => String::from("11th"),
82 12 => String::from("12th"),
83 _ => num.to_string(),
84 }
85}
86
87
88#[cfg(test)]
89mod tests {
90 use super::*;
91
92 #[test]
93 fn make_string_twelfth() {
94 let result = make_string(12);
95 assert_eq!(result, "12th");
96 }
97 #[test]
98 fn match_one() {
99 let result = match_num(1);
100 assert_eq!(result, "1st");
101 }
102 #[test]
103 fn match_two() {
104 let result = match_num(2);
105 assert_eq!(result, "2nd");
106 }
107 #[test]
108 fn match_twelve() {
109 let result = match_num(12);
110 assert_eq!(result, "12th");
111 }
112}