1
exercism fetch objective-c flatten-array

FlattenArrayTest.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
#import <XCTest/XCTest.h>

#if __has_include("FlattenArrayExample.h")
# import "FlattenArrayExample.h"
# else
# import "FlattenArray.h"
#endif

@interface FlattenArrayTest : XCTestCase

@end

static NSNull *nullValue;

@implementation FlattenArrayTest

- (void)setUp {
    nullValue = [NSNull null];
}

- (void)testFlattenArrayWithJustIntegers {
    NSArray *inputArray = @[@1, @[@2, @3, @4, @5, @6, @7], @8];
    NSArray *expected = @[@1, @2, @3, @4, @5, @6, @7, @8];
    XCTAssertEqualObjects(expected, [FlattenArrayExample flattenArray:inputArray]);
}

- (void)testFiveLevelNesting {
    NSArray *inputArray = @[@0, @2, @[@[@2, @3], @8, @100, @4, @[@[@50]]], @-2];
    NSArray *expected = @[@0, @2, @2, @3, @8, @100, @4, @50, @-2];
    XCTAssertEqualObjects(expected, [FlattenArrayExample flattenArray:inputArray]);
}

- (void)testSixLevelNesting {
    NSArray *inputArray = @[@1, @[@2, @[@[@3]], @[@4, @[@[@5]]], @6, @7], @8];
    NSArray *expected = @[@1, @2, @3, @4, @5, @6, @7, @8];
    XCTAssertEqualObjects(expected, [FlattenArrayExample flattenArray:inputArray]);
}

- (void)testSixLevelNestingWithNullValues {
    NSArray *inputArray = @[@0, @2, @[@[@2, @3], @8, @[@[@100]], nullValue, @[@[nullValue]]], @-2];
    NSArray *expected = @[@0, @2, @2, @3, @8, @100, @-2];
    XCTAssertEqualObjects(expected, [FlattenArrayExample flattenArray:inputArray]);
}

- (void)testAllValuesInNestedListAreNull {
    NSArray *inputArray = @[nullValue, @[@[@[@[nullValue]]]], nullValue, nullValue, @[@[nullValue, nullValue], nullValue], nullValue];
    NSArray *expected = @[];
    XCTAssertEqualObjects(expected, [FlattenArrayExample flattenArray:inputArray]);
}

- (void)testFiveLevelDeepNestedListWithDoubleValuesAndNullValues {
    NSArray *inputArray = @[@0.085, @2.8844557, @[@[@2.00005, @3.13], @8.4, @100, @4.8, @[@[@[nullValue]]]], @-2.5];
    NSArray *expected = @[@0.085, @2.8844557, @2.00005, @3.13, @8.4, @100, @4.8, @-2.5];
    XCTAssertEqualObjects(expected, [FlattenArrayExample flattenArray:inputArray]);
}

- (void)testSixLevelDeepNestedListWithStringsAndNullValues {
    NSArray *inputArray = @[@"Zero", @"two", @[@[@[@"Two", @"three"]], @"eight", @[@[@"One Hundred"]], nullValue, @[@[nullValue]]], @"minus two"];
    NSArray *expected = @[@"Zero", @"two", @"Two", @"three", @"eight", @"One Hundred", @"minus two"];
    XCTAssertEqualObjects(expected, [FlattenArrayExample flattenArray:inputArray]);
}
@end