-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ali Yousuf <[email protected]>
- Loading branch information
1 parent
6a04081
commit 2814fba
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package twenty48_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/alyyousuf7/twenty48" | ||
) | ||
|
||
func TestGridTranspose(t *testing.T) { | ||
// prepare data | ||
grid := twenty48.Grid{ | ||
twenty48.Row{1, 2, 3, 4, 5}, | ||
twenty48.Row{6, 7, 8, 9, 10}, | ||
twenty48.Row{11, 12, 13, 14, 15}, | ||
twenty48.Row{16, 17, 18, 19, 20}, | ||
} | ||
|
||
expectedGrid := twenty48.Grid{ | ||
twenty48.Row{1, 6, 11, 16}, | ||
twenty48.Row{2, 7, 12, 17}, | ||
twenty48.Row{3, 8, 13, 18}, | ||
twenty48.Row{4, 9, 14, 19}, | ||
twenty48.Row{5, 10, 15, 20}, | ||
} | ||
|
||
// do reverse | ||
newGrid := grid.Transpose() | ||
|
||
// check if the values are as expected | ||
for kr, r := range expectedGrid { | ||
for kc, c := range r { | ||
if c.Value() != newGrid[kr][kc].Value() { | ||
t.Errorf("Transposed grid did not return expected result") | ||
break | ||
} | ||
} | ||
} | ||
} | ||
|
||
func TestGridString(t *testing.T) { | ||
// prepare data | ||
grid := twenty48.Grid{ | ||
twenty48.Row{1, 2, 3, 4, 5, 6}, | ||
twenty48.Row{7, 8, 9, 10, 11, 12}, | ||
} | ||
|
||
expectedStr := "123456789101112" | ||
|
||
str := grid.String() | ||
|
||
if expectedStr != str { | ||
t.Errorf("Expected %s, but got %s", expectedStr, str) | ||
} | ||
} |