Skip to content

Commit

Permalink
Merge pull request #2 from vaskoz/day1
Browse files Browse the repository at this point in the history
add large dataset tests
  • Loading branch information
vaskoz committed Aug 22, 2018
2 parents 20a3dc8 + b9f6268 commit d678ccc
Showing 1 changed file with 67 additions and 2 deletions.
69 changes: 67 additions & 2 deletions day1/problem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package day1

import "testing"

func TestTwoSums(t *testing.T) {
func TestTwoSumsSmall(t *testing.T) {
ten := []int{100, 75, 50, 25, 11, 45, 78, 99, 101, 12}
tenK := 201
t.Run("Brute", func(t *testing.T) {
Expand Down Expand Up @@ -34,7 +34,44 @@ func TestTwoSums(t *testing.T) {
})
}

func BenchmarkTwoSums(b *testing.B) {
func TestTwoSumsLarge(t *testing.T) {
large := make([]int, 1000)
largeK := 2
for i := 1; i < 501; i++ {
for j := 0; j < 2; j++ {
large[2*(i-1)+j] = i
}
}
t.Run("Brute", func(t *testing.T) {
t.Parallel()
if result := TwoSumBrute(large, largeK); !result {
t.Error("tenK should be true")
}
if result := TwoSumBrute(large, 1); result {
t.Error("tenK should be false")
}
})
t.Run("Better", func(t *testing.T) {
t.Parallel()
if result := TwoSumBetter(large, largeK); !result {
t.Error("tenK should be true")
}
if result := TwoSumBetter(large, 1); result {
t.Error("tenK should be false")
}
})
t.Run("Best", func(t *testing.T) {
t.Parallel()
if result := TwoSumBest(large, largeK); !result {
t.Error("tenK should be true")
}
if result := TwoSumBest(large, 1); result {
t.Error("tenK should be false")
}
})
}

func BenchmarkTwoSumsSmall(b *testing.B) {
ten := []int{100, 75, 50, 25, 11, 45, 78, 99, 101, 12}
tenK := 201
b.Run("Brute", func(b *testing.B) {
Expand All @@ -56,3 +93,31 @@ func BenchmarkTwoSums(b *testing.B) {
}
})
}

func BenchmarkTwoSumsLarge(b *testing.B) {
large := make([]int, 1000)
largeK := 2
for i := 1; i < 501; i++ {
for j := 0; j < 2; j++ {
large[2*(i-1)+j] = i
}
}
b.Run("Brute", func(b *testing.B) {
for i := 0; i < b.N; i++ {
TwoSumBrute(large, largeK)
TwoSumBrute(large, 1)
}
})
b.Run("Better", func(b *testing.B) {
for i := 0; i < b.N; i++ {
TwoSumBetter(large, largeK)
TwoSumBetter(large, 1)
}
})
b.Run("Best", func(b *testing.B) {
for i := 0; i < b.N; i++ {
TwoSumBest(large, largeK)
TwoSumBest(large, 1)
}
})
}

0 comments on commit d678ccc

Please sign in to comment.