Exercism: Go 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.

22 lines
481 B

6 years ago
  1. package leap
  2. import "testing"
  3. func TestLeapYears(t *testing.T) {
  4. for _, test := range testCases {
  5. observed := IsLeapYear(test.year)
  6. if observed != test.expected {
  7. t.Fatalf("IsLeapYear(%d) = %t, want %t (%s)",
  8. test.year, observed, test.expected, test.description)
  9. }
  10. }
  11. }
  12. // Benchmark 400 year interval to get fair weighting of different years.
  13. func Benchmark400(b *testing.B) {
  14. for i := 0; i < b.N; i++ {
  15. for y := 1600; y < 2000; y++ {
  16. IsLeapYear(y)
  17. }
  18. }
  19. }