Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @link Problem definition [[docs/hackerrank/warmup/interview_preparation_kit/2d_array.md]]
* @link Problem definition [[docs/hackerrank/interview_preparation_kit/2d_array.md]]
*/

package hackerrank
Expand Down Expand Up @@ -48,3 +48,7 @@ func hourglassSum(arr [][]int32) int32 {

return maxHourglassSum
}

func HourglassSum(arr [][]int32) int32 {
return hourglassSum(arr)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@ import (
"gon.cl/algorithms/utils"
)

type TestCase struct {
type TwoDArrayTestCase struct {
Input [][]int32 `json:"input"`
Expected int32 `json:"expected"`
}

var testCases []TestCase
var TwoDArrayTestCases []TwoDArrayTestCase

// You can use testing.T, if you want to test the code without benchmarking
func setupSuite(t testing.TB) {
func twoDArraySetupSuite(t testing.TB) {
wd, _ := os.Getwd()
filepath := wd + "/2d_array.testcases.json"
t.Log("Setup test cases from JSON: ", filepath)

var _, err = utils.LoadJSON(filepath, &testCases)
var _, err = utils.LoadJSON(filepath, &TwoDArrayTestCases)
if err != nil {
t.Log(err)
}
}

func Test2DArray(t *testing.T) {
func TestTwoDArray(t *testing.T) {

setupSuite(t)
twoDArraySetupSuite(t)

for _, tt := range testCases {
for _, tt := range TwoDArrayTestCases {
testname := fmt.Sprintf("hourglassSum(%v) => %v \n", tt.Input, tt.Expected)
t.Run(testname, func(t *testing.T) {

ans := hourglassSum(tt.Input)
ans := HourglassSum(tt.Input)
assert.Equal(t, tt.Expected, ans)
})

Expand Down
Loading