Skip to content

[Hacker Rank] Interview Preparation Kit: Greedy Algorithms: Minimum A… #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2025
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type MinimumAbsoluteDifferenceInAnArrayTestCase struct {
}

var MinimumAbsoluteDifferenceInAnArrayTestCases []MinimumAbsoluteDifferenceInAnArrayTestCase
var MinimumAbsoluteDifferenceInAnArrayTestCase2 []MinimumAbsoluteDifferenceInAnArrayTestCase

// You can use testing.T, if you want to test the code without benchmarking
func MinimumAbsoluteDifferenceInAnArraySetupSuite(t testing.TB) {
Expand All @@ -28,6 +29,17 @@ func MinimumAbsoluteDifferenceInAnArraySetupSuite(t testing.TB) {
}
}

func MinimumAbsoluteDifferenceInAnArraySetupSuiteTestCase2(t testing.TB) {
wd, _ := os.Getwd()
filepath := wd + "/minimum_absolute_difference_in_an_array.testcases.json"
t.Log("Setup test cases from JSON: ", filepath)

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

func TestMinimumAbsoluteDifferenceInAnArray(t *testing.T) {

MinimumAbsoluteDifferenceInAnArraySetupSuite(t)
Expand All @@ -40,3 +52,16 @@ func TestMinimumAbsoluteDifferenceInAnArray(t *testing.T) {
})
}
}

func TestMinimumAbsoluteDifferenceInAnArrayBigCase(t *testing.T) {

MinimumAbsoluteDifferenceInAnArraySetupSuiteTestCase2(t)

for _, tt := range MinimumAbsoluteDifferenceInAnArrayTestCase2 {
testname := fmt.Sprintf("MinimumAbsoluteDifferenceInAnArray(%v) => %v \n", tt.Input, tt.Expected)
t.Run(testname, func(t *testing.T) {
ans := MinimumAbsoluteDifferenceInAnArray(tt.Input)
assert.Equal(t, tt.Expected, ans)
})
}
}