From 4f1bb81b4401686fa8860756a68c81a7b292008a Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 27 Aug 2016 23:12:22 +0200 Subject: Solve largest --- .../largest_series_product_test.go | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 go/largest-series-product/largest_series_product_test.go (limited to 'go/largest-series-product/largest_series_product_test.go') diff --git a/go/largest-series-product/largest_series_product_test.go b/go/largest-series-product/largest_series_product_test.go new file mode 100644 index 0000000..275c0a8 --- /dev/null +++ b/go/largest-series-product/largest_series_product_test.go @@ -0,0 +1,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) + } + } +} -- cgit v1.2.3