Sha256: b8f61d7b139b0e3a094b938fdbbc6780bc568bd6be8cd2e9b6626539e398d53d

Contents?: true

Size: 1.66 KB

Versions: 38

Compression:

Stored size: 1.66 KB

Contents

package perfect

import "testing"

var _ error = ErrOnlyPositive

var classificationTestCases = []struct {
	input    uint64
	expected Classification
}{
	{1, ClassificationDeficient},
	{13, ClassificationDeficient},
	{12, ClassificationAbundant},
	{6, ClassificationPerfect},
	{28, ClassificationPerfect},
	{496, ClassificationPerfect},
	{8128, ClassificationPerfect},
}

const targetTestVersion = 1

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

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

func TestClassifiesCorrectly(t *testing.T) {
	for _, c := range classificationTestCases {
		if cat, err := Classify(c.input); err != nil {
			t.Errorf("%d: Expected no error but got %s", c.input, err)
		} else if cat != c.expected {
			t.Errorf("%d: Expected %q, got %q", c.input, c.expected, cat)
		}
	}
}

// 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)
			}
		}
	}
}

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
trackler-2.2.1.29 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.28 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.27 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.26 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.25 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.24 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.23 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.22 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.21 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.20 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.19 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.18 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.17 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.16 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.15 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.14 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.13 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.12 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.11 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go
trackler-2.2.1.10 tracks/go/exercises/perfect-numbers/perfect_numbers_test.go