Skip to content

Commit 2349489

Browse files
author
Gonzalo Diaz
committed
[Hacker Rank] Interview Preparation Kit: Arrays: Left Rotation. WIP.
1 parent 0444738 commit 2349489

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package hackerrank
2+
3+
func rotLeft(a []int32, d int32) []int32 {
4+
// Write your code here
5+
return []int32{}
6+
}
7+
8+
func RotLeft(a []int32, d int32) []int32 {
9+
return rotLeft(a, d)
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{"input": [1, 2, 3, 4, 5], "expected": [2, 3, 4, 5, 1]},
3+
{"input": [2, 3, 4, 5, 1], "expected": [3, 4, 5, 1, 2]},
4+
{"input": [3, 4, 5, 1, 2], "expected": [4, 5, 1, 2, 3]},
5+
{"input": [4, 5, 1, 2, 3], "expected": [5, 1, 2, 3, 4]},
6+
{"input": [5, 1, 2, 3, 4], "expected": [1, 2, 3, 4, 5]}
7+
]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package hackerrank
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
"gon.cl/algorithms/utils"
10+
)
11+
12+
type TestCase struct {
13+
Input [][]int32 `json:"input"`
14+
Expected int32 `json:"expected"`
15+
}
16+
17+
var testCases []TestCase
18+
19+
// You can use testing.T, if you want to test the code without benchmarking
20+
func setupSuite(t testing.TB) {
21+
wd, _ := os.Getwd()
22+
filepath := wd + "/ctci_array_left_rotation.testcases.json"
23+
t.Log("Setup test cases from JSON: ", filepath)
24+
25+
var _, err = utils.LoadJSON(filepath, &testCases)
26+
if err != nil {
27+
t.Log(err)
28+
}
29+
}
30+
31+
func TestRotLeft(t *testing.T) {
32+
33+
setupSuite(t)
34+
35+
for _, tt := range testCases {
36+
testname := fmt.Sprintf("hourglassSum(%v) => %v \n", tt.Input, tt.Expected)
37+
t.Run(testname, func(t *testing.T) {
38+
39+
ans := hourglassSum(tt.Input)
40+
assert.Equal(t, tt.Expected, ans)
41+
})
42+
43+
}
44+
}

0 commit comments

Comments
 (0)