From 920ed00a7fd8f53ecb68e1f874adf06656174ce1 Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Fri, 18 Nov 2016 13:23:04 -0800 Subject: [PATCH] Test move sorting and pointer equality Summary: A couple other methods that were missing coverage. - [x] All tests pass. Demo project builds and runs. - [x] I added tests, an experiment, or detailed why my change isn't tested. - [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/CONTRIBUTING.md) Closes https://github.com/Instagram/IGListKit/pull/222 Differential Revision: D4206510 Pulled By: rnystrom fbshipit-source-id: c21a88a00881dc88cc20b3957179e4d267be95a3 --- Tests/IGListDiffResultTests.m | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/Tests/IGListDiffResultTests.m b/Tests/IGListDiffResultTests.m index b66f5b0..6d7eb98 100644 --- a/Tests/IGListDiffResultTests.m +++ b/Tests/IGListDiffResultTests.m @@ -68,4 +68,52 @@ XCTAssertEqual(set.count, 2); } +- (void)test_whenComparingMovePointers_withIndexPaths_thatEqual { + IGListMoveIndexPath *move = [[IGListMoveIndexPath alloc] initWithFrom:[NSIndexPath new] to:[NSIndexPath new]]; + XCTAssertTrue([move isEqual:move]); +} + +- (void)test_whenComparingMovePointers_withIndexes_thatEqual { + IGListMoveIndex *move = [[IGListMoveIndex alloc] initWithFrom:1 to:1]; + XCTAssertTrue([move isEqual:move]); +} + +- (void)test_whenComparingMoves_withIndexPaths_withNonMove_thatNotEqual { + IGListMoveIndexPath *move = [[IGListMoveIndexPath alloc] initWithFrom:[NSIndexPath new] to:[NSIndexPath new]]; + XCTAssertFalse([move isEqual:[NSObject new]]); +} + +- (void)test_whenComparingMoves_withIndexes_withNonMove_thatNotEqual { + IGListMoveIndex *move = [[IGListMoveIndex alloc] initWithFrom:1 to:1]; + XCTAssertFalse([move isEqual:[NSObject new]]); +} + +- (void)test_whenSortingMoves_withIndexPaths_thatSorted { + NSArray *moves = @[ + [[IGListMoveIndexPath alloc] initWithFrom:[NSIndexPath indexPathForItem:2 inSection:2] + to:[NSIndexPath indexPathForItem:3 inSection:3]], + [[IGListMoveIndexPath alloc] initWithFrom:[NSIndexPath indexPathForItem:6 inSection:3] + to:[NSIndexPath indexPathForItem:7 inSection:4]], + [[IGListMoveIndexPath alloc] initWithFrom:[NSIndexPath indexPathForItem:0 inSection:1] + to:[NSIndexPath indexPathForItem:1 inSection:5]], + [[IGListMoveIndexPath alloc] initWithFrom:[NSIndexPath indexPathForItem:2 inSection:2] + to:[NSIndexPath indexPathForItem:3 inSection:3]], + ]; + NSArray *expected = @[moves[2], moves[0], moves[3], moves[1]]; + NSArray *sorted = [moves sortedArrayUsingSelector:@selector(compare:)]; + XCTAssertEqualObjects(sorted, expected); +} + +- (void)test_whenSortingMoves_withIndexes_thatSorted { + NSArray *moves = @[ + [[IGListMoveIndex alloc] initWithFrom:2 to:2], + [[IGListMoveIndex alloc] initWithFrom:3 to:2], + [[IGListMoveIndex alloc] initWithFrom:1 to:2], + [[IGListMoveIndex alloc] initWithFrom:2 to:2], + ]; + NSArray *expected = @[moves[2], moves[0], moves[3], moves[1]]; + NSArray *sorted = [moves sortedArrayUsingSelector:@selector(compare:)]; + XCTAssertEqualObjects(sorted, expected); +} + @end