Sha256: c12aedcd2fd4950cfdb921ee837f8682f83975caa9b7963d4318fb6dc2b9efb1

Contents?: true

Size: 1.2 KB

Versions: 122

Compression:

Stored size: 1.2 KB

Contents

package spiralmatrix

import (
	"reflect"
	"testing"
)

var testCases = []struct {
	description string
	input       int
	expected    [][]int
}{
	{
		description: "empty spiral",
		input:       0,
		expected:    [][]int{},
	},
	{
		description: "trivial spiral",
		input:       1,
		expected: [][]int{
			{1},
		},
	},
	{
		description: "spiral of size 2",
		input:       2,
		expected: [][]int{
			{1, 2},
			{4, 3},
		},
	},
	{
		description: "spiral of size 3",
		input:       3,
		expected: [][]int{
			{1, 2, 3},
			{8, 9, 4},
			{7, 6, 5},
		},
	},
	{
		description: "spiral of size 4",
		input:       4,
		expected: [][]int{
			{1, 2, 3, 4},
			{12, 13, 14, 5},
			{11, 16, 15, 6},
			{10, 9, 8, 7},
		},
	},
}

func TestSpiralMatrix(t *testing.T) {
	for _, testCase := range testCases {
		matrix := SpiralMatrix(testCase.input)
		if !reflect.DeepEqual(matrix, testCase.expected) {
			t.Fatalf("FAIL: %s\n\tSpiralMatrix(%v)\nexpected: %v\ngot     : %v",
				testCase.description, testCase.input, testCase.expected, matrix)
		}
		t.Logf("PASS: %s", testCase.description)
	}
}

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

Version data entries

122 entries across 122 versions & 1 rubygems

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