diff options
Diffstat (limited to 'rust/proverb/tests/proverb.rs')
| -rw-r--r-- | rust/proverb/tests/proverb.rs | 70 |
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 @@ | |||
| 1 | use proverb::build_proverb; | ||
| 2 | |||
| 3 | #[test] | ||
| 4 | fn 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] | ||
| 16 | fn 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] | ||
| 28 | fn 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] | ||
| 35 | fn 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] | ||
| 42 | fn 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] | ||
| 60 | fn 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 | } | ||
