Sha256: 52d81df6a5813344a72c111184532a72fdf9a4715370e61d921be58a1f8fa5f4

Contents?: true

Size: 1.63 KB

Versions: 114

Compression:

Stored size: 1.63 KB

Contents

package perfect

import "testing"

var _ error = ErrOnlyPositive

func TestGivesPositiveRequiredError(t *testing.T) {
	if _, err := Classify(0); err != ErrOnlyPositive {
		t.Fatalf("FAIL GivesPositiveRequiredError Expected error %q but got %q", ErrOnlyPositive, err)
	}
	t.Logf("PASS GivesPositiveRequiredError")
}

func TestClassifiesCorrectly(t *testing.T) {
	for _, c := range classificationTestCases {
		cat, err := Classify(c.input)
		switch {
		case err != nil:
			if c.ok {
				t.Fatalf("FAIL %s\nClassify(%d)\nExpected no error but got error %q", c.description, c.input, err)
			}
		case !c.ok:
			t.Fatalf("FAIL %s\nClassify(%d)\nExpected error but got %q", c.description, c.input, cat)
		case cat != c.expected:
			t.Fatalf("FAIL %s\nClassify(%d)\nExpected %q, got %q", c.description, c.input, c.expected, cat)
		}
		t.Logf("PASS %s", c.description)
	}
}

// Test that the classifications are not equal to each other.
// If they are equal, then the tests will return false positives.
func TestClassificationsNotEqual(t *testing.T) {
	classifications := []struct {
		class Classification
		name  string
	}{
		{ClassificationAbundant, "ClassificationAbundant"},
		{ClassificationDeficient, "ClassificationDeficient"},
		{ClassificationPerfect, "ClassificationPerfect"},
	}

	for i, pair1 := range classifications {
		for j := i + 1; j < len(classifications); j++ {
			pair2 := classifications[j]
			if pair1.class == pair2.class {
				t.Fatalf("%s should not be equal to %s", pair1.name, pair2.name)
			}
		}
	}
}

func BenchmarkClassify(b *testing.B) {
	for i := 0; i < b.N; i++ {
		for _, c := range classificationTestCases {
			Classify(c.input)
		}
	}
}

Version data entries

114 entries across 114 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.179 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.178 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.177 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.176 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.175 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.174 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.173 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.172 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.171 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.170 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.169 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.167 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.166 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.165 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.164 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.163 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.162 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.161 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.160 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go