chart_test.go
1.2 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package domain
import (
"github.com/magiconair/properties/assert"
"testing"
)
func TestReorder(t *testing.T) {
//chartsAfter:
//target := &Chart{Id: 3, Pid: 0, Sort: 3}
inputs := []struct {
charts []*Chart
targetId int64
sortIndex int
pid int64
appendFlag bool
want []int64
}{
{createChartsBefore(), 3, 1, 0, true, []int64{3, 1, 2}},
{createChartsBefore(), 3, 2, 0, true, []int64{1, 3, 2}},
{createChartsBefore(), 3, 3, 0, true, []int64{1, 2, 3}},
{createChartsBefore(), 3, 4, 0, true, []int64{1, 2, 3}},
{createChartsBefore(), 3, 1, 1, false, []int64{1, 2}},
}
for _, input := range inputs {
assert.Equal(t, chartIds(Reorder(input.charts, &Chart{Id: input.targetId, Pid: input.pid, Sort: input.sortIndex}, input.appendFlag)), input.want)
}
}
func chartIds(charts []*Chart) []int64 {
var idList = make([]int64, 0)
for _, c := range charts {
if c.Id == 0 {
continue
}
idList = append(idList, c.Id)
}
return idList
}
func createChartsBefore() []*Chart {
return []*Chart{
{Id: 1, Pid: 0, Sort: 1},
{Id: 2, Pid: 0, Sort: 2},
{Id: 3, Pid: 0, Sort: 3},
}
}
func createChartsAfter() []*Chart {
return []*Chart{
{Id: 5, Pid: 1, Sort: 1},
{Id: 6, Pid: 1, Sort: 2},
{Id: 7, Pid: 1, Sort: 3},
}
}