From 6fa0c30358a7e5ddd5324514efc304d5d5e69876 Mon Sep 17 00:00:00 2001 From: gloriaswj Date: Sat, 3 Apr 2021 01:39:30 -0700 Subject: [PATCH 1/4] Add unit test for drop candy --- game/gamemap/dropcandy_test.go | 74 ++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 game/gamemap/dropcandy_test.go diff --git a/game/gamemap/dropcandy_test.go b/game/gamemap/dropcandy_test.go new file mode 100644 index 0000000..8211356 --- /dev/null +++ b/game/gamemap/dropcandy_test.go @@ -0,0 +1,74 @@ +package gamemap + +import ( + "candy/game/square" + "testing" + + "github.com/stretchr/testify/assert" +) + + +func TestDropCandyChecker_CanDropCandy(t *testing.T) { + + gamemap := &Map { + screenX:3, + screenY:3, + batch: nil, + maxRow: 4, + maxCol: 4, + gridXOffset: 3, + gridYOffset: 3, + grid: &[][]square.Square{ + {nil, nil, nil, nil}, + {nil, nil, nil, nil}, + {nil, nil, nil, nil}, + {nil, nil, nil, nil}, + }, + + } + dropCandyChecker := NewDropCandyChecker(gamemap) + + testCases := []struct{ + name string + playerX int + playerY int + playerWidth int + playerHeight int + threshold bool + }{ + { name: "testcase1", + playerX: 1, + playerY: 2, + playerWidth: 1, + playerHeight: 1, + threshold: true, + }, + } + + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T){ + canDropCandyChecker := + dropCandyChecker.CanDropCandy( + testCase.playerX, + testCase.playerY, + testCase.playerWidth, + testCase.playerHeight) + assert.Equal(t, testCase.threshold, canDropCandyChecker) + }) + } + +} + + + + + + + + + + + + + + From 2bf7fec19c6c585b932e619e76b5bf5c16a37091 Mon Sep 17 00:00:00 2001 From: gloriaswj Date: Sat, 3 Apr 2021 01:41:21 -0700 Subject: [PATCH 2/4] Format code --- game/gamemap/dropcandy_test.go | 53 ++++++++++++---------------------- 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/game/gamemap/dropcandy_test.go b/game/gamemap/dropcandy_test.go index 8211356..0aa7872 100644 --- a/game/gamemap/dropcandy_test.go +++ b/game/gamemap/dropcandy_test.go @@ -7,15 +7,13 @@ import ( "github.com/stretchr/testify/assert" ) - func TestDropCandyChecker_CanDropCandy(t *testing.T) { - - gamemap := &Map { - screenX:3, - screenY:3, - batch: nil, - maxRow: 4, - maxCol: 4, + gamemap := &Map{ + screenX: 3, + screenY: 3, + batch: nil, + maxRow: 4, + maxCol: 4, gridXOffset: 3, gridYOffset: 3, grid: &[][]square.Square{ @@ -24,29 +22,28 @@ func TestDropCandyChecker_CanDropCandy(t *testing.T) { {nil, nil, nil, nil}, {nil, nil, nil, nil}, }, - } dropCandyChecker := NewDropCandyChecker(gamemap) - testCases := []struct{ - name string - playerX int - playerY int - playerWidth int + testCases := []struct { + name string + playerX int + playerY int + playerWidth int playerHeight int - threshold bool + threshold bool }{ - { name: "testcase1", - playerX: 1, - playerY: 2, - playerWidth: 1, + {name: "testcase1", + playerX: 1, + playerY: 2, + playerWidth: 1, playerHeight: 1, - threshold: true, + threshold: true, }, } for _, testCase := range testCases { - t.Run(testCase.name, func(t *testing.T){ + t.Run(testCase.name, func(t *testing.T) { canDropCandyChecker := dropCandyChecker.CanDropCandy( testCase.playerX, @@ -58,17 +55,3 @@ func TestDropCandyChecker_CanDropCandy(t *testing.T) { } } - - - - - - - - - - - - - - From ab33a10e09982b51548ab87a21e68f723fcf1be4 Mon Sep 17 00:00:00 2001 From: gloriaswj Date: Sat, 3 Apr 2021 01:58:25 -0700 Subject: [PATCH 3/4] Clean up test --- game/gamemap/dropcandy_test.go | 67 +++++++++++++++------------------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/game/gamemap/dropcandy_test.go b/game/gamemap/dropcandy_test.go index 0aa7872..d939aec 100644 --- a/game/gamemap/dropcandy_test.go +++ b/game/gamemap/dropcandy_test.go @@ -1,56 +1,49 @@ package gamemap import ( - "candy/game/square" "testing" + "candy/game/square" + "github.com/stretchr/testify/assert" ) func TestDropCandyChecker_CanDropCandy(t *testing.T) { - gamemap := &Map{ - screenX: 3, - screenY: 3, - batch: nil, - maxRow: 4, - maxCol: 4, - gridXOffset: 3, - gridYOffset: 3, - grid: &[][]square.Square{ - {nil, nil, nil, nil}, - {nil, nil, nil, nil}, - {nil, nil, nil, nil}, - {nil, nil, nil, nil}, - }, - } - dropCandyChecker := NewDropCandyChecker(gamemap) - testCases := []struct { - name string - playerX int - playerY int - playerWidth int - playerHeight int - threshold bool + name string + gameMap *Map + playerX int + playerY int + expectedCanDropCandy bool }{ - {name: "testcase1", - playerX: 1, - playerY: 2, - playerWidth: 1, - playerHeight: 1, - threshold: true, + { + name: "map empty", + gameMap: &Map{ + batch: nil, + maxRow: 4, + maxCol: 4, + grid: &[][]square.Square{ + {nil, nil, nil, nil}, + {nil, nil, nil, nil}, + {nil, nil, nil, nil}, + {nil, nil, nil, nil}, + }, + }, + playerX: 1, + playerY: 2, + expectedCanDropCandy: true, }, } for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { - canDropCandyChecker := - dropCandyChecker.CanDropCandy( - testCase.playerX, - testCase.playerY, - testCase.playerWidth, - testCase.playerHeight) - assert.Equal(t, testCase.threshold, canDropCandyChecker) + dropCandyChecker := NewDropCandyChecker(testCase.gameMap) + gotCanDropCandyCheck := dropCandyChecker.CanDropCandy( + testCase.playerX, + testCase.playerY, + 1, + 1) + assert.Equal(t, testCase.expectedCanDropCandy, gotCanDropCandyCheck) }) } From 66c8d449a52d8e2162ce5b0cc2b4567071658de8 Mon Sep 17 00:00:00 2001 From: gloriaswj Date: Sat, 3 Apr 2021 01:59:13 -0700 Subject: [PATCH 4/4] Clean up --- game/gamemap/dropcandy_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/game/gamemap/dropcandy_test.go b/game/gamemap/dropcandy_test.go index d939aec..b7fffe8 100644 --- a/game/gamemap/dropcandy_test.go +++ b/game/gamemap/dropcandy_test.go @@ -46,5 +46,4 @@ func TestDropCandyChecker_CanDropCandy(t *testing.T) { assert.Equal(t, testCase.expectedCanDropCandy, gotCanDropCandyCheck) }) } - }