diff options
Diffstat (limited to 'go/leap/leap_test.go')
-rw-r--r-- | go/leap/leap_test.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/go/leap/leap_test.go b/go/leap/leap_test.go new file mode 100644 index 0000000..eabd1f2 --- /dev/null +++ b/go/leap/leap_test.go @@ -0,0 +1,22 @@ +package leap + +import "testing" + +func TestLeapYears(t *testing.T) { + 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) + } + } +} |