aboutsummaryrefslogtreecommitdiff
path: root/rust/proverb/tests/proverb.rs
diff options
context:
space:
mode:
authorFederico Igne <git@federicoigne.com>2020-12-26 17:48:38 +0000
committerFederico Igne <git@federicoigne.com>2021-11-03 18:55:08 +0000
commit02481656966b0a8dfc95cf3c22bcc049660ff7d4 (patch)
tree8e39798fcaf27931d91c2088423fd4e97adcfc2d /rust/proverb/tests/proverb.rs
parent4e2052c4d792540c2f742b2c2a081b11117ed41d (diff)
downloadexercism-02481656966b0a8dfc95cf3c22bcc049660ff7d4.tar.gz
exercism-02481656966b0a8dfc95cf3c22bcc049660ff7d4.zip
Move Rust exercises in a subdirectory
Diffstat (limited to 'rust/proverb/tests/proverb.rs')
-rw-r--r--rust/proverb/tests/proverb.rs70
1 files changed, 70 insertions, 0 deletions
diff --git a/rust/proverb/tests/proverb.rs b/rust/proverb/tests/proverb.rs
new file mode 100644
index 0000000..220de45
--- /dev/null
+++ b/rust/proverb/tests/proverb.rs
@@ -0,0 +1,70 @@
1use proverb::build_proverb;
2
3#[test]
4fn test_two_pieces() {
5 let input = vec!["nail", "shoe"];
6 let expected = vec![
7 "For want of a nail the shoe was lost.",
8 "And all for the want of a nail.",
9 ]
10 .join("\n");
11 assert_eq!(build_proverb(&input), expected);
12}
13
14// Notice the change in the last line at three pieces.
15#[test]
16fn test_three_pieces() {
17 let input = vec!["nail", "shoe", "horse"];
18 let expected = vec![
19 "For want of a nail the shoe was lost.",
20 "For want of a shoe the horse was lost.",
21 "And all for the want of a nail.",
22 ]
23 .join("\n");
24 assert_eq!(build_proverb(&input), expected);
25}
26
27#[test]
28fn test_one_piece() {
29 let input = vec!["nail"];
30 let expected = String::from("And all for the want of a nail.");
31 assert_eq!(build_proverb(&input), expected);
32}
33
34#[test]
35fn test_zero_pieces() {
36 let input: Vec<&str> = vec![];
37 let expected = String::new();
38 assert_eq!(build_proverb(&input), expected);
39}
40
41#[test]
42fn test_full() {
43 let input = vec![
44 "nail", "shoe", "horse", "rider", "message", "battle", "kingdom",
45 ];
46 let expected = vec![
47 "For want of a nail the shoe was lost.",
48 "For want of a shoe the horse was lost.",
49 "For want of a horse the rider was lost.",
50 "For want of a rider the message was lost.",
51 "For want of a message the battle was lost.",
52 "For want of a battle the kingdom was lost.",
53 "And all for the want of a nail.",
54 ]
55 .join("\n");
56 assert_eq!(build_proverb(&input), expected);
57}
58
59#[test]
60fn test_three_pieces_modernized() {
61 let input = vec!["pin", "gun", "soldier", "battle"];
62 let expected = vec![
63 "For want of a pin the gun was lost.",
64 "For want of a gun the soldier was lost.",
65 "For want of a soldier the battle was lost.",
66 "And all for the want of a pin.",
67 ]
68 .join("\n");
69 assert_eq!(build_proverb(&input), expected);
70}