1
exercism fetch objective-c sublist

SublistTest.m

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#import <XCTest/XCTest.h>

#if __has_include("SublistExample.h")
# import "SublistExample.h"
# else
# import "Sublist.h"
#endif

@interface SublistTest : XCTestCase

@end

@implementation SublistTest

- (void)testEmptyLists {
    XCTAssertEqual(SublistKindEqual, [SublistExample classifierForFirstList:@[] andSecondList:@[]]);
}
    
- (void)testEmptyListWithinNonEmptyList {
    NSArray *secondList = @[@1, @2, @3];
    XCTAssertEqual(SublistKindSublist, [SublistExample classifierForFirstList:@[] andSecondList:secondList]);
}
    
- (void)testNonEmptyListContainsEmptyList {
    NSArray *firstList = @[@1, @2, @3];
    XCTAssertEqual(SublistKindSuperlist, [SublistExample classifierForFirstList:firstList andSecondList:@[]]);
}
    
- (void)testListEqualsItself {
    NSArray *firstList = @[@1, @2, @3];
    NSArray *secondList = @[@1, @2, @3];
    XCTAssertEqual(SublistKindEqual, [SublistExample classifierForFirstList:firstList andSecondList:secondList]);
}
    
- (void)testDifferentLists {
    NSArray *firstList = @[@1, @2, @3];
    NSArray *secondList = @[@2, @3, @4];
    XCTAssertEqual(SublistKindUnequal, [SublistExample classifierForFirstList:firstList andSecondList:secondList]);
}
    
- (void)testFalseStart {
    NSArray *firstList = @[@1, @2, @5];
    NSArray *secondList = @[@0, @1, @2, @3, @1, @2, @5, @6];
    XCTAssertEqual(SublistKindSublist, [SublistExample classifierForFirstList:firstList andSecondList:secondList]);
}
    
- (void)testConsecutive {
    NSArray *firstList = @[@1, @1, @2];
    NSArray *secondList = @[@0, @1, @1, @1, @2, @1, @2];
    XCTAssertEqual(SublistKindSublist, [SublistExample classifierForFirstList:firstList andSecondList:secondList]);
}
    
- (void)testSublistAtStart {
    NSArray *firstList = @[@0, @1, @2];
    NSArray *secondList = @[@0, @1, @2, @3, @4, @5];
    XCTAssertEqual(SublistKindSublist, [SublistExample classifierForFirstList:firstList andSecondList:secondList]);
}
    
- (void)testSublistInMiddle{
    NSArray *firstList = @[@2, @3, @4];
    NSArray *secondList = @[@0, @1, @2, @3, @4, @5];
    XCTAssertEqual(SublistKindSublist, [SublistExample classifierForFirstList:firstList andSecondList:secondList]);
}
    
- (void)testSublistAtEnd {
    NSArray *firstList = @[@3, @4, @5];
    NSArray *secondList = @[@0, @1, @2, @3, @4, @5];
    XCTAssertEqual(SublistKindSublist, [SublistExample classifierForFirstList:firstList andSecondList:secondList]);
}
    
- (void)testAtStartOfSuperlist {
    NSArray *firstList = @[@0, @1, @2, @3, @4, @5];
    NSArray *secondList = @[@0, @1, @2];
    XCTAssertEqual(SublistKindSuperlist, [SublistExample classifierForFirstList:firstList andSecondList:secondList]);
}
    
- (void)testAtMiddleOfSuperlist {
    NSArray *firstList = @[@0, @1, @2, @3, @4, @5];
    NSArray *secondList = @[@2, @3];
    XCTAssertEqual(SublistKindSuperlist, [SublistExample classifierForFirstList:firstList andSecondList:secondList]);
}

- (void)testAtEndOfSuperlist {
    NSArray *firstList = @[@0, @1, @2, @3, @4, @5];
    NSArray *secondList = @[@3, @4, @5];
    XCTAssertEqual(SublistKindSuperlist, [SublistExample classifierForFirstList:firstList andSecondList:secondList]);
}
    
- (void)testFirstListMissingElementFromSecondList {
    NSArray *firstList = @[@1, @3];
    NSArray *secondList = @[@1, @2, @3];
    XCTAssertEqual(SublistKindUnequal, [SublistExample classifierForFirstList:firstList andSecondList:secondList]);
}
    
- (void)testSecondListMissingOneElementFromFirstList {
    NSArray *firstList = @[@1, @2, @3];
    NSArray *secondList = @[@1, @3];
    XCTAssertEqual(SublistKindUnequal, [SublistExample classifierForFirstList:firstList andSecondList:secondList]);
}
    
- (void)testOrderMattersToAList {
    NSArray *firstList = @[@1, @2, @3];
    NSArray *secondList = @[@3, @2, @1];
    XCTAssertEqual(SublistKindUnequal, [SublistExample classifierForFirstList:firstList andSecondList:secondList]);
}
    
- (void)testSameDigitsButDifferentNumbers {
    NSArray *firstList = @[@1, @0, @1];
    NSArray *secondList = @[@10, @1];
    XCTAssertEqual(SublistKindUnequal, [SublistExample classifierForFirstList:firstList andSecondList:secondList]);
}

@end