From f45890a79f087ec2d65c6d3e0210b21de66414b1 Mon Sep 17 00:00:00 2001 From: Broderick Westrope Date: Fri, 27 Sep 2024 12:47:03 +1000 Subject: [PATCH 1/5] refactor: return rotation point instead of bool for SRS --- pkg/tetris/tetrimino.go | 44 +++++----- pkg/tetris/tetrimino_test.go | 160 +++++++++++++++++++++++++++++++++-- 2 files changed, 177 insertions(+), 27 deletions(-) diff --git a/pkg/tetris/tetrimino.go b/pkg/tetris/tetrimino.go index 65936ed..adb2670 100644 --- a/pkg/tetris/tetrimino.go +++ b/pkg/tetris/tetrimino.go @@ -6,6 +6,8 @@ import ( "math" ) +const invalidRotationPoint = -1 + // A Tetrimino is a geometric Tetris shape formed by four Minos connected along their sides. type Tetrimino struct { // The value of the Tetrimino. This is the character that will be used to represent the Tetrimino in the matrix. @@ -252,26 +254,28 @@ func (t *Tetrimino) Rotate(matrix Matrix, clockwise bool) error { rotated := t.DeepCopy() var err error - var foundValid bool + var rotationPoint int if clockwise { - foundValid, err = rotated.rotateClockwise(matrix) + rotationPoint, err = rotated.rotateClockwise(matrix) } else { - foundValid, err = rotated.rotateCounterClockwise(matrix) + rotationPoint, err = rotated.rotateCounterClockwise(matrix) } if err != nil { return fmt.Errorf("failed to rotate tetrimino: %w", err) } - if foundValid { - t.Pos = rotated.Pos - t.Minos = rotated.Minos - t.CompassDirection = rotated.CompassDirection + foundValid := rotationPoint != invalidRotationPoint + if !foundValid { + return nil } + t.Pos = rotated.Pos + t.Minos = rotated.Minos + t.CompassDirection = rotated.CompassDirection return nil } -func (t *Tetrimino) rotateClockwise(matrix Matrix) (bool, error) { +func (t *Tetrimino) rotateClockwise(matrix Matrix) (int, error) { // Reverse the order of the rows for i, j := 0, len(t.Minos)-1; i < j; i, j = i+1, j-1 { t.Minos[i], t.Minos[j] = t.Minos[j], t.Minos[i] @@ -282,23 +286,23 @@ func (t *Tetrimino) rotateClockwise(matrix Matrix) (bool, error) { var err error t.CompassDirection, err = positiveMod(t.CompassDirection+1, len(t.RotationCompass)) if err != nil { - return false, fmt.Errorf("failed to get positive mod: %w", err) + return invalidRotationPoint, fmt.Errorf("failed to get positive mod: %w", err) } originalX, originalY := t.Pos.X, t.Pos.Y - for _, coord := range t.RotationCompass[t.CompassDirection] { + for i, coord := range t.RotationCompass[t.CompassDirection] { t.Pos.X = originalX + coord.X t.Pos.Y = originalY + coord.Y if t.isValid(matrix) { - return true, nil + return i + 1, nil } } - return false, nil + return invalidRotationPoint, nil } -func (t *Tetrimino) rotateCounterClockwise(matrix Matrix) (bool, error) { +func (t *Tetrimino) rotateCounterClockwise(matrix Matrix) (int, error) { // Reverse the order of the columns for _, row := range t.Minos { for i, j := 0, len(row)-1; i < j; i, j = i+1, j-1 { @@ -308,28 +312,28 @@ func (t *Tetrimino) rotateCounterClockwise(matrix Matrix) (bool, error) { t.transpose() - foundValid := false + rotationPoint := invalidRotationPoint originalX, originalY := t.Pos.X, t.Pos.Y - for _, coord := range t.RotationCompass[t.CompassDirection] { + for i, coord := range t.RotationCompass[t.CompassDirection] { t.Pos.X = originalX - coord.X t.Pos.Y = originalY - coord.Y if t.isValid(matrix) { - foundValid = true + rotationPoint = i + 1 break } } - if !foundValid { - return false, nil + if rotationPoint == invalidRotationPoint { + return rotationPoint, nil } var err error t.CompassDirection, err = positiveMod(t.CompassDirection-1, len(t.RotationCompass)) if err != nil { - return false, fmt.Errorf("failed to get positive mod: %w", err) + return invalidRotationPoint, fmt.Errorf("failed to get positive mod: %w", err) } - return true, nil + return rotationPoint, nil } func (t *Tetrimino) transpose() { diff --git a/pkg/tetris/tetrimino_test.go b/pkg/tetris/tetrimino_test.go index 2e4633f..d90625a 100644 --- a/pkg/tetris/tetrimino_test.go +++ b/pkg/tetris/tetrimino_test.go @@ -402,9 +402,10 @@ func TestTetrimino_Rotate(t *testing.T) { func TestTetrimino_rotateClockwise(t *testing.T) { tt := map[string]struct { - matrix Matrix - tet *Tetrimino - wantTet *Tetrimino + matrix Matrix + tet *Tetrimino + wantTet *Tetrimino + wantRotationPoint int }{ "I; starting rotation 0 (north); rotation point 1": { matrix: Matrix{ @@ -434,6 +435,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 1, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 1, }, "I; starting rotation 0 (north); rotation point 2": { matrix: Matrix{ @@ -463,6 +465,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 1, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 2, }, "I; starting rotation 0 (north); rotation point 3": { matrix: Matrix{ @@ -492,6 +495,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 1, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 3, }, "I; starting rotation 0 (north); rotation point 4": { matrix: Matrix{ @@ -522,6 +526,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 1, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 4, }, "I; starting rotation 0 (north); rotation point 5": { matrix: Matrix{ @@ -554,6 +559,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 1, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 5, }, "I; starting rotation 0 (north); no valid rotation": { matrix: Matrix{ @@ -599,6 +605,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 2, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 1, }, "I; starting rotation 1 (east); rotation point 2": { matrix: Matrix{ @@ -628,6 +635,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 2, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 2, }, "I; starting rotation 1 (east); rotation point 3": { matrix: Matrix{ @@ -657,6 +665,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 2, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 3, }, "I; starting rotation 1 (east); rotation point 4": { matrix: Matrix{ @@ -686,6 +695,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 2, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 4, }, "I; starting rotation 1 (east); rotation point 5": { matrix: Matrix{ @@ -715,6 +725,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 2, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 5, }, "I; starting rotation 1 (east); no valid rotation": { matrix: Matrix{ @@ -763,6 +774,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 3, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 1, }, "I; starting rotation 2 (south); rotation point 2": { matrix: Matrix{ @@ -792,6 +804,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 3, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 2, }, "I; starting rotation 2 (south); rotation point 3": { matrix: Matrix{ @@ -821,6 +834,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 3, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 3, }, "I; starting rotation 2 (south); rotation point 4": { matrix: Matrix{ @@ -851,6 +865,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 3, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 4, }, "I; starting rotation 2 (south); rotation point 5": { matrix: Matrix{ @@ -882,6 +897,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 3, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 5, }, "I; starting rotation 2 (south); no valid rotation": { matrix: Matrix{ @@ -927,6 +943,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 0, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 1, }, "I; starting rotation 3 (west); rotation point 2": { matrix: Matrix{ @@ -956,6 +973,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 0, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 2, }, "I; starting rotation 3 (west); rotation point 3": { matrix: Matrix{ @@ -985,6 +1003,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 0, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 3, }, "I; starting rotation 3 (west); rotation point 4": { matrix: Matrix{ @@ -1014,6 +1033,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 0, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 4, }, "I; starting rotation 3 (west); rotation point 5": { matrix: Matrix{ @@ -1043,6 +1063,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 0, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 5, }, "I; starting rotation 3 (west); no valid rotation": { matrix: Matrix{ @@ -1088,6 +1109,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 1, RotationCompass: RotationCompasses['O'], }, + wantRotationPoint: 1, }, "O; starting rotation 0 (north); no valid rotation": { matrix: Matrix{ @@ -1131,6 +1153,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 2, RotationCompass: RotationCompasses['O'], }, + wantRotationPoint: 1, }, "O; starting rotation 1 (east); no valid rotation": { matrix: Matrix{ @@ -1174,6 +1197,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 3, RotationCompass: RotationCompasses['O'], }, + wantRotationPoint: 1, }, "O; starting rotation 2 (south); no valid rotation": { matrix: Matrix{ @@ -1217,6 +1241,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 0, RotationCompass: RotationCompasses['O'], }, + wantRotationPoint: 1, }, "O; starting rotation 3 (west); no valid rotation": { matrix: Matrix{ @@ -1262,7 +1287,125 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 1, RotationCompass: RotationCompasses['6'], }, + wantRotationPoint: 1, + }, + "6; starting rotation 0 (north); rotation point 2": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: 1, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, + {true, true}, + {true, false}, + }, + Pos: Coordinate{X: 1, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 2, + }, + "6; starting rotation 0 (north); rotation point 3": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 1}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, + {true, true}, + {true, false}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 3, + }, + "6; starting rotation 0 (north); rotation point 4": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: -1, Y: -2}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, + {true, true}, + {true, false}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 4, }, + "6; starting rotation 0 (north); rotation point 5": { + matrix: Matrix{ + {0, 0}, + {0, 0}, + {0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: 0, Y: -2}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, + {true, true}, + {true, false}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 5, + }, + "6; starting rotation 1 (east); rotation point 1": { matrix: Matrix{ {0, 0, 0}, @@ -1290,6 +1433,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 2, RotationCompass: RotationCompasses['6'], }, + wantRotationPoint: 1, }, "6; starting rotation 2 (south); rotation point 1": { matrix: Matrix{ @@ -1318,6 +1462,7 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 3, RotationCompass: RotationCompasses['6'], }, + wantRotationPoint: 1, }, "6; starting rotation 3 (west); rotation point 1": { matrix: Matrix{ @@ -1346,19 +1491,20 @@ func TestTetrimino_rotateClockwise(t *testing.T) { CompassDirection: 0, RotationCompass: RotationCompasses['6'], }, + wantRotationPoint: 1, }, } for name, tc := range tt { t.Run(name, func(t *testing.T) { - result, err := tc.tet.rotateClockwise(tc.matrix) + rotationPoint, err := tc.tet.rotateClockwise(tc.matrix) require.NoError(t, err) if tc.wantTet != nil { assert.EqualValues(t, tc.wantTet, tc.tet) - assert.True(t, result) + assert.Equal(t, tc.wantRotationPoint, rotationPoint) } else { - assert.False(t, result) + assert.Equal(t, invalidRotationPoint, rotationPoint) } }) } @@ -1711,7 +1857,7 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { result, err := tc.tet.rotateCounterClockwise(tc.matrix) require.NoError(t, err) - assert.True(t, result) + assert.Equal(t, invalidRotationPoint, result) assert.EqualValues(t, tc.wantTet, tc.tet) }) } From 110fb50d8243b0ffc3d77fa2516d1dc5400ec5c7 Mon Sep 17 00:00:00 2001 From: Broderick Westrope Date: Fri, 27 Sep 2024 13:07:41 +1000 Subject: [PATCH 2/5] test: finish adding cases for TestTetrimino_rotateClockwise --- pkg/tetris/tetrimino_test.go | 445 ++++++++++++++++++++++++++++++++++- 1 file changed, 439 insertions(+), 6 deletions(-) diff --git a/pkg/tetris/tetrimino_test.go b/pkg/tetris/tetrimino_test.go index d90625a..ee4eec2 100644 --- a/pkg/tetris/tetrimino_test.go +++ b/pkg/tetris/tetrimino_test.go @@ -1405,6 +1405,22 @@ func TestTetrimino_rotateClockwise(t *testing.T) { }, wantRotationPoint: 5, }, + "6; starting rotation 0 (north); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantTet: nil, + }, "6; starting rotation 1 (east); rotation point 1": { matrix: Matrix{ @@ -1435,6 +1451,140 @@ func TestTetrimino_rotateClockwise(t *testing.T) { }, wantRotationPoint: 1, }, + "6; starting rotation 1 (east); rotation point 2": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, + {true, true}, + {true, false}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, true, true}, + {false, true, false}, + }, + Pos: Coordinate{X: 0, Y: 1}, + CompassDirection: 2, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 2, + }, + "6; starting rotation 1 (east); rotation point 3": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, + {true, true}, + {true, false}, + }, + Pos: Coordinate{X: 0, Y: -2}, + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, true, true}, + {false, true, false}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 2, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 3, + }, + "6; starting rotation 1 (east); rotation point 4": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, + {true, true}, + {true, false}, + }, + Pos: Coordinate{X: 1, Y: 1}, + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, true, true}, + {false, true, false}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 2, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 4, + }, + "6; starting rotation 1 (east); rotation point 5": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, + {true, true}, + {true, false}, + }, + Pos: Coordinate{X: 0, Y: 1}, + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, true, true}, + {false, true, false}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 2, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 5, + }, + "6; starting rotation 1 (east); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, + {true, true}, + {true, false}, + }, + Pos: Coordinate{X: 0, Y: 1}, + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], + }, + wantTet: nil, + }, + "6; starting rotation 2 (south); rotation point 1": { matrix: Matrix{ {0, 0, 0}, @@ -1464,6 +1614,139 @@ func TestTetrimino_rotateClockwise(t *testing.T) { }, wantRotationPoint: 1, }, + "6; starting rotation 2 (south); rotation point 2": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, true, true}, + {false, true, false}, + }, + Pos: Coordinate{X: -1, Y: 1}, + CompassDirection: 2, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true}, + {true, true}, + {false, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 2, + }, + "6; starting rotation 2 (south); rotation point 3": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, true, true}, + {false, true, false}, + }, + Pos: Coordinate{X: -1, Y: 2}, + CompassDirection: 2, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true}, + {true, true}, + {false, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 3, + }, + "6; starting rotation 2 (south); rotation point 4": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, true, true}, + {false, true, false}, + }, + Pos: Coordinate{X: 0, Y: -1}, + CompassDirection: 2, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true}, + {true, true}, + {false, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 4, + }, + "6; starting rotation 2 (south); rotation point 5": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, true, true}, + {false, true, false}, + }, + Pos: Coordinate{X: -1, Y: -1}, + CompassDirection: 2, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true}, + {true, true}, + {false, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 5, + }, + "6; starting rotation 2 (south); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, true, true}, + {false, true, false}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 2, + RotationCompass: RotationCompasses['6'], + }, + wantTet: nil, + }, + "6; starting rotation 3 (west); rotation point 1": { matrix: Matrix{ {0, 0, 0}, @@ -1493,6 +1776,139 @@ func TestTetrimino_rotateClockwise(t *testing.T) { }, wantRotationPoint: 1, }, + "6; starting rotation 3 (west); rotation point 2": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true}, + {true, true}, + {false, true}, + }, + Pos: Coordinate{X: 1, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 2, + }, + "6; starting rotation 3 (west); rotation point 3": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true}, + {true, true}, + {false, true}, + }, + Pos: Coordinate{X: 1, Y: -1}, + CompassDirection: 3, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 3, + }, + "6; starting rotation 3 (west); rotation point 4": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true}, + {true, true}, + {false, true}, + }, + Pos: Coordinate{X: 0, Y: 2}, + CompassDirection: 3, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 4, + }, + "6; starting rotation 3 (west); rotation point 5": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true}, + {true, true}, + {false, true}, + }, + Pos: Coordinate{X: 1, Y: 2}, + CompassDirection: 3, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 5, + }, + "6; starting rotation 3 (west); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true}, + {true, true}, + {false, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['6'], + }, + wantTet: nil, + }, } for name, tc := range tt { @@ -1512,9 +1928,10 @@ func TestTetrimino_rotateClockwise(t *testing.T) { func TestTetrimino_rotateCounterClockwise(t *testing.T) { tt := map[string]struct { - matrix Matrix - tet *Tetrimino - wantTet *Tetrimino + matrix Matrix + tet *Tetrimino + wantTet *Tetrimino + wantRotationPoint int }{ "I; starting rotation 0 (north); rotation point 1": { matrix: Matrix{ @@ -1544,6 +1961,7 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { CompassDirection: 3, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 1, }, "I; starting rotation 1 (east); rotation point 1": { matrix: Matrix{ @@ -1573,6 +1991,7 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { CompassDirection: 0, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 1, }, "I; starting rotation 2 (south); rotation point 1": { matrix: Matrix{ @@ -1602,6 +2021,7 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { CompassDirection: 1, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 1, }, "I; starting rotation 3 (west); rotation point 1": { matrix: Matrix{ @@ -1631,6 +2051,7 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { CompassDirection: 2, RotationCompass: RotationCompasses['I'], }, + wantRotationPoint: 1, }, "O; starting rotation 0 (north); rotation point 1": { @@ -1658,6 +2079,7 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { CompassDirection: 3, RotationCompass: RotationCompasses['O'], }, + wantRotationPoint: 1, }, "O; starting rotation 1 (east); rotation point 1": { matrix: Matrix{ @@ -1684,6 +2106,7 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { CompassDirection: 0, RotationCompass: RotationCompasses['O'], }, + wantRotationPoint: 1, }, "O; starting rotation 2 (south); rotation point 1": { matrix: Matrix{ @@ -1710,6 +2133,7 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { CompassDirection: 1, RotationCompass: RotationCompasses['O'], }, + wantRotationPoint: 1, }, "O; starting rotation 3 (west); rotation point 1": { matrix: Matrix{ @@ -1736,6 +2160,7 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { CompassDirection: 2, RotationCompass: RotationCompasses['O'], }, + wantRotationPoint: 1, }, "6; starting rotation 0 (north); rotation point 1": { @@ -1765,6 +2190,7 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { CompassDirection: 3, RotationCompass: RotationCompasses['6'], }, + wantRotationPoint: 1, }, "6; starting rotation 1 (east); rotation point 1": { matrix: Matrix{ @@ -1793,6 +2219,7 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { CompassDirection: 0, RotationCompass: RotationCompasses['6'], }, + wantRotationPoint: 1, }, "6; starting rotation 2 (south); rotation point 1": { matrix: Matrix{ @@ -1821,6 +2248,7 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { CompassDirection: 1, RotationCompass: RotationCompasses['6'], }, + wantRotationPoint: 1, }, "6; starting rotation 3 (west); rotation point 1": { matrix: Matrix{ @@ -1849,16 +2277,21 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { CompassDirection: 2, RotationCompass: RotationCompasses['6'], }, + wantRotationPoint: 1, }, } for name, tc := range tt { t.Run(name, func(t *testing.T) { - result, err := tc.tet.rotateCounterClockwise(tc.matrix) + rotationPoint, err := tc.tet.rotateCounterClockwise(tc.matrix) require.NoError(t, err) - assert.Equal(t, invalidRotationPoint, result) - assert.EqualValues(t, tc.wantTet, tc.tet) + if tc.wantTet != nil { + assert.EqualValues(t, tc.wantTet, tc.tet) + assert.Equal(t, tc.wantRotationPoint, rotationPoint) + } else { + assert.Equal(t, invalidRotationPoint, rotationPoint) + } }) } } From 5ceb5be19365b659186a7d6d17d4f932e9ce1798 Mon Sep 17 00:00:00 2001 From: Broderick Westrope Date: Fri, 27 Sep 2024 13:18:12 +1000 Subject: [PATCH 3/5] test: add invalid cases for TestTetrimino_rotateCounterClockwise --- pkg/tetris/tetrimino_test.go | 205 +++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) diff --git a/pkg/tetris/tetrimino_test.go b/pkg/tetris/tetrimino_test.go index ee4eec2..71e6b56 100644 --- a/pkg/tetris/tetrimino_test.go +++ b/pkg/tetris/tetrimino_test.go @@ -1963,6 +1963,22 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { }, wantRotationPoint: 1, }, + "I; starting rotation 0 (north); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true, true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['I'], + }, + wantTet: nil, + }, + "I; starting rotation 1 (east); rotation point 1": { matrix: Matrix{ {0, 0, 0, 0}, @@ -1993,6 +2009,25 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { }, wantRotationPoint: 1, }, + "I; starting rotation 1 (east); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 2, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['I'], + }, + wantTet: nil, + }, + "I; starting rotation 2 (south); rotation point 1": { matrix: Matrix{ {0, 0, 0, 0}, @@ -2023,6 +2058,22 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { }, wantRotationPoint: 1, }, + "I; starting rotation 2 (south); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true, true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 2}, + CompassDirection: 2, + RotationCompass: RotationCompasses['I'], + }, + wantTet: nil, + }, + "I; starting rotation 3 (west); rotation point 1": { matrix: Matrix{ {0, 0, 0, 0}, @@ -2053,6 +2104,24 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { }, wantRotationPoint: 1, }, + "I; starting rotation 3 (west); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 1, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['I'], + }, + wantTet: nil, + }, "O; starting rotation 0 (north); rotation point 1": { matrix: Matrix{ @@ -2081,6 +2150,23 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { }, wantRotationPoint: 1, }, + "O; starting rotation 0 (north); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'O', + Minos: [][]bool{ + {true, true}, + {true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['O'], + }, + wantTet: nil, + }, + "O; starting rotation 1 (east); rotation point 1": { matrix: Matrix{ {0, 0}, @@ -2108,6 +2194,23 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { }, wantRotationPoint: 1, }, + "O; starting rotation 1 (east); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'O', + Minos: [][]bool{ + {true, true}, + {true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['O'], + }, + wantTet: nil, + }, + "O; starting rotation 2 (south); rotation point 1": { matrix: Matrix{ {0, 0}, @@ -2135,6 +2238,23 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { }, wantRotationPoint: 1, }, + "O; starting rotation 2 (south); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'O', + Minos: [][]bool{ + {true, true}, + {true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 2, + RotationCompass: RotationCompasses['O'], + }, + wantTet: nil, + }, + "O; starting rotation 3 (west); rotation point 1": { matrix: Matrix{ {0, 0}, @@ -2162,6 +2282,22 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { }, wantRotationPoint: 1, }, + "O; starting rotation 3 (west); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'O', + Minos: [][]bool{ + {true, true}, + {true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['O'], + }, + wantTet: nil, + }, "6; starting rotation 0 (north); rotation point 1": { matrix: Matrix{ @@ -2192,6 +2328,23 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { }, wantRotationPoint: 1, }, + "6; starting rotation 0 (north); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantTet: nil, + }, + "6; starting rotation 1 (east); rotation point 1": { matrix: Matrix{ {0, 0, 0}, @@ -2221,6 +2374,24 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { }, wantRotationPoint: 1, }, + "6; starting rotation 1 (east); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, + {true, true}, + {true, false}, + }, + Pos: Coordinate{X: 1, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], + }, + wantTet: nil, + }, + "6; starting rotation 2 (south); rotation point 1": { matrix: Matrix{ {0, 0, 0}, @@ -2250,6 +2421,23 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { }, wantRotationPoint: 1, }, + "6; starting rotation 2 (south); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, true, true}, + {false, true, false}, + }, + Pos: Coordinate{X: 0, Y: 1}, + CompassDirection: 2, + RotationCompass: RotationCompasses['6'], + }, + wantTet: nil, + }, + "6; starting rotation 3 (west); rotation point 1": { matrix: Matrix{ {0, 0, 0}, @@ -2279,6 +2467,23 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { }, wantRotationPoint: 1, }, + "6; starting rotation 3 (west); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true}, + {true, true}, + {false, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['6'], + }, + wantTet: nil, + }, } for name, tc := range tt { From dfb5c967ade3fa92f59bdd45482aeb3356fe7d90 Mon Sep 17 00:00:00 2001 From: Broderick Westrope Date: Fri, 27 Sep 2024 13:49:24 +1000 Subject: [PATCH 4/5] test: finish adding cases for TestTetrimino_rotateCounterClockwise --- pkg/tetris/tetrimino_test.go | 1266 +++++++++++++++++++++++++++++----- 1 file changed, 1089 insertions(+), 177 deletions(-) diff --git a/pkg/tetris/tetrimino_test.go b/pkg/tetris/tetrimino_test.go index 71e6b56..79fba15 100644 --- a/pkg/tetris/tetrimino_test.go +++ b/pkg/tetris/tetrimino_test.go @@ -1963,30 +1963,23 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { }, wantRotationPoint: 1, }, - "I; starting rotation 0 (north); no valid rotation": { + "I; starting rotation 0 (north); rotation point 2": { matrix: Matrix{ {0}, + {0}, + {0}, + {0}, }, tet: &Tetrimino{ Value: 'I', Minos: [][]bool{ {true, true, true, true}, }, - Pos: Coordinate{X: 0, Y: 0}, + Pos: Coordinate{X: 0, Y: 1}, CompassDirection: 0, RotationCompass: RotationCompasses['I'], }, - wantTet: nil, - }, - - "I; starting rotation 1 (east); rotation point 1": { - matrix: Matrix{ - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - }, - tet: &Tetrimino{ + wantTet: &Tetrimino{ Value: 'I', Minos: [][]bool{ {true}, @@ -1994,26 +1987,59 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { {true}, {true}, }, - Pos: Coordinate{X: 2, Y: 0}, - CompassDirection: 1, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, RotationCompass: RotationCompasses['I'], }, - wantTet: &Tetrimino{ + wantRotationPoint: 2, + }, + "I; starting rotation 0 (north); rotation point 3": { + matrix: Matrix{ + {0}, + {0}, + {0}, + {0}, + }, + tet: &Tetrimino{ Value: 'I', Minos: [][]bool{ {true, true, true, true}, }, - Pos: Coordinate{X: 0, Y: 1}, + Pos: Coordinate{X: -3, Y: 1}, CompassDirection: 0, RotationCompass: RotationCompasses['I'], }, - wantRotationPoint: 1, + wantTet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['I'], + }, + wantRotationPoint: 3, }, - "I; starting rotation 1 (east); no valid rotation": { + "I; starting rotation 0 (north); rotation point 4": { matrix: Matrix{ {0}, + {0}, + {0}, + {0}, }, tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true, true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 3}, + CompassDirection: 0, + RotationCompass: RotationCompasses['I'], + }, + wantTet: &Tetrimino{ Value: 'I', Minos: [][]bool{ {true}, @@ -2021,27 +2047,26 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { {true}, {true}, }, - Pos: Coordinate{X: 2, Y: 0}, - CompassDirection: 1, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, RotationCompass: RotationCompasses['I'], }, - wantTet: nil, + wantRotationPoint: 4, }, - - "I; starting rotation 2 (south); rotation point 1": { + "I; starting rotation 0 (north); rotation point 5": { matrix: Matrix{ - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, + {0}, + {0}, + {0}, + {0}, }, tet: &Tetrimino{ Value: 'I', Minos: [][]bool{ {true, true, true, true}, }, - Pos: Coordinate{X: 0, Y: 2}, - CompassDirection: 2, + Pos: Coordinate{X: -3, Y: 0}, + CompassDirection: 0, RotationCompass: RotationCompasses['I'], }, wantTet: &Tetrimino{ @@ -2052,13 +2077,13 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { {true}, {true}, }, - Pos: Coordinate{X: 2, Y: 0}, - CompassDirection: 1, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, RotationCompass: RotationCompasses['I'], }, - wantRotationPoint: 1, + wantRotationPoint: 5, }, - "I; starting rotation 2 (south); no valid rotation": { + "I; starting rotation 0 (north); no valid rotation": { matrix: Matrix{ {0}, }, @@ -2067,14 +2092,14 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { Minos: [][]bool{ {true, true, true, true}, }, - Pos: Coordinate{X: 0, Y: 2}, - CompassDirection: 2, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, RotationCompass: RotationCompasses['I'], }, wantTet: nil, }, - "I; starting rotation 3 (west); rotation point 1": { + "I; starting rotation 1 (east); rotation point 1": { matrix: Matrix{ {0, 0, 0, 0}, {0, 0, 0, 0}, @@ -2089,8 +2114,8 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { {true}, {true}, }, - Pos: Coordinate{X: 1, Y: 0}, - CompassDirection: 3, + Pos: Coordinate{X: 2, Y: 0}, + CompassDirection: 1, RotationCompass: RotationCompasses['I'], }, wantTet: &Tetrimino{ @@ -2098,15 +2123,15 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { Minos: [][]bool{ {true, true, true, true}, }, - Pos: Coordinate{X: 0, Y: 2}, - CompassDirection: 2, + Pos: Coordinate{X: 0, Y: 1}, + CompassDirection: 0, RotationCompass: RotationCompasses['I'], }, wantRotationPoint: 1, }, - "I; starting rotation 3 (west); no valid rotation": { + "I; starting rotation 1 (east); rotation point 2": { matrix: Matrix{ - {0}, + {0, 0, 0, 0}, }, tet: &Tetrimino{ Value: 'I', @@ -2116,236 +2141,1104 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { {true}, {true}, }, - Pos: Coordinate{X: 1, Y: 0}, - CompassDirection: 3, + Pos: Coordinate{X: 0, Y: -1}, + CompassDirection: 1, RotationCompass: RotationCompasses['I'], }, - wantTet: nil, + wantTet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true, true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['I'], + }, + wantRotationPoint: 2, }, - - "O; starting rotation 0 (north); rotation point 1": { + "I; starting rotation 1 (east); rotation point 3": { matrix: Matrix{ - {0, 0}, - {0, 0}, + {0, 0, 0, 0}, }, tet: &Tetrimino{ - Value: 'O', + Value: 'I', Minos: [][]bool{ - {true, true}, - {true, true}, + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 3, Y: -1}, + CompassDirection: 1, + RotationCompass: RotationCompasses['I'], + }, + wantTet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true, true, true, true}, }, Pos: Coordinate{X: 0, Y: 0}, CompassDirection: 0, - RotationCompass: RotationCompasses['O'], + RotationCompass: RotationCompasses['I'], + }, + wantRotationPoint: 3, + }, + "I; starting rotation 1 (east); rotation point 4": { + matrix: Matrix{ + {0, 0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['I'], }, wantTet: &Tetrimino{ - Value: 'O', + Value: 'I', Minos: [][]bool{ - {true, true}, - {true, true}, + {true, true, true, true}, }, Pos: Coordinate{X: 0, Y: 0}, - CompassDirection: 3, - RotationCompass: RotationCompasses['O'], + CompassDirection: 0, + RotationCompass: RotationCompasses['I'], }, - wantRotationPoint: 1, + wantRotationPoint: 4, }, - "O; starting rotation 0 (north); no valid rotation": { + "I; starting rotation 1 (east); rotation point 5": { matrix: Matrix{ - {0}, + {0, 0, 0, 0}, }, tet: &Tetrimino{ - Value: 'O', + Value: 'I', Minos: [][]bool{ - {true, true}, - {true, true}, + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 3, Y: -3}, + CompassDirection: 1, + RotationCompass: RotationCompasses['I'], + }, + wantTet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true, true, true, true}, }, Pos: Coordinate{X: 0, Y: 0}, CompassDirection: 0, - RotationCompass: RotationCompasses['O'], + RotationCompass: RotationCompasses['I'], + }, + wantRotationPoint: 5, + }, + "I; starting rotation 1 (east); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 2, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['I'], }, wantTet: nil, }, - "O; starting rotation 1 (east); rotation point 1": { + "I; starting rotation 2 (south); rotation point 1": { matrix: Matrix{ - {0, 0}, - {0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, }, tet: &Tetrimino{ - Value: 'O', + Value: 'I', Minos: [][]bool{ - {true, true}, - {true, true}, + {true, true, true, true}, }, - Pos: Coordinate{X: 0, Y: 0}, + Pos: Coordinate{X: 0, Y: 2}, + CompassDirection: 2, + RotationCompass: RotationCompasses['I'], + }, + wantTet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 2, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['I'], + }, + wantRotationPoint: 1, + }, + "I; starting rotation 2 (south); rotation point 2": { + matrix: Matrix{ + {0}, + {0}, + {0}, + {0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true, true, true, true}, + }, + Pos: Coordinate{X: -3, Y: 2}, + CompassDirection: 2, + RotationCompass: RotationCompasses['I'], + }, + wantTet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['I'], + }, + wantRotationPoint: 2, + }, + "I; starting rotation 2 (south); rotation point 3": { + matrix: Matrix{ + {0}, + {0}, + {0}, + {0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true, true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 2}, + CompassDirection: 2, + RotationCompass: RotationCompasses['I'], + }, + wantTet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['I'], + }, + wantRotationPoint: 3, + }, + "I; starting rotation 2 (south); rotation point 4": { + matrix: Matrix{ + {0}, + {0}, + {0}, + {0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true, true, true, true}, + }, + Pos: Coordinate{X: -3, Y: 0}, + CompassDirection: 2, + RotationCompass: RotationCompasses['I'], + }, + wantTet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['I'], + }, + wantRotationPoint: 4, + }, + "I; starting rotation 2 (south); rotation point 5": { + matrix: Matrix{ + {0}, + {0}, + {0}, + {0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true, true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 3}, + CompassDirection: 2, + RotationCompass: RotationCompasses['I'], + }, + wantTet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['I'], + }, + wantRotationPoint: 5, + }, + "I; starting rotation 2 (south); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true, true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 2}, + CompassDirection: 2, + RotationCompass: RotationCompasses['I'], + }, + wantTet: nil, + }, + + "I; starting rotation 3 (west); rotation point 1": { + matrix: Matrix{ + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 1, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['I'], + }, + wantTet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true, true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 2}, + CompassDirection: 2, + RotationCompass: RotationCompasses['I'], + }, + wantRotationPoint: 1, + }, + "I; starting rotation 3 (west); rotation point 2": { + matrix: Matrix{ + {0, 0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 3, Y: -2}, + CompassDirection: 3, + RotationCompass: RotationCompasses['I'], + }, + wantTet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true, true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 2, + RotationCompass: RotationCompasses['I'], + }, + wantRotationPoint: 2, + }, + "I; starting rotation 3 (west); rotation point 3": { + matrix: Matrix{ + {0, 0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 0, Y: -2}, + CompassDirection: 3, + RotationCompass: RotationCompasses['I'], + }, + wantTet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true, true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 2, + RotationCompass: RotationCompasses['I'], + }, + wantRotationPoint: 3, + }, + "I; starting rotation 3 (west); rotation point 4": { + matrix: Matrix{ + {0, 0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 3, Y: -3}, + CompassDirection: 3, + RotationCompass: RotationCompasses['I'], + }, + wantTet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true, true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 2, + RotationCompass: RotationCompasses['I'], + }, + wantRotationPoint: 4, + }, + "I; starting rotation 3 (west); rotation point 5": { + matrix: Matrix{ + {0, 0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['I'], + }, + wantTet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true, true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 2, + RotationCompass: RotationCompasses['I'], + }, + wantRotationPoint: 5, + }, + "I; starting rotation 3 (west); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'I', + Minos: [][]bool{ + {true}, + {true}, + {true}, + {true}, + }, + Pos: Coordinate{X: 1, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['I'], + }, + wantTet: nil, + }, + + "O; starting rotation 0 (north); rotation point 1": { + matrix: Matrix{ + {0, 0}, + {0, 0}, + }, + tet: &Tetrimino{ + Value: 'O', + Minos: [][]bool{ + {true, true}, + {true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['O'], + }, + wantTet: &Tetrimino{ + Value: 'O', + Minos: [][]bool{ + {true, true}, + {true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['O'], + }, + wantRotationPoint: 1, + }, + "O; starting rotation 0 (north); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'O', + Minos: [][]bool{ + {true, true}, + {true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['O'], + }, + wantTet: nil, + }, + + "O; starting rotation 1 (east); rotation point 1": { + matrix: Matrix{ + {0, 0}, + {0, 0}, + }, + tet: &Tetrimino{ + Value: 'O', + Minos: [][]bool{ + {true, true}, + {true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['O'], + }, + wantTet: &Tetrimino{ + Value: 'O', + Minos: [][]bool{ + {true, true}, + {true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['O'], + }, + wantRotationPoint: 1, + }, + "O; starting rotation 1 (east); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'O', + Minos: [][]bool{ + {true, true}, + {true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['O'], + }, + wantTet: nil, + }, + + "O; starting rotation 2 (south); rotation point 1": { + matrix: Matrix{ + {0, 0}, + {0, 0}, + }, + tet: &Tetrimino{ + Value: 'O', + Minos: [][]bool{ + {true, true}, + {true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 2, + RotationCompass: RotationCompasses['O'], + }, + wantTet: &Tetrimino{ + Value: 'O', + Minos: [][]bool{ + {true, true}, + {true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['O'], + }, + wantRotationPoint: 1, + }, + "O; starting rotation 2 (south); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'O', + Minos: [][]bool{ + {true, true}, + {true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 2, + RotationCompass: RotationCompasses['O'], + }, + wantTet: nil, + }, + + "O; starting rotation 3 (west); rotation point 1": { + matrix: Matrix{ + {0, 0}, + {0, 0}, + }, + tet: &Tetrimino{ + Value: 'O', + Minos: [][]bool{ + {true, true}, + {true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['O'], + }, + wantTet: &Tetrimino{ + Value: 'O', + Minos: [][]bool{ + {true, true}, + {true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 2, + RotationCompass: RotationCompasses['O'], + }, + wantRotationPoint: 1, + }, + "O; starting rotation 3 (west); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'O', + Minos: [][]bool{ + {true, true}, + {true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['O'], + }, + wantTet: nil, + }, + + "6; starting rotation 0 (north); rotation point 1": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true}, + {true, true}, + {false, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 1, + }, + "6; starting rotation 0 (north); rotation point 2": { + matrix: Matrix{ + {0, 0}, + {0, 0}, + {0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: -1, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true}, + {true, true}, + {false, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 2, + }, + "6; starting rotation 0 (north); rotation point 3": { + matrix: Matrix{ + {0, 0}, + {0, 0}, + {0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: -1, Y: 1}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true}, + {true, true}, + {false, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 3, + }, + "6; starting rotation 0 (north); rotation point 4": { + matrix: Matrix{ + {0, 0}, + {0, 0}, + {0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: 0, Y: -2}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true}, + {true, true}, + {false, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 4, + }, + "6; starting rotation 0 (north); rotation point 5": { + matrix: Matrix{ + {0, 0}, + {0, 0}, + {0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: -1, Y: -2}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true}, + {true, true}, + {false, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 5, + }, + "6; starting rotation 0 (north); no valid rotation": { + matrix: Matrix{ + {0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantTet: nil, + }, + + "6; starting rotation 1 (east); rotation point 1": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, + {true, true}, + {true, false}, + }, + Pos: Coordinate{X: 1, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 1, + }, + "6; starting rotation 1 (east); rotation point 2": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, + {true, true}, + {true, false}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 2, + }, + "6; starting rotation 1 (east); rotation point 3": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, + {true, true}, + {true, false}, + }, + Pos: Coordinate{X: 0, Y: -1}, + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 3, + }, + "6; starting rotation 1 (east); rotation point 4": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, + {true, true}, + {true, false}, + }, + Pos: Coordinate{X: 1, Y: 2}, + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true, false}, + {true, true, true}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 0, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 4, + }, + "6; starting rotation 1 (east); rotation point 5": { + matrix: Matrix{ + {0, 0, 0}, + {0, 0, 0}, + }, + tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, + {true, true}, + {true, false}, + }, + Pos: Coordinate{X: 0, Y: 2}, CompassDirection: 1, - RotationCompass: RotationCompasses['O'], + RotationCompass: RotationCompasses['6'], }, wantTet: &Tetrimino{ - Value: 'O', + Value: 'T', Minos: [][]bool{ - {true, true}, - {true, true}, + {false, true, false}, + {true, true, true}, }, Pos: Coordinate{X: 0, Y: 0}, CompassDirection: 0, - RotationCompass: RotationCompasses['O'], + RotationCompass: RotationCompasses['6'], }, - wantRotationPoint: 1, + wantRotationPoint: 5, }, - "O; starting rotation 1 (east); no valid rotation": { + "6; starting rotation 1 (east); no valid rotation": { matrix: Matrix{ {0}, }, tet: &Tetrimino{ - Value: 'O', + Value: 'T', Minos: [][]bool{ + {true, false}, {true, true}, - {true, true}, + {true, false}, }, - Pos: Coordinate{X: 0, Y: 0}, + Pos: Coordinate{X: 1, Y: 0}, CompassDirection: 1, - RotationCompass: RotationCompasses['O'], + RotationCompass: RotationCompasses['6'], }, wantTet: nil, }, - "O; starting rotation 2 (south); rotation point 1": { + "6; starting rotation 2 (south); rotation point 1": { matrix: Matrix{ - {0, 0}, - {0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, }, tet: &Tetrimino{ - Value: 'O', + Value: 'T', Minos: [][]bool{ - {true, true}, - {true, true}, + {true, true, true}, + {false, true, false}, }, - Pos: Coordinate{X: 0, Y: 0}, + Pos: Coordinate{X: 0, Y: 1}, CompassDirection: 2, - RotationCompass: RotationCompasses['O'], + RotationCompass: RotationCompasses['6'], }, wantTet: &Tetrimino{ - Value: 'O', + Value: 'T', Minos: [][]bool{ + {true, false}, {true, true}, - {true, true}, + {true, false}, }, - Pos: Coordinate{X: 0, Y: 0}, + Pos: Coordinate{X: 1, Y: 0}, CompassDirection: 1, - RotationCompass: RotationCompasses['O'], + RotationCompass: RotationCompasses['6'], }, wantRotationPoint: 1, }, - "O; starting rotation 2 (south); no valid rotation": { + "6; starting rotation 2 (south); rotation point 2": { matrix: Matrix{ - {0}, + {0, 0}, + {0, 0}, + {0, 0}, }, tet: &Tetrimino{ - Value: 'O', + Value: 'T', Minos: [][]bool{ + {true, true, true}, + {false, true, false}, + }, + Pos: Coordinate{X: 0, Y: 1}, + CompassDirection: 2, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, {true, true}, - {true, true}, + {true, false}, }, Pos: Coordinate{X: 0, Y: 0}, - CompassDirection: 2, - RotationCompass: RotationCompasses['O'], + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], }, - wantTet: nil, + wantRotationPoint: 2, }, - - "O; starting rotation 3 (west); rotation point 1": { + "6; starting rotation 2 (south); rotation point 3": { matrix: Matrix{ {0, 0}, {0, 0}, + {0, 0}, }, tet: &Tetrimino{ - Value: 'O', + Value: 'T', Minos: [][]bool{ - {true, true}, - {true, true}, + {true, true, true}, + {false, true, false}, }, - Pos: Coordinate{X: 0, Y: 0}, - CompassDirection: 3, - RotationCompass: RotationCompasses['O'], + Pos: Coordinate{X: 0, Y: 2}, + CompassDirection: 2, + RotationCompass: RotationCompasses['6'], }, wantTet: &Tetrimino{ - Value: 'O', + Value: 'T', Minos: [][]bool{ + {true, false}, {true, true}, - {true, true}, + {true, false}, }, Pos: Coordinate{X: 0, Y: 0}, - CompassDirection: 2, - RotationCompass: RotationCompasses['O'], + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], }, - wantRotationPoint: 1, + wantRotationPoint: 3, }, - "O; starting rotation 3 (west); no valid rotation": { + "6; starting rotation 2 (south); rotation point 4": { matrix: Matrix{ - {0}, + {0, 0}, + {0, 0}, + {0, 0}, }, tet: &Tetrimino{ - Value: 'O', + Value: 'T', Minos: [][]bool{ + {true, true, true}, + {false, true, false}, + }, + Pos: Coordinate{X: -1, Y: -1}, + CompassDirection: 2, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, false}, {true, true}, - {true, true}, + {true, false}, }, Pos: Coordinate{X: 0, Y: 0}, - CompassDirection: 3, - RotationCompass: RotationCompasses['O'], + CompassDirection: 1, + RotationCompass: RotationCompasses['6'], }, - wantTet: nil, + wantRotationPoint: 4, }, - - "6; starting rotation 0 (north); rotation point 1": { + "6; starting rotation 2 (south); rotation point 5": { matrix: Matrix{ - {0, 0, 0}, - {0, 0, 0}, - {0, 0, 0}, + {0, 0}, + {0, 0}, + {0, 0}, }, tet: &Tetrimino{ Value: 'T', Minos: [][]bool{ - {false, true, false}, {true, true, true}, + {false, true, false}, }, - Pos: Coordinate{X: 0, Y: 0}, - CompassDirection: 0, + Pos: Coordinate{X: 0, Y: -1}, + CompassDirection: 2, RotationCompass: RotationCompasses['6'], }, wantTet: &Tetrimino{ Value: 'T', Minos: [][]bool{ - {false, true}, + {true, false}, {true, true}, - {false, true}, + {true, false}, }, Pos: Coordinate{X: 0, Y: 0}, - CompassDirection: 3, + CompassDirection: 1, RotationCompass: RotationCompasses['6'], }, - wantRotationPoint: 1, + wantRotationPoint: 5, }, - "6; starting rotation 0 (north); no valid rotation": { + "6; starting rotation 2 (south); no valid rotation": { matrix: Matrix{ {0}, }, tet: &Tetrimino{ Value: 'T', Minos: [][]bool{ - {false, true, false}, {true, true, true}, + {false, true, false}, }, - Pos: Coordinate{X: 0, Y: 0}, - CompassDirection: 0, + Pos: Coordinate{X: 0, Y: 1}, + CompassDirection: 2, RotationCompass: RotationCompasses['6'], }, wantTet: nil, }, - "6; starting rotation 1 (east); rotation point 1": { + "6; starting rotation 3 (west); rotation point 1": { matrix: Matrix{ {0, 0, 0}, {0, 0, 0}, @@ -2354,95 +3247,114 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { tet: &Tetrimino{ Value: 'T', Minos: [][]bool{ - {true, false}, + {false, true}, {true, true}, - {true, false}, + {false, true}, }, - Pos: Coordinate{X: 1, Y: 0}, - CompassDirection: 1, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 3, RotationCompass: RotationCompasses['6'], }, wantTet: &Tetrimino{ Value: 'T', Minos: [][]bool{ - {false, true, false}, {true, true, true}, + {false, true, false}, }, - Pos: Coordinate{X: 0, Y: 0}, - CompassDirection: 0, + Pos: Coordinate{X: 0, Y: 1}, + CompassDirection: 2, RotationCompass: RotationCompasses['6'], }, wantRotationPoint: 1, }, - "6; starting rotation 1 (east); no valid rotation": { + "6; starting rotation 3 (west); rotation point 2": { matrix: Matrix{ - {0}, + {0, 0, 0}, + {0, 0, 0}, }, tet: &Tetrimino{ Value: 'T', Minos: [][]bool{ - {true, false}, + {false, true}, {true, true}, - {true, false}, + {false, true}, }, - Pos: Coordinate{X: 1, Y: 0}, - CompassDirection: 1, + Pos: Coordinate{X: 1, Y: -1}, + CompassDirection: 3, RotationCompass: RotationCompasses['6'], }, - wantTet: nil, + wantTet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {true, true, true}, + {false, true, false}, + }, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 2, + RotationCompass: RotationCompasses['6'], + }, + wantRotationPoint: 2, }, - - "6; starting rotation 2 (south); rotation point 1": { + "6; starting rotation 3 (west); rotation point 3": { matrix: Matrix{ {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, }, tet: &Tetrimino{ Value: 'T', Minos: [][]bool{ - {true, true, true}, - {false, true, false}, + {false, true}, + {true, true}, + {false, true}, }, - Pos: Coordinate{X: 0, Y: 1}, - CompassDirection: 2, + Pos: Coordinate{X: 1, Y: -2}, + CompassDirection: 3, RotationCompass: RotationCompasses['6'], }, wantTet: &Tetrimino{ Value: 'T', Minos: [][]bool{ - {true, false}, - {true, true}, - {true, false}, + {true, true, true}, + {false, true, false}, }, - Pos: Coordinate{X: 1, Y: 0}, - CompassDirection: 1, + Pos: Coordinate{X: 0, Y: 0}, + CompassDirection: 2, RotationCompass: RotationCompasses['6'], }, - wantRotationPoint: 1, + wantRotationPoint: 3, }, - "6; starting rotation 2 (south); no valid rotation": { + "6; starting rotation 3 (west); rotation point 4": { matrix: Matrix{ - {0}, + {0, 0, 0}, + {0, 0, 0}, }, tet: &Tetrimino{ + Value: 'T', + Minos: [][]bool{ + {false, true}, + {true, true}, + {false, true}, + }, + Pos: Coordinate{X: 0, Y: 1}, + CompassDirection: 3, + RotationCompass: RotationCompasses['6'], + }, + wantTet: &Tetrimino{ Value: 'T', Minos: [][]bool{ {true, true, true}, {false, true, false}, }, - Pos: Coordinate{X: 0, Y: 1}, + Pos: Coordinate{X: 0, Y: 0}, CompassDirection: 2, RotationCompass: RotationCompasses['6'], }, - wantTet: nil, + wantRotationPoint: 4, }, - - "6; starting rotation 3 (west); rotation point 1": { + "6; starting rotation 3 (west); rotation point 5": { matrix: Matrix{ {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, }, tet: &Tetrimino{ Value: 'T', @@ -2451,7 +3363,7 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { {true, true}, {false, true}, }, - Pos: Coordinate{X: 0, Y: 0}, + Pos: Coordinate{X: 1, Y: 1}, CompassDirection: 3, RotationCompass: RotationCompasses['6'], }, @@ -2461,11 +3373,11 @@ func TestTetrimino_rotateCounterClockwise(t *testing.T) { {true, true, true}, {false, true, false}, }, - Pos: Coordinate{X: 0, Y: 1}, + Pos: Coordinate{X: 0, Y: 0}, CompassDirection: 2, RotationCompass: RotationCompasses['6'], }, - wantRotationPoint: 1, + wantRotationPoint: 5, }, "6; starting rotation 3 (west); no valid rotation": { matrix: Matrix{ From 9a9b792da431988781a78904dab2fe4def9a294e Mon Sep 17 00:00:00 2001 From: Broderick Westrope Date: Fri, 27 Sep 2024 13:51:34 +1000 Subject: [PATCH 5/5] docs(readme): update todo list --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 4603ddb..0f0322b 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,6 @@ The ordered priorities for testing are: ### TODO - Add more tests - - Finish Super Rotation System testing in [tetrimino_test.go](./pkg/tetris/tetrimino_test.go). - Add tests for scoring endOnMaxLevel. - Revisit scoring tests. - Add the remaining Lock Down options.