summaryrefslogtreecommitdiff
path: root/go/largest-series-product/largest_series_product_test.go
blob: 275c0a8f30504f2c6fc1851bf732b9c5cbb00fab (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
33
34
35
36
package lsproduct

import "testing"

const targetTestVersion = 3

func TestLargestSeriesProduct(t *testing.T) {
	if testVersion != targetTestVersion {
		t.Fatalf("Found testVersion = %v, want %v", testVersion, targetTestVersion)
	}
	for _, test := range tests {
		p, err := LargestSeriesProduct(test.digits, test.span)
		switch {
		case err != nil:
			if test.ok {
				t.Fatalf("LargestSeriesProduct(%s, %d) returned error %q.  "+
					"Error not expected.",
					test.digits, test.span, err)
			}
		case !test.ok:
			t.Fatalf("LargestSeriesProduct(%s, %d) = %d, %v.  Expected error",
				test.digits, test.span, p, err)
		case int64(p) != test.product:
			t.Fatalf("LargestSeriesProduct(%s, %d) = %d, want %d",
				test.digits, test.span, p, test.product)
		}
	}
}

func BenchmarkLargestSeriesProduct(b *testing.B) {
	for i := 0; i < b.N; i++ {
		for _, test := range tests {
			LargestSeriesProduct(test.digits, test.span)
		}
	}
}