-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNNArrayDiffSpec.m
More file actions
59 lines (46 loc) · 2.81 KB
/
Copy pathNNArrayDiffSpec.m
File metadata and controls
59 lines (46 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// NNArrayDiffSpec.m
// ArrayDiff
//
// Created by Nick Tymchenko on 20/04/14.
// Copyright (c) 2014 Nick Tymchenko. All rights reserved.
//
#import <XCTest/XCTest.h>
SpecBegin(NNArrayDiff)
describe(@"-initWithDeleted:inserted:changed:", ^{
it(@"should initialize diff object with given values", ^{
NNArrayDiff *diff = [[NNArrayDiff alloc] initWithDeleted:[NSIndexSet indexSetWithIndex:1]
inserted:[NSIndexSet indexSetWithIndex:2]
changed:[NSSet setWithObject:[[NNArrayDiffChange alloc] initWithBefore:3 after:4 type:NNDiffChangeMove]]];
expect(diff.deleted).to.equal([NSIndexSet indexSetWithIndex:1]);
expect(diff.inserted).to.equal([NSIndexSet indexSetWithIndex:2]);
expect(diff.changed).to.equal([NSSet setWithObject:[[NNArrayDiffChange alloc] initWithBefore:3 after:4 type:NNDiffChangeMove]]);
});
it(@"should handle nil arguments properly", ^{
NNArrayDiff *diff = [[NNArrayDiff alloc] initWithDeleted:nil inserted:nil changed:nil];
expect(diff.deleted).to.equal([NSIndexSet indexSet]);
expect(diff.inserted).to.equal([NSIndexSet indexSet]);
expect(diff.changed).to.equal([NSSet set]);
});
});
describe(@"-isEqual:", ^{
it(@"should return YES for equal diffs", ^{
NNArrayDiff *diff = [[NNArrayDiff alloc] initWithDeleted:[NSIndexSet indexSetWithIndex:1]
inserted:[NSIndexSet indexSetWithIndex:2]
changed:[NSSet setWithObject:[[NNArrayDiffChange alloc] initWithBefore:3 after:4 type:NNDiffChangeMove]]];
NNArrayDiff *anotherDiff = [[NNArrayDiff alloc] initWithDeleted:[NSIndexSet indexSetWithIndex:1]
inserted:[NSIndexSet indexSetWithIndex:2]
changed:[NSSet setWithObject:[[NNArrayDiffChange alloc] initWithBefore:3 after:4 type:NNDiffChangeMove]]];
expect([diff isEqual:anotherDiff]).to.beTruthy();
});
it(@"should return NO for different diffs", ^{
NNArrayDiff *diff = [[NNArrayDiff alloc] initWithDeleted:[NSIndexSet indexSetWithIndex:1]
inserted:nil
changed:nil];
NNArrayDiff *anotherDiff = [[NNArrayDiff alloc] initWithDeleted:[NSIndexSet indexSetWithIndex:42]
inserted:nil
changed:nil];
expect([diff isEqual:anotherDiff]).to.beFalsy();
});
});
SpecEnd