1
exercism fetch java crypto-square

src/test/java/CryptoSquareTest.java

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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import org.junit.Test;
import org.junit.Ignore;

import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class CryptoSquareTest {


    @Test
    public void strangeCharactersAreStrippedDuringNormalization() {
        Crypto crypto = new Crypto("s#$%^&plunk");
        String expectedOutput = "splunk";

        assertEquals(expectedOutput, crypto.getNormalizedPlaintext());
    }

    @Ignore("Remove to run test")
    @Test
    public void lettersAreLowerCasedDuringNormalization() {
        Crypto crypto = new Crypto("WHOA HEY!");
        String expectedOutput = "whoahey";

        assertEquals(expectedOutput, crypto.getNormalizedPlaintext());
    }

    @Ignore("Remove to run test")
    @Test
    public void numbersAreKeptDuringNormalization() {
        Crypto crypto = new Crypto("1, 2, 3, GO!");
        String expectedOutput = "123go";

        assertEquals(expectedOutput, crypto.getNormalizedPlaintext());
    }

    @Ignore("Remove to run test")
    @Test
    public void smallestSquareSizeIs2() {
        Crypto crypto = new Crypto("1234");
        int expectedOutput = 2;

        assertEquals(expectedOutput, crypto.getSquareSize());
    }

    @Ignore("Remove to run test")
    @Test
    public void sizeOfTextWhoseLengthIsPerfectSquareIsItsSquareRoot() {
        Crypto crypto = new Crypto("123456789");
        int expectedOutput = 3;

        assertEquals(expectedOutput, crypto.getSquareSize());
    }

    @Ignore("Remove to run test")
    @Test
    public void sizeOfTextWhoseLengthIsNoPerfectSquareIsNextBiggestSquareRoot() {
        Crypto crypto = new Crypto("123456789abc");
        int expectedOutput = 4;

        assertEquals(expectedOutput, crypto.getSquareSize());
    }

    @Ignore("Remove to run test")
    @Test
    public void sizeIsDeterminedByNormalizedText() {
        Crypto crypto = new Crypto("Oh hey, this is nuts!");
        int expectedOutput = 4;

        assertEquals(expectedOutput, crypto.getSquareSize());
    }

    @Ignore("Remove to run test")
    @Test
    public void segmentsAreSplitBySquareSize() {
        Crypto crypto = new Crypto("Never vex thine heart with idle woes");
        List<String> expectedOutput = Arrays.asList(new String[]{"neverv", "exthin", "eheart", "withid", "lewoes"});

        assertEquals(expectedOutput, crypto.getPlaintextSegments());
    }

    @Ignore("Remove to run test")
    @Test
    public void segmentsAreSplitBySquareSizeUntilTextRunsOut() {
        Crypto crypto = new Crypto("ZOMG! ZOMBIES!!!");
        List<String> expectedOutput = Arrays.asList(new String[]{"zomg", "zomb", "ies"});

        assertEquals(expectedOutput, crypto.getPlaintextSegments());
    }

    @Ignore("Remove to run test")
    @Test
    public void cipherTextCombinesTextByColumn() {
        Crypto crypto = new Crypto("First, solve the problem. Then, write the code.");
        String expectedOutput = "foeewhilpmrervrticseohtottbeedshlnte";

        assertEquals(expectedOutput, crypto.getCipherText());
    }

    @Ignore("Remove to run test")
    @Test
    public void cipherTextSkipsCellsWithNoText() {
        Crypto crypto = new Crypto("Time is an illusion. Lunchtime doubly so.");
        String expectedOutput = "tasneyinicdsmiohooelntuillibsuuml";

        assertEquals(expectedOutput, crypto.getCipherText());
    }

    @Ignore("Remove to run test")
    @Test
    public void normalizedCipherTextIsSplitByHeightOfSquare() {
        Crypto crypto = new Crypto("Vampires are people too!");
        String expectedOutput = "vrel aepe mset paoo irpo";

        assertEquals(expectedOutput, crypto.getNormalizedCipherText());
    }

    @Ignore("Remove to run test")
    @Test
    public void normalizedCipherNotExactlyDivisibleBy5SpillsIntoSmallerSegment() {
        Crypto crypto = new Crypto("Madness, and then illumination.");
        String expectedOutput = "msemo aanin dnin ndla etlt shui";

        assertEquals(expectedOutput, crypto.getNormalizedCipherText());
    }

    @Ignore("Remove to run test")
    @Test
    public void normalizedCipherIsSplitIntoSegmentsOfCorrectSize() {
        Crypto crypto = new Crypto("If man was meant to stay on the ground god would have given us roots");
        String expectedOutput = "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau";

        assertEquals(expectedOutput, crypto.getNormalizedCipherText());
    }

    @Ignore("Remove to run test")
    @Test
    public void normalizedCipherTextIsSplitIntoSegmentsOfCorrectSizeWithPunctuation() {
        Crypto crypto = new Crypto("Have a nice day. Feed the dog & chill out!");
        String expectedOutput = "hifei acedl veeol eddgo aatcu nyhht";

        assertEquals(expectedOutput, crypto.getNormalizedCipherText());
    }
}