1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
// import "github.com/stretchr/testify/assert"
func TestLRU(t *testing.T) {
assert := assert.New(t)
input1 := []string{"LRUCache","put","put","get","put","get","put","get","get","get"}
input2 := [][]int{{2},{1,1},{2,2},{1},{3,3},{2},{4,4},{1},{3},{4}}
expected_res := []interface{}{nil, nil, nil, 1, nil, -1, nil, -1, 3, 4}
real_res := ExecLRU(input1, input2)
assert.Equal(expected_res, real_res)
}
func ExecLRU(input1 []string, input2 [][]int) []interface{} {
l := Constructor(input2[0][0])
res := []interface{}{nil}
for i, v := range input1 {
if i == 0 {
continue
}
if v == "put" {
l.Put(input2[i][0], input2[i][1])
res = append(res, nil)
} else if v == "get" {
tmp := l.Get(input2[i][0])
res = append(res, tmp)
}
}
return res
}
|