Sha256: 96bc97875b86ec1883c4c8b90be5b56dd3a9e04fc078fb4aa57cdc456d54afbd

Contents?: true

Size: 1.34 KB

Versions: 177

Compression:

Stored size: 1.34 KB

Contents

package diffsquares

import "testing"

const targetTestVersion = 1

var tests = []struct{ n, sqOfSums, sumOfSq int }{
	{5, 225, 55},
	{10, 3025, 385},
	{100, 25502500, 338350},
}

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

func TestSquareOfSums(t *testing.T) {
	for _, test := range tests {
		if s := SquareOfSums(test.n); s != test.sqOfSums {
			t.Fatalf("SquareOfSums(%d) = %d, want %d", test.n, s, test.sqOfSums)
		}
	}
}

func TestSumOfSquares(t *testing.T) {
	for _, test := range tests {
		if s := SumOfSquares(test.n); s != test.sumOfSq {
			t.Fatalf("SumOfSquares(%d) = %d, want %d", test.n, s, test.sumOfSq)
		}
	}
}

func TestDifference(t *testing.T) {
	for _, test := range tests {
		want := test.sqOfSums - test.sumOfSq
		if s := Difference(test.n); s != want {
			t.Fatalf("Difference(%d) = %d, want %d", test.n, s, want)
		}
	}
}

// Benchmark functions on just a single number (100, from the original PE problem)
// to avoid overhead of iterating over tests.
func BenchmarkSquareOfSums(b *testing.B) {
	for i := 0; i < b.N; i++ {
		SquareOfSums(100)
	}
}

func BenchmarkSumOfSquares(b *testing.B) {
	for i := 0; i < b.N; i++ {
		SumOfSquares(100)
	}
}

func BenchmarkDifference(b *testing.B) {
	for i := 0; i < b.N; i++ {
		Difference(100)
	}
}

Version data entries

177 entries across 177 versions & 1 rubygems

Version Path
trackler-2.2.1.56 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.55 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.54 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.53 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.52 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.51 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.50 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.49 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.48 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.47 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.46 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.45 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.44 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.43 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.42 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.41 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.40 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.39 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.38 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go
trackler-2.2.1.37 tracks/go/exercises/difference-of-squares/difference_of_squares_test.go