Exercism: Rust version of the 'Leap' 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.

100 lines
2.1 KiB

3 years ago
  1. fn process_leapyear_case(year: u64, expected: bool) {
  2. assert_eq!(leap::is_leap_year(year), expected);
  3. }
  4. #[test]
  5. fn test_year_not_divisible_by_4_common_year() {
  6. process_leapyear_case(2015, false);
  7. }
  8. #[test]
  9. #[ignore]
  10. fn test_year_divisible_by_2_not_divisible_by_4_in_common_year() {
  11. process_leapyear_case(1970, false);
  12. }
  13. #[test]
  14. #[ignore]
  15. fn test_year_divisible_by_4_not_divisible_by_100_leap_year() {
  16. process_leapyear_case(1996, true);
  17. }
  18. #[test]
  19. #[ignore]
  20. fn test_year_divisible_by_4_and_5_is_still_a_leap_year() {
  21. process_leapyear_case(1960, true);
  22. }
  23. #[test]
  24. #[ignore]
  25. fn test_year_divisible_by_100_not_divisible_by_400_common_year() {
  26. process_leapyear_case(2100, false);
  27. }
  28. #[test]
  29. #[ignore]
  30. fn test_year_divisible_by_100_but_not_by_3_is_still_not_a_leap_year() {
  31. process_leapyear_case(1900, false);
  32. }
  33. #[test]
  34. #[ignore]
  35. fn test_year_divisible_by_400_leap_year() {
  36. process_leapyear_case(2000, true);
  37. }
  38. #[test]
  39. #[ignore]
  40. fn test_year_divisible_by_400_but_not_by_125_is_still_a_leap_year() {
  41. process_leapyear_case(2400, true);
  42. }
  43. #[test]
  44. #[ignore]
  45. fn test_year_divisible_by_200_not_divisible_by_400_common_year() {
  46. process_leapyear_case(1800, false);
  47. }
  48. #[test]
  49. #[ignore]
  50. fn test_any_old_year() {
  51. process_leapyear_case(1997, false);
  52. }
  53. #[test]
  54. #[ignore]
  55. fn test_early_years() {
  56. process_leapyear_case(1, false);
  57. process_leapyear_case(4, true);
  58. process_leapyear_case(100, false);
  59. process_leapyear_case(400, true);
  60. process_leapyear_case(900, false);
  61. }
  62. #[test]
  63. #[ignore]
  64. fn test_century() {
  65. process_leapyear_case(1700, false);
  66. process_leapyear_case(1800, false);
  67. process_leapyear_case(1900, false);
  68. }
  69. #[test]
  70. #[ignore]
  71. fn test_exceptional_centuries() {
  72. process_leapyear_case(1600, true);
  73. process_leapyear_case(2000, true);
  74. process_leapyear_case(2400, true);
  75. }
  76. #[test]
  77. #[ignore]
  78. fn test_years_1600_to_1699() {
  79. let incorrect_years = (1600..1700)
  80. .filter(|&year| leap::is_leap_year(year) != (year % 4 == 0))
  81. .collect::<Vec<_>>();
  82. if !incorrect_years.is_empty() {
  83. panic!("incorrect result for years: {:?}", incorrect_years);
  84. }
  85. }