Sort Order for tasks #110

Merged
konrad merged 62 commits from feature/sort-order into master 2019-12-07 14:30:52 +00:00
1 changed files with 19 additions and 36 deletions
Showing only changes of commit 3da710637d - Show all commits

View File

@ -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)
})
})
}