|
| 1 | +// ==================================================== |
| 2 | +// Data-Structures-with-Go Copyright(C) 2017 Furkan Türkal |
| 3 | +// This program comes with ABSOLUTELY NO WARRANTY; This is free software, |
| 4 | +// and you are welcome to redistribute it under certain conditions; See |
| 5 | +// file LICENSE, which is part of this source code package, for details. |
| 6 | +// ==================================================== |
| 7 | + |
| 8 | +package main |
| 9 | + |
| 10 | +import ( |
| 11 | + "reflect" |
| 12 | + "testing" |
| 13 | +) |
| 14 | + |
| 15 | +func TestLeftRotate(t *testing.T) { |
| 16 | + var testDatas = []struct { |
| 17 | + ArrayIn []int |
| 18 | + Count int |
| 19 | + Depth int |
| 20 | + ArrayOut []int |
| 21 | + }{ |
| 22 | + {[]int{1, 2, 3, 4, 5, 6, 7}, 2, 7, []int{3, 4, 5, 6, 7, 1, 2}}, |
| 23 | + {[]int{1, 2, 3, 4, 5, 6, 7}, 2, 6, []int{3, 4, 5, 6, 1, 2, 7}}, |
| 24 | + {[]int{1, 2, 3, 4, 5, 6, 7}, 1, 2, []int{2, 1, 3, 4, 5, 6, 7}}, |
| 25 | + {[]int{1, 2, 3, 4, 5, 6, 7}, 7, 7, []int{1, 2, 3, 4, 5, 6, 7}}, |
| 26 | + {[]int{1, 2, 3, 4, 5, 6, 7}, 7, 6, []int{2, 3, 4, 5, 6, 1, 7}}, |
| 27 | + } |
| 28 | + for _, data := range testDatas { |
| 29 | + expected := data.ArrayOut |
| 30 | + leftRotate(data.ArrayIn, data.Count, data.Depth) |
| 31 | + actual := data.ArrayIn |
| 32 | + |
| 33 | + if !reflect.DeepEqual(expected, actual) { |
| 34 | + t.Errorf("LeftRotate: Expected: %d, Actual: %d", expected, actual) |
| 35 | + } |
| 36 | + } |
| 37 | +} |
0 commit comments