1
exercism fetch objective-c run-length-encoding

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

#if __has_include("RunLengthEncodingExample.h")
# import "RunLengthEncodingExample.h"
# else
# import "RunLengthEncoding.h"
#endif

@interface RunLengthEncodingTest : XCTestCase

@end

@implementation RunLengthEncodingTest

- (void)testEncodeSimple {
    XCTAssertEqualObjects([RunLengthEncoding encode:@"AABBBCCCC"], @"2A3B4C");
}

- (void)testDecodeSimple {
    XCTAssertEqualObjects([RunLengthEncoding decode:@"2A3B4C"], @"AABBBCCCC");
}

- (void)testEncodeWithSingleValues {
    XCTAssertEqualObjects([RunLengthEncoding encode:@"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"], @"12WB12W3B24WB");
}

- (void)testDecodeWithSingleValues {
    XCTAssertEqualObjects([RunLengthEncoding decode:@"12WB12W3B24WB"], @"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB");
}

- (void)testDecodeEncodeCombination {
    XCTAssertEqualObjects([RunLengthEncoding decode:[RunLengthEncoding encode:@"zzz ZZ  zZ"]], @"zzz ZZ  zZ");
}

- (void)testEncodeUnicode {
    XCTAssertEqualObjects([RunLengthEncoding encode:@"⏰⚽⚽⚽⭐⭐⏰"], @"⏰3⚽2⭐⏰");
}

- (void)testDecodeUnicode {
    XCTAssertEqualObjects([RunLengthEncoding decode:@"⏰3⚽2⭐⏰"], @"⏰⚽⚽⚽⭐⭐⏰");
}

@end