1
exercism fetch objective-c crypto-square

CryptoSquareTest.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
#import <XCTest/XCTest.h>
#if __has_include("CryptoSquareExample.h")
# import "CryptoSquareExample.h"
# else
# import "CryptoSquare.h"
#endif

@interface CryptoSquareTest : XCTestCase

@end

@implementation CryptoSquareTest

- (void)testNormalizeStrangeCharacters {
    CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"s#$%^&plunk"];
    XCTAssertEqualObjects(@"splunk", [crypto normalizePlaintext]);
}

- (void)testNormalizeUppercaseCharacters {
    CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"WHOA HEY!"];
    XCTAssertEqualObjects(@"whoahey", [crypto normalizePlaintext]);
}

- (void)testNormalizeWithNumbers {
    CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"1, 2, 3 GO!"];
    XCTAssertEqualObjects(@"123go", [crypto normalizePlaintext]);
}

- (void)testSizeOfSmallSquare {
    CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"1234"];
    XCTAssertEqual(2, crypto.numberOfColumns);
}

- (void)testSizeOfSlightlyLargerSquare {
    CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"123456789"];
    XCTAssertEqual(3, crypto.numberOfColumns);
}

- (void)testSizeOfNonPerfectSquare {
    CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"123456789abc"];
    XCTAssertEqual(4, crypto.numberOfColumns);
}

- (void)testSizeIsDeterminedByNormalizedPlaintext {
    CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"Oh hey, this is nuts!"];
    XCTAssertEqual(4, crypto.numberOfColumns);
}

- (void)testPlaintextSegments {
    CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"Never vex thine heart with idle woes"];
    NSArray *expected = @[@"neverv", @"exthin", @"eheart", @"withid", @"lewoes"];
    XCTAssertEqualObjects(expected, crypto.plaintextSegments);
}

- (void)testOtherPlaintextSegments {
    CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"ZOMG! ZOMBIES!!!"];
    NSArray *expected = @[@"zomg", @"zomb", @"ies"];
    XCTAssertEqualObjects(expected, crypto.plaintextSegments);
}

- (void)testCiphertext {
    CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"Time is an illusion. Lunchtime doubly so."];
    XCTAssertEqualObjects(@"tasneyinicdsmiohooelntuillibsuuml", crypto.cipherText);
}

- (void)testAnotherCiphertext {
    CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"We all know interspecies romance is weird."];
    XCTAssertEqualObjects(@"wneiaweoreneawssciliprerlneoidktcms", crypto.cipherText);
}

- (void)testNormalizedCiphertext {
    CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"Vampires are people too!"];
    XCTAssertEqualObjects(@"vrel aepe mset paoo irpo", crypto.normalizedCipherText);
}

- (void)testNormalizedCiphertextSpillsIntoShortSegment {
    CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"Madness, and then illumination."];
    XCTAssertEqualObjects(@"msemo aanin dninn dlaet ltshu i", crypto.normalizedCipherText);
}

- (void)testAnotherNormalizedCiphertext {
    CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:
                            @"If man was meant to stay on the ground god would have given us roots"];
    NSString *expected = @"imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghns seoau";
    XCTAssertEqualObjects(expected, crypto.normalizedCipherText);
}

- (void)testNormalizedCiphertextWithPunctuation {
    CryptoSquare *crypto = [[CryptoSquare alloc] initWithText:@"Have a nice day. Feed the dog & chill out!"];
    NSString *expected = @"hifei acedl veeol eddgo aatcu nyhht";
    XCTAssertEqualObjects(expected, crypto.normalizedCipherText);
}

@end