Last active
August 29, 2015 14:15
-
-
Save bgerstle/4b23a5c4b6b7323b7b1a to your computer and use it in GitHub Desktop.
Some tests demonstrating copying behavior of immutable and mutable dictionaries.
This file contains hidden or 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
- (void)testCopyReturnsImmutable | |
{ | |
NSDictionary* immutable = @{@"foo": @"bar"}; | |
NSMutableDictionary* mutable = [immutable mutableCopy]; | |
NSDictionary* copyOfMutable = [mutable copy]; | |
XCTAssertFalse([copyOfMutable isMemberOfClass:[NSMutableDictionary class]]); | |
// interestingly, the class is actually __NSDictionaryI, so you can't assert isMemberOfClass:NSDictionary | |
XCTAssertTrue([copyOfMutable isKindOfClass:[NSDictionary class]]); | |
} | |
- (void)testCopyOfImmutableReturnsSelf | |
{ | |
NSDictionary* test = @{@"foo": @1}; | |
XCTAssertEqual(test, [test copy], @"Expected copies of immutable objects to be the objects themselves."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment