-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert some tests to goconvey, and improve assertions along the way
- Loading branch information
1 parent
1809a8b
commit 9f67f73
Showing
15 changed files
with
377 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,72 @@ | ||
package base | ||
|
||
import ( | ||
. "github.com/smartystreets/goconvey/convey" | ||
"testing" | ||
) | ||
|
||
func TestLazySortDesc(t *testing.T) { | ||
inst1, err := ParseCSVToInstances("../examples/datasets/iris_headers.csv", true) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
inst2, err := ParseCSVToInstances("../examples/datasets/iris_sorted_desc.csv", true) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
as1 := ResolveAllAttributes(inst1) | ||
as2 := ResolveAllAttributes(inst2) | ||
|
||
if isSortedDesc(inst1, as1[0]) { | ||
t.Error("Can't test descending sort order") | ||
} | ||
if !isSortedDesc(inst2, as2[0]) { | ||
t.Error("Reference data not sorted in descending order!") | ||
} | ||
|
||
inst, err := LazySort(inst1, Descending, as1[0:len(as1)-1]) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if !isSortedDesc(inst, as1[0]) { | ||
t.Error("Instances are not sorted in descending order") | ||
t.Error(inst1) | ||
} | ||
if !inst2.Equal(inst) { | ||
t.Error("Instances don't match") | ||
t.Error(inst) | ||
t.Error(inst2) | ||
} | ||
Convey("Given data that's not already sorted descending", t, func() { | ||
unsorted, err := ParseCSVToInstances("../examples/datasets/iris_headers.csv", true) | ||
So(err, ShouldBeNil) | ||
|
||
as1 := ResolveAllAttributes(unsorted) | ||
So(isSortedDesc(unsorted, as1[0]), ShouldBeFalse) | ||
|
||
Convey("Given reference data that's alredy sorted descending", func() { | ||
sortedDescending, err := ParseCSVToInstances("../examples/datasets/iris_sorted_desc.csv", true) | ||
So(err, ShouldBeNil) | ||
|
||
as2 := ResolveAllAttributes(sortedDescending) | ||
So(isSortedDesc(sortedDescending, as2[0]), ShouldBeTrue) | ||
|
||
Convey("LazySorting Descending", func() { | ||
result, err := LazySort(unsorted, Descending, as1[0:len(as1)-1]) | ||
So(err, ShouldBeNil) | ||
|
||
Convey("Result should be sorted descending", func() { | ||
So(isSortedDesc(result, as1[0]), ShouldBeTrue) | ||
}) | ||
|
||
Convey("Result should match the reference", func() { | ||
So(sortedDescending.Equal(result), ShouldBeTrue) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
func TestLazySortAsc(t *testing.T) { | ||
inst, err := ParseCSVToInstances("../examples/datasets/iris_headers.csv", true) | ||
as1 := ResolveAllAttributes(inst) | ||
if isSortedAsc(inst, as1[0]) { | ||
t.Error("Can't test ascending sort on something ascending already") | ||
} | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
insts, err := LazySort(inst, Ascending, as1) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
if !isSortedAsc(insts, as1[0]) { | ||
t.Error("Instances are not sorted in ascending order") | ||
t.Error(insts) | ||
} | ||
|
||
inst2, err := ParseCSVToInstances("../examples/datasets/iris_sorted_asc.csv", true) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
as2 := ResolveAllAttributes(inst2) | ||
if !isSortedAsc(inst2, as2[0]) { | ||
t.Error("This file should be sorted in ascending order") | ||
} | ||
|
||
if !inst2.Equal(insts) { | ||
t.Error("Instances don't match") | ||
t.Error(inst) | ||
t.Error(inst2) | ||
} | ||
|
||
rowStr := insts.RowString(0) | ||
ref := "4.30 3.00 1.10 0.10 Iris-setosa" | ||
if rowStr != ref { | ||
t.Fatalf("'%s' != '%s'", rowStr, ref) | ||
} | ||
Convey("Given data that's not already sorted ascending", t, func() { | ||
unsorted, err := ParseCSVToInstances("../examples/datasets/iris_headers.csv", true) | ||
So(err, ShouldBeNil) | ||
|
||
as1 := ResolveAllAttributes(unsorted) | ||
So(isSortedAsc(unsorted, as1[0]), ShouldBeFalse) | ||
|
||
Convey("Given reference data that's alredy sorted ascending", func() { | ||
sortedAscending, err := ParseCSVToInstances("../examples/datasets/iris_sorted_asc.csv", true) | ||
So(err, ShouldBeNil) | ||
|
||
as2 := ResolveAllAttributes(sortedAscending) | ||
So(isSortedAsc(sortedAscending, as2[0]), ShouldBeTrue) | ||
|
||
Convey("LazySorting Ascending", func() { | ||
result, err := LazySort(unsorted, Ascending, as1[0:len(as1)-1]) | ||
So(err, ShouldBeNil) | ||
|
||
Convey("Result should be sorted descending", func() { | ||
So(isSortedAsc(result, as1[0]), ShouldBeTrue) | ||
}) | ||
|
||
Convey("Result should match the reference", func() { | ||
So(sortedAscending.Equal(result), ShouldBeTrue) | ||
}) | ||
|
||
Convey("First element of Result should equal known value", func() { | ||
So(result.RowString(0), ShouldEqual, "4.30 3.00 1.10 0.10 Iris-setosa") | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.