Skip to content

Commit

Permalink
sieve: Add test versioning (#588)
Browse files Browse the repository at this point in the history
See #470
  • Loading branch information
tleen authored Mar 15, 2017
1 parent f2f15ad commit a645a8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions exercises/sieve/example.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package sieve

const testVersion = 1

func Sieve(limit int) (primes []int) {
c := make([]bool, limit)
for p := 2; p < limit; {
Expand Down
8 changes: 8 additions & 0 deletions exercises/sieve/sieve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"testing"
)

const targetTestVersion = 1

var p10 = []int{2, 3, 5, 7}
var p1000 = []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
Expand All @@ -18,6 +20,12 @@ var p1000 = []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883,
887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997}

func TestTestVersion(t *testing.T) {
if testVersion != targetTestVersion {
t.Fatalf("Found testVersion = %v, want %v", testVersion, targetTestVersion)
}
}

func TestSieve(t *testing.T) {
p := Sieve(10)
if !reflect.DeepEqual(p, p10) {
Expand Down

0 comments on commit a645a8d

Please sign in to comment.