diff options
Diffstat (limited to 'Example/Database/Tests/Unit')
4 files changed, 97 insertions, 97 deletions
diff --git a/Example/Database/Tests/Unit/FIRDataSnapshotTests.m b/Example/Database/Tests/Unit/FIRDataSnapshotTests.m index 2a442df..df950e2 100644 --- a/Example/Database/Tests/Unit/FIRDataSnapshotTests.m +++ b/Example/Database/Tests/Unit/FIRDataSnapshotTests.m @@ -34,14 +34,14 @@ - (void)setUp { [super setUp]; - + // Set-up code here. } - (void)tearDown { // Tear-down code here. - + [super tearDown]; } @@ -62,13 +62,13 @@ XCTAssertEqualObjects(x.val, @5, @"Values are the same"); XCTAssertEqualObjects(x.getPriority, [FSnapshotUtilities nodeFrom:@42], @"Priority is the same"); XCTAssertTrue([x isLeafNode], @"Node is a leaf"); - + x = [[FLeafNode alloc] initWithValue:@"test"]; XCTAssertEqualObjects(x.value, @"test", @"Check if leaf node is holding onto a string value"); - + x = [[FLeafNode alloc] initWithValue:[NSNumber numberWithBool:YES]]; XCTAssertTrue([x.value boolValue], @"Check if leaf node is holding onto a YES boolean"); - + x = [[FLeafNode alloc] initWithValue:[NSNumber numberWithBool:NO]]; XCTAssertFalse([x.value boolValue], @"Check if leaf node is holding onto a NO boolean"); } @@ -76,11 +76,11 @@ - (void) testUpdatingPriorityWithoutChangingOld { FLeafNode* x = [[FLeafNode alloc] initWithValue:@"test" withPriority:[FSnapshotUtilities nodeFrom:[NSNumber numberWithInt:42]]]; FLeafNode* y = [x updatePriority:[FSnapshotUtilities nodeFrom:[NSNumber numberWithInt:187]]]; - + // old node is the same XCTAssertEqualObjects(x.value, @"test", @"Values of old node are the same"); XCTAssertEqualObjects(x.getPriority, [FSnapshotUtilities nodeFrom:[NSNumber numberWithInt:42]], @"Priority of old node is the same."); - + // new node has the new priority but the old value XCTAssertEqualObjects(y.value, @"test", @"Values of old node are the same"); XCTAssertEqualObjects(y.getPriority, [FSnapshotUtilities nodeFrom:[NSNumber numberWithInt:187]], @"Priority of new node is update"); @@ -89,10 +89,10 @@ - (void) testUpdateImmediateChildReturnsANewChildrenNode { FLeafNode* x = [[FLeafNode alloc] initWithValue:@"test" withPriority:[FSnapshotUtilities nodeFrom:[NSNumber numberWithInt:42]]]; FChildrenNode* y = [x updateImmediateChild:@"test" withNewChild:[[FLeafNode alloc] initWithValue:@"foo"]]; - + XCTAssertFalse([y isLeafNode], @"New node is no longer a leaf"); XCTAssertEqualObjects(y.getPriority, [FSnapshotUtilities nodeFrom:[NSNumber numberWithInt:42]], @"Priority of new node is update"); - + XCTAssertEqualObjects([[y getImmediateChild:@"test"] val], @"foo", @"Child node has the correct value"); } @@ -130,7 +130,7 @@ FChildrenNode* x = [[FChildrenNode alloc] initWithChildren:children]; FLeafNode* newValue = [[FLeafNode alloc] initWithValue:@"new value"]; FChildrenNode* y = [x updateImmediateChild:@"test" withNewChild:newValue]; - + XCTAssertEqualObjects(x.children, children, @"Original object stays the same"); XCTAssertEqualObjects([y.children objectForKey:@"test"], newValue, @"New internal node with the proper new value"); XCTAssertEqualObjects([[y.children objectForKey:@"test"] val], @"new value", @"Check the payload"); @@ -149,10 +149,10 @@ - (void) testObjectTypes { XCTAssertEqualObjects(@"string", [FUtilities getJavascriptType:@""], @"Check string type"); XCTAssertEqualObjects(@"string", [FUtilities getJavascriptType:@"moo"], @"Check string type"); - + XCTAssertEqualObjects(@"boolean", [FUtilities getJavascriptType:@YES], @"Check boolean type"); XCTAssertEqualObjects(@"boolean", [FUtilities getJavascriptType:@NO], @"Check boolean type"); - + XCTAssertEqualObjects(@"number", [FUtilities getJavascriptType:@5], @"Check number type"); XCTAssertEqualObjects(@"number", [FUtilities getJavascriptType:@5.5], @"Check number type"); XCTAssertEqualObjects(@"number", [FUtilities getJavascriptType:@0], @"Check number type"); @@ -161,12 +161,12 @@ XCTAssertEqualObjects(@"number", [FUtilities getJavascriptType:@-2.11], @"Check number type"); } -- (void) testNodeHashWorksCorrectly { +- (void) testNodeHashWorksCorrectly { id<FNode> node = [FSnapshotUtilities nodeFrom:@{ @"intNode" : @4, @"doubleNode" : @4.5623, @"stringNode" : @"hey guys", @"boolNode" : @YES }]; - + XCTAssertEqualObjects(@"eVih19a6ZDz3NL32uVBtg9KSgQY=", [[node getImmediateChild:@"intNode"] dataHash], @"Check integer node"); XCTAssertEqualObjects(@"vf1CL0tIRwXXunHcG/irRECk3lY=", [[node getImmediateChild:@"doubleNode"] dataHash], @"Check double node"); XCTAssertEqualObjects(@"CUNLXWpCVoJE6z7z1vE57lGaKAU=", [[node getImmediateChild:@"stringNode"] dataHash], @"Check string node"); @@ -178,13 +178,13 @@ id<FNode> node = [FSnapshotUtilities nodeFrom:@{ @"root": @{ @"c": @{@".value": @99, @".priority": @"abc"}, @".priority" : @"def" } }]; - + XCTAssertEqualObjects(@"Fm6tzN4CVEu5WxFDZUdTtqbTVaA=", [node dataHash], @"Check compound node"); } - (void) testGetPredecessorChild { id<FNode> node = [FSnapshotUtilities nodeFrom:@{@"d": @YES, @"a": @YES, @"g": @YES, @"c": @YES, @"e": @YES}]; - + XCTAssertNil([node predecessorChildKey:@"a"], @"Check the first one sorted properly"); XCTAssertEqualObjects([node predecessorChildKey:@"c"], @@ -206,13 +206,13 @@ } - (void) testDataSnapshotHasChildrenWorks { - + FIRDataSnapshot * snap = [self snapshotFor:@{}]; XCTAssertFalse([snap hasChildren], @"Empty dict has no children"); - + snap = [self snapshotFor:@5]; XCTAssertFalse([snap hasChildren], @"Leaf node has no children"); - + snap = [self snapshotFor:@{@"x": @5}]; XCTAssertTrue([snap hasChildren], @"Properly has children"); } @@ -220,10 +220,10 @@ - (void) testDataSnapshotValWorks { FIRDataSnapshot * snap = [self snapshotFor:@5]; XCTAssertEqualObjects([snap value], @5, @"Leaf node values are correct"); - + snap = [self snapshotFor:@{}]; XCTAssertTrue([snap value] == [NSNull null], @"Snapshot value is properly null"); - + NSDictionary* dict = @{ @"x": @5, @"y": @{ @@ -232,18 +232,18 @@ @"yc": @{ @"yca" : @3} } }; - + snap = [self snapshotFor:dict]; XCTAssertTrue([dict isEqualToDictionary:[snap value]], @"Check if the dictionaries are the same"); } - (void) testDataSnapshotChildWorks { FIRDataSnapshot * snap = [self snapshotFor:@{@"x": @5, @"y": @{@"yy": @3, @"yz": @4}}]; - + XCTAssertEqualObjects([[snap childSnapshotForPath:@"x"] value], @5, @"Check x"); NSDictionary* dict = @{@"yy": @3, @"yz": @4}; XCTAssertTrue([[[snap childSnapshotForPath:@"y"] value] isEqualToDictionary:dict], @"Check y"); - + XCTAssertEqualObjects([[[snap childSnapshotForPath:@"y"] childSnapshotForPath:@"yy"] value], @3, @"Check y/yy"); XCTAssertEqualObjects([[snap childSnapshotForPath:@"y/yz"] value], @4, @"Check y/yz"); XCTAssertTrue([[snap childSnapshotForPath:@"z"] value] == [NSNull null], @"Check nonexistent z"); @@ -256,7 +256,7 @@ XCTAssertTrue([snap hasChild:@"x"], @"Has child"); XCTAssertTrue([snap hasChild:@"y/yy"], @"Has child"); - + XCTAssertFalse([snap hasChild:@"dinosaur dinosaucer"], @"No child"); XCTAssertFalse([[snap childSnapshotForPath:@"x"] hasChild:@"anything"], @"No child"); XCTAssertFalse([snap hasChild:@"x/anything/at/all"], @"No child"); @@ -264,25 +264,25 @@ - (void) testDataSnapshotNameWorks { FIRDataSnapshot * snap = [self snapshotFor:@{@"a": @{@"b": @{@"c": @5}}}]; - + XCTAssertEqualObjects([[snap childSnapshotForPath:@"a"] key], @"a", @"Check child key"); XCTAssertEqualObjects([[snap childSnapshotForPath:@"a/b/c"] key], @"c", @"Check child key"); XCTAssertEqualObjects([[snap childSnapshotForPath:@"/a/b/c"] key], @"c", @"Check child key"); XCTAssertEqualObjects([[snap childSnapshotForPath:@"/a/b/c/"] key], @"c", @"Check child key"); - XCTAssertEqualObjects([[snap childSnapshotForPath:@"////a///b////c///"] key], @"c", @"Check child key"); + XCTAssertEqualObjects([[snap childSnapshotForPath:@"////a///b////c///"] key], @"c", @"Check child key"); XCTAssertEqualObjects([[snap childSnapshotForPath:@"////"] key], [snap key], @"Check root key"); - + XCTAssertEqualObjects([[snap childSnapshotForPath:@"/z/q/r/v////m"] key], @"m", @"Should also work for nonexistent paths"); } - (void) testDataSnapshotForEachWithNoPriorities { FIRDataSnapshot * snap = [self snapshotFor:@{@"a": @1, @"z": @26, @"m": @13, @"n": @14, @"c": @3, @"b": @2, @"e": @5}]; - + NSMutableString* out = [[NSMutableString alloc] init]; for (FIRDataSnapshot * child in snap.children) { [out appendFormat:@"%@:%@:", [child key], [child value] ]; } - + XCTAssertTrue([out isEqualToString:@"a:1:b:2:c:3:e:5:m:13:n:14:z:26:"], @"Proper order"); } @@ -296,12 +296,12 @@ @"b": @{@".value" : @2, @".priority": @25}, @"e": @{@".value" : @5, @".priority": @22}, }]; - + NSMutableString* out = [[NSMutableString alloc] init]; for (FIRDataSnapshot * child in snap.children) { [out appendFormat:@"%@:%@:", [child key], [child value] ]; } - + XCTAssertTrue([out isEqualToString:@"z:26:n:14:m:13:e:5:c:3:b:2:a:1:"], @"Proper order"); } @@ -315,12 +315,12 @@ @"b": @{@".value" : @2, @".priority": @"25"}, @"e": @{@".value" : @5, @".priority": @"22"}, }]; - + NSMutableString* out = [[NSMutableString alloc] init]; for (FIRDataSnapshot * child in snap.children) { [out appendFormat:@"%@:%@:", [child key], [child value] ]; } - + XCTAssertTrue([out isEqualToString:@"z:26:n:14:m:13:e:5:c:3:b:2:a:1:"], @"Proper order"); } @@ -334,14 +334,14 @@ @"b": @{@".value" : @2, @".priority": @"sixth"}, @"e": @{@".value" : @5, @".priority": @"seventh"}, }]; - + NSMutableString* output = [[NSMutableString alloc] init]; NSMutableArray* priorities = [[NSMutableArray alloc] init]; for (FIRDataSnapshot * child in snap.children) { [output appendFormat:@"%@:%@:", child.key, child.value]; [priorities addObject:child.priority]; } - + XCTAssertTrue([output isEqualToString:@"c:3:a:1:n:14:z:26:e:5:b:2:m:13:"], @"Proper order"); NSArray* expected = @[@"fifth", @"first", @"fourth", @"second", @"seventh", @"sixth", @"third"]; XCTAssertTrue([priorities isEqualToArray:expected], @"Correct priorities"); @@ -371,14 +371,14 @@ @"alpha40": @{@".value": @1, @".priority": @"zed" }, @"num40": @{@".value": @1, @".priority": @500 } }]; - + NSMutableString* out = [[NSMutableString alloc] init]; for (FIRDataSnapshot * child in snap.children) { [out appendFormat:@"%@, ", [child key]]; } - + NSString* expected = @"noPriorityA, noPriorityB, noPriorityC, num20, num40, num42, num60, num70, num80, alpha10, alpha11, alpha12, alpha13, alpha14, alpha20, alpha30, alpha40, alpha41, alpha42, "; - + XCTAssertTrue([expected isEqualToString:out], @"Proper ordering seen"); } diff --git a/Example/Database/Tests/Unit/FLevelDBStorageEngineTests.m b/Example/Database/Tests/Unit/FLevelDBStorageEngineTests.m index f26a913..560104a 100644 --- a/Example/Database/Tests/Unit/FLevelDBStorageEngineTests.m +++ b/Example/Database/Tests/Unit/FLevelDBStorageEngineTests.m @@ -495,7 +495,7 @@ id intValue = @247; id longValue = @1542405709418655810; id doubleValue = @0xFFFFFFFFFFFFFFFFUL; // This number can't be represented as a signed long. - + id<FNode> expectedData = NODE((@{@"int": @247, @"long": longValue, @"double": doubleValue})); FLevelDBStorageEngine *engine = [self cleanStorageEngine]; [engine updateServerCache:expectedData atPath:PATH(@"foo") merge:NO]; @@ -503,7 +503,7 @@ NSNumber* actualInt = [actualData val][@"int"]; NSNumber* actualLong = [actualData val][@"long"]; NSNumber* actualDouble = [actualData val][@"double"]; - + XCTAssertEqualObjects([actualInt stringValue], [intValue stringValue]); XCTAssertEqual(CFNumberGetType((CFNumberRef)actualInt), kCFNumberSInt64Type); XCTAssertEqualObjects([actualLong stringValue ], [longValue stringValue]); diff --git a/Example/Database/Tests/Unit/FPathTests.m b/Example/Database/Tests/Unit/FPathTests.m index 9b26a85..c70e3ab 100644 --- a/Example/Database/Tests/Unit/FPathTests.m +++ b/Example/Database/Tests/Unit/FPathTests.m @@ -25,7 +25,7 @@ XCTAssertTrue([[[FPath alloc] initWith:@"/a"] contains:[[FPath alloc] initWith:@"/a/b/c"]], @"contains should be correct"); XCTAssertTrue([[[FPath alloc] initWith:@"/a/b"] contains:[[FPath alloc] initWith:@"/a/b/c"]], @"contains should be correct"); XCTAssertTrue([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a/b/c"]], @"contains should be correct"); - + XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a/b"]], @"contains should be correct"); XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a"]], @"contains should be correct"); XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/"]], @"contains should be correct"); @@ -34,7 +34,7 @@ XCTAssertTrue([[[FPath alloc] initWithPieces:pathPieces andPieceNum:1] contains:[[FPath alloc] initWith:@"/b/c"]], @"contains should be correct"); XCTAssertTrue([[[FPath alloc] initWithPieces:pathPieces andPieceNum:1] contains:[[FPath alloc] initWith:@"/b/c/d"]], @"contains should be correct"); - + XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/b/c"]], @"contains should be correct"); XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a/c/b"]], @"contains should be correct"); diff --git a/Example/Database/Tests/Unit/FTreeSortedDictionaryTests.m b/Example/Database/Tests/Unit/FTreeSortedDictionaryTests.m index 6aee84d..396be06 100644 --- a/Example/Database/Tests/Unit/FTreeSortedDictionaryTests.m +++ b/Example/Database/Tests/Unit/FTreeSortedDictionaryTests.m @@ -75,7 +75,7 @@ FTreeSortedDictionary* map = [[[[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]] insertKey:@1 withValue:@1] insertKey:@2 withValue:@2]; - + XCTAssertEqualObjects([map get:@1], @1, @"Found first object"); XCTAssertEqualObjects([map get:@2], @2, @"Found second object"); XCTAssertNil([map get:@3], @"Properly not found object"); @@ -85,7 +85,7 @@ FTreeSortedDictionary* map = [[[[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]] insertKey:@1 withValue:@1] insertKey:@2 withValue:@2]; - + XCTAssertEqualObjects(map.root.key, @2, @"Check the root key"); XCTAssertEqualObjects(map.root.left.key, @1, @"Check the root.left key"); } @@ -94,11 +94,11 @@ FTreeSortedDictionary* map = [[[[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]] insertKey:@1 withValue:@1] insertKey:@2 withValue:@2]; - + FImmutableSortedDictionary* newMap = [map removeKey:@1]; XCTAssertEqualObjects([newMap get:@2], @2, @"Found second object"); XCTAssertNil([newMap get:@1], @"Properly not found object"); - + // Make sure the original one is not mutated XCTAssertEqualObjects([map get:@1], @1, @"Found first object"); XCTAssertEqualObjects([map get:@2], @2, @"Found second object"); @@ -121,21 +121,21 @@ XCTAssertNotNil([map get:@7], @"Found object"); XCTAssertNotNil([map get:@3], @"Found object"); XCTAssertNotNil([map get:@1], @"Found object"); - - + + FImmutableSortedDictionary* m1 = [map removeKey:@7]; FImmutableSortedDictionary* m2 = [map removeKey:@3]; FImmutableSortedDictionary* m3 = [map removeKey:@1]; - + XCTAssertNil([m1 get:@7], @"Removed object"); XCTAssertNotNil([m1 get:@3], @"Found object"); XCTAssertNotNil([m1 get:@1], @"Found object"); - + XCTAssertNil([m2 get:@3], @"Removed object"); XCTAssertNotNil([m2 get:@7], @"Found object"); XCTAssertNotNil([m2 get:@1], @"Found object"); - - + + XCTAssertNil([m3 get:@1], @"Removed object"); XCTAssertNotNil([m3 get:@7], @"Found object"); XCTAssertNotNil([m3 get:@3], @"Found object"); @@ -146,11 +146,11 @@ insertKey:@1 withValue:@1] insertKey:@2 withValue:@2] insertKey:@3 withValue:@3]; - + XCTAssertEqualObjects([map get:@1], @1, @"Found object"); XCTAssertEqualObjects([map get:@2], @2, @"Found object"); XCTAssertEqualObjects([map get:@3], @3, @"Found object"); - + FImmutableSortedDictionary* m1 = [map removeKey:@2]; XCTAssertEqualObjects([m1 get:@1], @1, @"Found object"); XCTAssertEqualObjects([m1 get:@3], @3, @"Found object"); @@ -159,23 +159,23 @@ - (void) testIncreasing { int total = 100; - + FTreeSortedDictionary* map = [[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]]; - + for(int i = 0; i < total; i++) { NSNumber* item = [NSNumber numberWithInt:i]; map = [map insertKey:item withValue:item]; } - + XCTAssertTrue([map count] == 100, @"Check if all 100 objects are in the map"); XCTAssertTrue([map.root isMemberOfClass:[FLLRBValueNode class]], @"Root is a value node"); XCTAssertTrue([(FLLRBValueNode *)map.root checkMaxDepth], @"Checking valid depth and tree structure"); - + for(int i = 0; i < total; i++) { NSNumber* item = [NSNumber numberWithInt:i]; map = [map removeKey:item]; } - + XCTAssertTrue([map count] == 0, @"Check if all 100 objects were removed"); // We can't check the depth here because the map no longer contains values, so we check that it doesn't responsd to this check XCTAssertTrue([map.root isMemberOfClass:[FLLRBEmptyNode class]], @"Root is an empty node"); @@ -187,8 +187,8 @@ insertKey:@1 withValue:@1] insertKey:@2 withValue:@2] insertKey:@3 withValue:@3]; - - + + XCTAssertEqualObjects(map.root.key, @2, @"Check root key"); XCTAssertEqualObjects(map.root.left.key, @1, @"Check the left key is correct"); XCTAssertEqualObjects(map.root.right.key, @3, @"Check the right key is correct"); @@ -208,7 +208,7 @@ insertKey:@71 withValue:@71] insertKey:@42 withValue:@42] insertKey:@88 withValue:@88]; - + XCTAssertTrue([map count] == 12, @"Check if all 12 objects are in the map"); XCTAssertTrue([map.root isMemberOfClass:[FLLRBValueNode class]], @"Root is a value node"); XCTAssertTrue([(FLLRBValueNode *)map.root checkMaxDepth], @"Checking valid depth and tree structure"); @@ -217,18 +217,18 @@ - (void) testRotateLeftLeavesTreeInAValidState { FLLRBValueNode* node = [[FLLRBValueNode alloc] initWithKey:@4 withValue:@4 withColor:BLACK withLeft: [[FLLRBValueNode alloc] initWithKey:@2 withValue:@2 withColor:BLACK withLeft:nil withRight:nil] withRight:[[FLLRBValueNode alloc]initWithKey:@7 withValue:@7 withColor:RED withLeft:[[FLLRBValueNode alloc ]initWithKey:@5 withValue:@5 withColor:BLACK withLeft:nil withRight:nil] withRight:[[FLLRBValueNode alloc] initWithKey:@8 withValue:@8 withColor:BLACK withLeft:nil withRight:nil]]]; - + FLLRBValueNode* node2 = [node performSelector:@selector(rotateLeft)]; - + XCTAssertTrue([node2 count] == 5, @"Make sure the count is correct"); XCTAssertTrue([node2 checkMaxDepth], @"Check proper structure"); } - (void) testRotateRightLeavesTreeInAValidState { FLLRBValueNode* node = [[FLLRBValueNode alloc] initWithKey:@7 withValue:@7 withColor:BLACK withLeft:[[FLLRBValueNode alloc] initWithKey:@4 withValue:@4 withColor:RED withLeft:[[FLLRBValueNode alloc] initWithKey:@2 withValue:@2 withColor:BLACK withLeft:nil withRight:nil] withRight:[[FLLRBValueNode alloc] initWithKey:@5 withValue:@5 withColor:BLACK withLeft:nil withRight:nil]] withRight:[[FLLRBValueNode alloc] initWithKey:@8 withValue:@8 withColor:BLACK withLeft:nil withRight:nil]]; - + FLLRBValueNode* node2 = [node performSelector:@selector(rotateRight)]; - + XCTAssertTrue([node2 count] == 5, @"Make sure the count is correct"); XCTAssertEqualObjects(node2.key, @4, @"Check roots key"); XCTAssertEqualObjects(node2.left.key, @2, @"Check first left child key"); @@ -245,18 +245,18 @@ insertKey:@4 withValue:@4] insertKey:@7 withValue:@7] insertKey:@9 withValue:@9]; - + XCTAssertTrue([map count] == 6, @"Check if all 6 objects are in the map"); XCTAssertTrue([map.root isMemberOfClass:[FLLRBValueNode class]], @"Root is a value node"); XCTAssertTrue([(FLLRBValueNode *)map.root checkMaxDepth], @"Checking valid depth and tree structure"); - + FTreeSortedDictionary* m2 = [[[map insertKey:@20 withValue:@20] insertKey:@18 withValue:@18] insertKey:@2 withValue:@2]; XCTAssertTrue([m2 count] == 9, @"Check if all 9 objects are in the map"); XCTAssertTrue([m2.root isMemberOfClass:[FLLRBValueNode class]], @"Root is a value node"); XCTAssertTrue([(FLLRBValueNode *)m2.root checkMaxDepth], @"Checking valid depth and tree structure"); - + FTreeSortedDictionary* m3 = [[[[m2 insertKey:@71 withValue:@71] insertKey:@42 withValue:@42] insertKey:@88 withValue:@88] @@ -270,16 +270,16 @@ FTreeSortedDictionary* map = [[[[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]] insertKey:@10 withValue:@10] insertKey:@10 withValue:@8]; - + XCTAssertEqualObjects([map get:@10], @8, @"Found first object"); } - (void) testEmpty { FTreeSortedDictionary* map = [[[[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]] insertKey:@10 withValue:@10] removeKey:@10]; - + XCTAssertTrue([map isEmpty], @"Properly empty"); - + } - (void) testEmptyGet { @@ -304,7 +304,7 @@ insertKey:@3 withValue:@3] insertKey:@2 withValue:@2] insertKey:@4 withValue:@4]; - + __block int next = 5; [map enumerateKeysAndObjectsReverse:YES usingBlock:^(id key, id value, BOOL *stop) { XCTAssertEqualObjects(key, [NSNumber numberWithInt:next], @"Properly equal"); @@ -317,18 +317,18 @@ int N = 100; NSMutableArray* toInsert = [[NSMutableArray alloc] initWithCapacity:N]; NSMutableArray* toRemove = [[NSMutableArray alloc] initWithCapacity:N]; - + for(int i = 0; i < N; i++) { [toInsert addObject:[NSNumber numberWithInt:i]]; [toRemove addObject:[NSNumber numberWithInt:i]]; } - - + + [self shuffleArray:toInsert]; [self shuffleArray:toRemove]; - + FTreeSortedDictionary* map = [[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]]; - + // add them to the dictionary for(int i = 0; i < N; i++) { map = [map insertKey:[toInsert objectAtIndex:i] withValue:[toInsert objectAtIndex:i]]; @@ -336,7 +336,7 @@ XCTAssertTrue([(FLLRBValueNode *)map.root checkMaxDepth], @"Checking valid depth and tree structure"); } XCTAssertTrue([map count] == N, @"Check if all N objects are in the map"); - + // check the order is correct __block int next = 0; [map enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) { @@ -345,9 +345,9 @@ next = next + 1; }]; XCTAssertEqual(next, N, @"Check we traversed all of the items"); - + // remove them - + for(int i = 0; i < N; i++) { if([map.root isMemberOfClass:[FLLRBValueNode class]]) { XCTAssertTrue([map.root isMemberOfClass:[FLLRBValueNode class]], @"Root is a value node"); @@ -355,8 +355,8 @@ } map = [map removeKey:[toRemove objectAtIndex:i]]; } - - + + XCTAssertEqual([map count], 0, @"Check we removed all of the items"); } @@ -370,11 +370,11 @@ } - (void) testBalanceProblem { - + NSArray* toInsert = [[NSArray alloc] initWithObjects:@1,@7,@8,@5,@2,@6,@4,@0,@3, nil]; - + FTreeSortedDictionary* map = [[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]]; - + // add them to the dictionary for(int i = 0; i < [toInsert count]; i++) { map = [map insertKey:[toInsert objectAtIndex:i] withValue:[toInsert objectAtIndex:i]]; @@ -382,7 +382,7 @@ XCTAssertTrue([(FLLRBValueNode *)map.root checkMaxDepth], @"Checking valid depth and tree structure"); } XCTAssertTrue([map count] == [toInsert count], @"Check if all N objects are in the map"); - + // check the order is correct __block int next = 0; [map enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) { @@ -391,11 +391,11 @@ next = next + 1; }]; XCTAssertEqual(next, [[NSNumber numberWithUnsignedInteger:[toInsert count]] intValue], @"Check we traversed all of the items"); - + // removing one triggers the balance problem - + map = [map removeKey:@5]; - + if([map.root isMemberOfClass:[FLLRBValueNode class]]) { XCTAssertTrue([map.root isMemberOfClass:[FLLRBValueNode class]], @"Root is a value node"); XCTAssertTrue([(FLLRBValueNode *)map.root checkMaxDepth], @"Checking valid depth and tree structure"); @@ -410,7 +410,7 @@ insertKey:@4 withValue:@4] insertKey:@7 withValue:@7] insertKey:@9 withValue:@9]; - + XCTAssertNil([map getPredecessorKey:@1], @"First object doesn't have a predecessor"); XCTAssertEqualObjects([map getPredecessorKey:@3], @1, @"@1"); XCTAssertEqualObjects([map getPredecessorKey:@4], @3, @"@3"); @@ -424,18 +424,18 @@ int N = 100; NSMutableArray* toInsert = [[NSMutableArray alloc] initWithCapacity:N]; NSMutableArray* toRemove = [[NSMutableArray alloc] initWithCapacity:N]; - + for(int i = 0; i < N; i++) { [toInsert addObject:[NSNumber numberWithInt:i]]; [toRemove addObject:[NSNumber numberWithInt:i]]; } - - + + [self shuffleArray:toInsert]; [self shuffleArray:toRemove]; - + FTreeSortedDictionary* map = [[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]]; - + // add them to the dictionary for(int i = 0; i < N; i++) { map = [map insertKey:[toInsert objectAtIndex:i] withValue:[toInsert objectAtIndex:i]]; |