Commits

Juri Pakaste committed 0b33a8a

more sort tests

Comments (0)

Files changed (1)

Tests/ScalarArrayTest.m

 }
 
 
+-(void)testSortEmpty
+{
+    ScalarDoubleArray *da0 = [[[ScalarDoubleArray alloc] init] autorelease];
+    [da0 sort];
+    GHAssertEquals([da0 count], 0UL, @"Expected 0 items after sort");
+}
+
+
+-(void)testSortOne
+{
+    ScalarDoubleArray *da0 = [[[ScalarDoubleArray alloc] init] autorelease];
+    [da0 addValue:54.0];
+    [da0 sort];
+    GHAssertEquals([da0 count], 1UL, @"Expected 0 items after sort");
+    GHAssertEquals([da0 valueAtIndex:0], 54.0, @"Wrong value 0");
+}
+
+
+-(void)testInverseSort
+{
+    ScalarDoubleArray *da0 = [[[ScalarDoubleArray alloc] init] autorelease];
+    [da0 addValue:32.0];
+    [da0 addValue:10.5];
+    [da0 addValue:49.0];
+    [da0 sortWithBlock:^int(const void *v0, const void *v1) {
+        double dv0 = *(const double*)v0;
+        double dv1 = *(const double*)v1;
+        return (dv0 < dv1) ? 1 : ((dv0 > dv1) ? -1 : 0);
+    }];
+    GHAssertEquals([da0 valueAtIndex:0], 49.0, @"Wrong value 0");
+    GHAssertEquals([da0 valueAtIndex:1], 32.0, @"Wrong value 1");
+    GHAssertEquals([da0 valueAtIndex:2], 10.5, @"Wrong value 2");
+}
+
+
 @end