2014-08-02 16:22:14 +01:00
|
|
|
package base
|
|
|
|
|
|
|
|
import (
|
2014-08-22 13:16:11 +00:00
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
2014-08-02 16:22:14 +01:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-08-22 08:13:19 +00:00
|
|
|
func TestLazySortDesc(t *testing.T) {
|
2014-08-22 13:16:11 +00:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-08-02 16:22:14 +01:00
|
|
|
}
|
|
|
|
|
2014-08-22 08:13:19 +00:00
|
|
|
func TestLazySortAsc(t *testing.T) {
|
2014-08-22 13:16:11 +00:00
|
|
|
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)
|
|
|
|
})
|
2014-08-02 16:22:14 +01:00
|
|
|
|
2014-08-22 13:16:11 +00:00
|
|
|
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")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-08-02 16:22:14 +01:00
|
|
|
}
|