Skip to content

Commit

Permalink
test: add TestTranspose
Browse files Browse the repository at this point in the history
  • Loading branch information
Broderick-Westrope committed Nov 12, 2023
1 parent f6c0719 commit 6b776d1
Showing 1 changed file with 76 additions and 16 deletions.
92 changes: 76 additions & 16 deletions tetrimino_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"reflect"
"testing"
)

Expand Down Expand Up @@ -513,35 +514,60 @@ func TestTetrimino_MoveRight(t *testing.T) {
}
}

func TestIsOutOfBoundsHorizontally(t *testing.T) {
playfield := &Playfield{}

func TestTranspose(t *testing.T) {
tt := []struct {
name string
tetPosX int
cellCol int
expects bool
name string
tet *Tetrimino
expectedCells [][]bool
}{
{
"out left", 0, -1, true,
},
{
"in left", -1, 1, false,
"1x2",
&Tetrimino{
Cells: [][]bool{
{true, false},
},
},
[][]bool{
{true},
{false},
},
},
{
"in right", 10, -1, false,
"2x2",
&Tetrimino{
Cells: [][]bool{
{true, false},
{true, false},
},
},
[][]bool{
{true, true},
{false, false},
},
},
{
"out right", 10, 0, true,
"3x3",
&Tetrimino{
Cells: [][]bool{
{true, false, true},
{true, false, false},
{true, false, true},
},
},
[][]bool{
{true, true, true},
{false, false, false},
{true, false, true},
},
},
}

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
result := isOutOfBoundsHorizontally(tc.tetPosX, tc.cellCol, playfield)
tc.tet.transpose()

if result != tc.expects {
t.Errorf("got %v, want %v", result, tc.expects)
if !reflect.DeepEqual(tc.tet.Cells, tc.expectedCells) {
t.Errorf("got %v,\nwant %v", tc.tet.Cells, tc.expectedCells)
}
})
}
Expand Down Expand Up @@ -701,6 +727,40 @@ func TestCanRotate(t *testing.T) {
}
}

func TestIsOutOfBoundsHorizontally(t *testing.T) {
playfield := &Playfield{}

tt := []struct {
name string
tetPosX int
cellCol int
expects bool
}{
{
"out left", 0, -1, true,
},
{
"in left", -1, 1, false,
},
{
"in right", 10, -1, false,
},
{
"out right", 10, 0, true,
},
}

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
result := isOutOfBoundsHorizontally(tc.tetPosX, tc.cellCol, playfield)

if result != tc.expects {
t.Errorf("got %v, want %v", result, tc.expects)
}
})
}
}

func TestIsOutOfBoundsVertically(t *testing.T) {
playfield := &Playfield{}

Expand Down

0 comments on commit 6b776d1

Please sign in to comment.