Skip to content

Commit

Permalink
Merge pull request #279 from sir-gon/develop
Browse files Browse the repository at this point in the history
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Array: 2D Array -…
  • Loading branch information
sir-gon authored Jan 28, 2025
2 parents 97861c1 + 0444738 commit 7e3c9f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
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

0 comments on commit 7e3c9f7

Please sign in to comment.