Sha256: acacfb5c2a19b27de6a55562f6767e9b8baa06319c1b63969f90b6d971056104

Contents?: true

Size: 1.13 KB

Versions: 81

Compression:

Stored size: 1.13 KB

Contents

package transpose

import (
	"reflect"
	"testing"
)

func TestTranspose(t *testing.T) {
	for _, test := range testCases {
		actual := Transpose(test.input)
		if !reflect.DeepEqual(actual, test.expected) {
			// check for zero length slices
			if len(actual) == 0 || len(test.expected) == 0 {
				t.Fatalf("\n\tTranspose(%q): %s\n\n\tExpected: %q\n\tGot: %q",
					test.input, test.description, test.expected, actual)
			}
			// let's make the error more specific and find the row it's on
			min := min(len(test.expected), len(actual))
			for i := 0; i < min; i++ {
				if test.expected[i] != actual[i] {
					t.Fatalf("\n\tTranspose(%q): %s\n\n\tExpected: %q\n\tGot: %q\n\n\tRow %d Expected: %q Got: %q",
						test.input, test.description, test.expected, actual, i, test.expected[i], actual[i])
				}
			}
		}
	}
}

// helper function
// https://stackoverflow.com/questions/27516387/what-is-the-correct-way-to-find-the-min-between-two-integers-in-go
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func BenchmarkTranspose(b *testing.B) {
	for i := 0; i < b.N; i++ {
		for _, test := range testCases {
			Transpose(test.input)
		}
	}
}

Version data entries

81 entries across 81 versions & 1 rubygems

Version Path
trackler-2.2.1.119 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.118 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.117 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.116 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.115 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.114 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.113 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.111 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.110 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.109 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.108 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.107 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.106 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.105 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.104 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.103 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.102 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.101 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.100 tracks/go/exercises/transpose/transpose_test.go
trackler-2.2.1.99 tracks/go/exercises/transpose/transpose_test.go