Sha256: 312e2ee8f4bd9b07f0ad0ec2529bd5ef2f524f9b4aad739f25fb57e4b62f4561

Contents?: true

Size: 1.42 KB

Versions: 51

Compression:

Stored size: 1.42 KB

Contents

package forth

// API:
// func Forth([]string) ([]int, error)
//

import (
	"reflect"
	"testing"
)

const targetTestVersion = 1

type testCase struct {
	description string
	input       []string
	expected    []int // nil slice indicates error expected.
}

type testcaseSection struct {
	name  string
	tests []testCase
}

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

func runTestCases(t *testing.T, sectionName string, testCases []testCase) {
	for _, tc := range testCases {
		description := sectionName + " - " + tc.description
		if v, err := Forth(tc.input); err == nil {
			var _ error = err
			if tc.expected == nil {
				t.Fatalf("%s\n\tForth(%#v) expected an error, got %v",
					description, tc.input, v)
			} else if !reflect.DeepEqual(v, tc.expected) {
				t.Fatalf("%s\n\tForth(%#v) expected %v, got %v",
					description, tc.input, tc.expected, v)
			}
		} else if tc.expected != nil {
			t.Fatalf("%s\n\tForth(%#v) expected %v, got an error: %q",
				description, tc.input, tc.expected, err)
		}
	}
}

func TestForth(t *testing.T) {
	for _, testSection := range testSections {
		runTestCases(t, testSection.name, testSection.tests)
	}
}

func BenchmarkForth(b *testing.B) {
	for i := 0; i < b.N; i++ {
		for _, testSection := range testSections {
			for _, test := range testSection.tests {
				Forth(test.input)
			}
		}
	}
}

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
trackler-2.0.8.43 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.42 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.41 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.40 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.39 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.38 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.37 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.36 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.35 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.34 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.33 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.32 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.31 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.30 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.29 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.28 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.27 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.26 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.24 tracks/go/exercises/forth/forth_test.go
trackler-2.0.8.23 tracks/go/exercises/forth/forth_test.go