summaryrefslogtreecommitdiff
path: root/go/leap/leap_test.go
blob: 974d79e457327c6a9c4c4abce51dd1589d6ff287 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package leap

import "testing"

// Define a function IsLeapYear(int) bool.
//
// Also define a testVersion with a value that matches
// the targetTestVersion here.

const targetTestVersion = 2

func TestLeapYears(t *testing.T) {
	if testVersion != targetTestVersion {
		t.Fatalf("Found testVersion = %v, want %v", testVersion, targetTestVersion)
	}
	for _, test := range testCases {
		observed := IsLeapYear(test.year)
		if observed != test.expected {
			t.Fatalf("IsLeapYear(%d) = %t, want %t (%s)",
				test.year, observed, test.expected, test.description)
		}
	}
}

// Benchmark 400 year interval to get fair weighting of different years.
func Benchmark400(b *testing.B) {
	for i := 0; i < b.N; i++ {
		for y := 1600; y < 2000; y++ {
			IsLeapYear(y)
		}
	}
}