Exercism: Rust version of the 'Proverb' exercise.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.0 KiB

  1. use proverb::build_proverb;
  2. #[test]
  3. fn test_two_pieces() {
  4. let input = vec!["nail", "shoe"];
  5. let expected = vec![
  6. "For want of a nail the shoe was lost.",
  7. "And all for the want of a nail.",
  8. ]
  9. .join("\n");
  10. assert_eq!(build_proverb(&input), expected);
  11. }
  12. // Notice the change in the last line at three pieces.
  13. #[test]
  14. #[ignore]
  15. fn test_three_pieces() {
  16. let input = vec!["nail", "shoe", "horse"];
  17. let expected = vec![
  18. "For want of a nail the shoe was lost.",
  19. "For want of a shoe the horse was lost.",
  20. "And all for the want of a nail.",
  21. ]
  22. .join("\n");
  23. assert_eq!(build_proverb(&input), expected);
  24. }
  25. #[test]
  26. #[ignore]
  27. fn test_one_piece() {
  28. let input = vec!["nail"];
  29. let expected = String::from("And all for the want of a nail.");
  30. assert_eq!(build_proverb(&input), expected);
  31. }
  32. #[test]
  33. #[ignore]
  34. fn test_zero_pieces() {
  35. let input: Vec<&str> = vec![];
  36. let expected = String::new();
  37. assert_eq!(build_proverb(&input), expected);
  38. }
  39. #[test]
  40. #[ignore]
  41. fn test_full() {
  42. let input = vec![
  43. "nail", "shoe", "horse", "rider", "message", "battle", "kingdom",
  44. ];
  45. let expected = vec![
  46. "For want of a nail the shoe was lost.",
  47. "For want of a shoe the horse was lost.",
  48. "For want of a horse the rider was lost.",
  49. "For want of a rider the message was lost.",
  50. "For want of a message the battle was lost.",
  51. "For want of a battle the kingdom was lost.",
  52. "And all for the want of a nail.",
  53. ]
  54. .join("\n");
  55. assert_eq!(build_proverb(&input), expected);
  56. }
  57. #[test]
  58. #[ignore]
  59. fn test_three_pieces_modernized() {
  60. let input = vec!["pin", "gun", "soldier", "battle"];
  61. let expected = vec![
  62. "For want of a pin the gun was lost.",
  63. "For want of a gun the soldier was lost.",
  64. "For want of a soldier the battle was lost.",
  65. "And all for the want of a pin.",
  66. ]
  67. .join("\n");
  68. assert_eq!(build_proverb(&input), expected);
  69. }