Skip to content

Commit

Permalink
perfect-numbers: small changes to test cases
Browse files Browse the repository at this point in the history
separate test data out from testing function and rename
  • Loading branch information
robphoenix committed Mar 6, 2017
1 parent f24e74b commit 04ebd40
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions exercises/perfect-numbers/perfect_numbers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ 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) {
Expand All @@ -19,19 +32,7 @@ func TestGivesPositiveRequiredError(t *testing.T) {
}

func TestClassifiesCorrectly(t *testing.T) {
cases := []struct {
input uint64
expected Classification
}{
{1, ClassificationDeficient},
{13, ClassificationDeficient},
{12, ClassificationAbundant},
{6, ClassificationPerfect},
{28, ClassificationPerfect},
{496, ClassificationPerfect},
{8128, ClassificationPerfect},
}
for _, c := range cases {
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 {
Expand Down

0 comments on commit 04ebd40

Please sign in to comment.