Sort Order for tasks #110
|
@ -318,6 +318,22 @@ var taskSortTestCases = []taskSortTestCase{
|
|||
}
|
||||
|
||||
func TestTaskSort(t *testing.T) {
|
||||
|
||||
assertTestSliceMatch := func(t *testing.T, got, want []*Task) {
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Error("Slices do not match in order")
|
||||
t.Error("Got:")
|
||||
for _, task := range got {
|
||||
t.Errorf(" - Task ID %d (%s)", task.ID, task.Text)
|
||||
}
|
||||
|
||||
t.Error("Want:")
|
||||
for _, task := range want {
|
||||
t.Errorf(" - Task ID %d (%s)", task.ID, task.Text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, testCase := range taskSortTestCases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
t.Run("asc default", func(t *testing.T) {
|
||||
|
@ -336,18 +352,7 @@ func TestTaskSort(t *testing.T) {
|
|||
|
||||
sortTasks(got, by)
|
||||
|
||||
if !reflect.DeepEqual(got, testCase.wantAsc) {
|
||||
t.Error("Slices do not match in order")
|
||||
t.Error("Got:")
|
||||
for _, task := range got {
|
||||
t.Errorf(" - Task ID %d (%s)", task.ID, task.Text)
|
||||
}
|
||||
|
||||
t.Error("Want:")
|
||||
for _, task := range testCase.wantAsc {
|
||||
t.Errorf(" - Task ID %d (%s)", task.ID, task.Text)
|
||||
}
|
||||
}
|
||||
assertTestSliceMatch(t, got, testCase.wantAsc)
|
||||
})
|
||||
t.Run("asc", func(t *testing.T) {
|
||||
by := []*sortParam{
|
||||
|
@ -366,18 +371,7 @@ func TestTaskSort(t *testing.T) {
|
|||
|
||||
sortTasks(got, by)
|
||||
|
||||
if !reflect.DeepEqual(got, testCase.wantAsc) {
|
||||
t.Error("Slices do not match in order")
|
||||
t.Error("Got:")
|
||||
for _, task := range got {
|
||||
t.Errorf(" - Task ID %d (%s)", task.ID, task.Text)
|
||||
}
|
||||
|
||||
t.Error("Want:")
|
||||
for _, task := range testCase.wantAsc {
|
||||
t.Errorf(" - Task ID %d (%s)", task.ID, task.Text)
|
||||
}
|
||||
}
|
||||
assertTestSliceMatch(t, got, testCase.wantAsc)
|
||||
})
|
||||
t.Run("desc", func(t *testing.T) {
|
||||
by := []*sortParam{
|
||||
|
@ -396,18 +390,7 @@ func TestTaskSort(t *testing.T) {
|
|||
|
||||
sortTasks(got, by)
|
||||
|
||||
if !reflect.DeepEqual(got, testCase.wantDesc) {
|
||||
t.Error("Slices do not match in order")
|
||||
t.Error("Got:")
|
||||
for _, task := range got {
|
||||
t.Errorf(" - Task ID %d (%s)", task.ID, task.Text)
|
||||
}
|
||||
|
||||
t.Error("Want:")
|
||||
for _, task := range testCase.wantDesc {
|
||||
t.Errorf(" - Task ID %d (%s)", task.ID, task.Text)
|
||||
}
|
||||
}
|
||||
assertTestSliceMatch(t, got, testCase.wantAsc)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue