Преглед на файлове

Merge pull request #1 from exercism/master

merge
Pavol Pidanič преди 11 години
родител
ревизия
3b158e5c37

+ 11
- 0
accumulate/build.gradle Целия файл

@@ -0,0 +1,11 @@
1
+apply plugin: "java"
2
+apply plugin: "eclipse"
3
+apply plugin: "idea"
4
+
5
+repositories {
6
+  mavenCentral()
7
+}
8
+
9
+dependencies {
10
+  testCompile "junit:junit:4.10"
11
+}

+ 16
- 0
accumulate/example.java Целия файл

@@ -0,0 +1,16 @@
1
+import java.util.ArrayList;
2
+import java.util.List;
3
+import java.util.function.Function;
4
+
5
+public class Accumulate {
6
+
7
+	public static <T> List<T> accumulate(List<T> collection, Function<T, T> function) {
8
+		List<T> newCollection = new ArrayList<>();
9
+
10
+		for (T item : collection) {
11
+			newCollection.add(function.apply(item));
12
+		}
13
+
14
+		return newCollection;
15
+	}
16
+}

+ 0
- 0
accumulate/src/main/java/.keep Целия файл


+ 2
- 0
accumulate/src/main/java/Accumulate.java Целия файл

@@ -0,0 +1,2 @@
1
+public class Accumulate {
2
+}

+ 53
- 0
accumulate/src/test/java/AccumulateTest.java Целия файл

@@ -0,0 +1,53 @@
1
+import org.junit.Test;
2
+
3
+import java.util.Arrays;
4
+import java.util.LinkedList;
5
+import java.util.List;
6
+
7
+import static org.junit.Assert.assertEquals;
8
+
9
+public class AccumulateTest {
10
+
11
+    @Test
12
+    public void emptyAccumulateProducesEmptyAccumulation() {
13
+        List<Integer> input = new LinkedList<>();
14
+        List<Integer> expectedOutput = new LinkedList<>();
15
+        assertEquals(expectedOutput, Accumulate.accumulate(input, x -> x * x));
16
+    }
17
+
18
+    @Test
19
+    public void accumulateSquares() {
20
+        List<Integer> input = Arrays.asList(1, 2, 3);
21
+        List<Integer> expectedOutput = Arrays.asList(1, 4, 9);
22
+        assertEquals(expectedOutput, Accumulate.accumulate(input, x -> x * x));
23
+    }
24
+
25
+    @Test
26
+    public void accumulateUpperCases() {
27
+        List<String> input = Arrays.asList("hello", "world");
28
+        List<String> expectedOutput = Arrays.asList("HELLO", "WORLD");
29
+        assertEquals(expectedOutput, Accumulate.accumulate(input, x -> x.toUpperCase()));
30
+    }
31
+
32
+    @Test
33
+    public void accumulateReversedStrings() {
34
+        List<String> input = Arrays.asList("the quick brown fox etc".split(" "));
35
+        List<String> expectedOutput = Arrays.asList("eht kciuq nworb xof cte".split(" "));
36
+        assertEquals(expectedOutput, Accumulate.accumulate(input, this::reverse));
37
+    }
38
+
39
+    private String reverse(String input) {
40
+        return new StringBuilder(input).reverse().toString();
41
+    }
42
+
43
+    @Test
44
+    public void accumulateWithinAccumulate() {
45
+        List<String> input1 = Arrays.asList("a", "b", "c");
46
+        List<String> input2 = Arrays.asList("1", "2", "3");
47
+        List<String> expectedOutput = Arrays.asList("a1 a2 a3", "b1 b2 b3", "c1 c2 c3");
48
+        assertEquals(expectedOutput, Accumulate.accumulate(
49
+                input1, c ->
50
+                        String.join(" ", Accumulate.accumulate(input2, d -> c + d))
51
+        ));
52
+    }
53
+}

+ 11
- 0
atbash-cipher/build.gradle Целия файл

@@ -0,0 +1,11 @@
1
+apply plugin: "java"
2
+apply plugin: "eclipse"
3
+apply plugin: "idea"
4
+
5
+repositories {
6
+  mavenCentral()
7
+}
8
+
9
+dependencies {
10
+  testCompile "junit:junit:4.10"
11
+}

+ 48
- 0
atbash-cipher/example.java Целия файл

@@ -0,0 +1,48 @@
1
+import java.util.ArrayList;
2
+import java.util.List;
3
+
4
+public class Atbash {
5
+
6
+    private static final int GROUP_SIZE = 5;
7
+    private static final String PLAIN = "abcdefghijklmnopqrstuvwxyz";
8
+    private static final String CIPHER = "zyxwvutsrqponmlkjihgfedcba";
9
+
10
+    public static String encode(String input) {
11
+        String encoded = stripInvalidCharacters(input).toLowerCase();
12
+        String cyphered = "";
13
+
14
+        for (char c : encoded.toCharArray()) {
15
+            cyphered += applyCipher(c);
16
+        }
17
+
18
+        return splitIntoFiveLetterWords(cyphered);
19
+    }
20
+
21
+    private static String stripInvalidCharacters(String input) {
22
+        String filteredValue = "";
23
+
24
+        for (char c : input.toCharArray()) {
25
+            if (Character.isLetterOrDigit(c)) {
26
+                filteredValue += c;
27
+            }
28
+        }
29
+
30
+        return filteredValue;
31
+    }
32
+
33
+    private static char applyCipher(char input) {
34
+        int idx = PLAIN.indexOf(input);
35
+
36
+        return idx >= 0 ? CIPHER.toCharArray()[idx] : input;
37
+    }
38
+
39
+    private static String splitIntoFiveLetterWords(String value) {
40
+        List<String> words = new ArrayList<>();
41
+
42
+        for (int i = 0; i < value.length(); i += GROUP_SIZE) {
43
+            words.add(i + GROUP_SIZE <= value.length() ? value.substring(i, i + GROUP_SIZE) : value.substring(i));
44
+        }
45
+
46
+        return String.join(" ", words);
47
+    }
48
+}

+ 0
- 0
atbash-cipher/src/main/java/.keep Целия файл


+ 2
- 0
atbash-cipher/src/main/java/Atbash.java Целия файл

@@ -0,0 +1,2 @@
1
+public class Atbash {
2
+}

+ 38
- 0
atbash-cipher/src/test/java/AtbashTest.java Целия файл

@@ -0,0 +1,38 @@
1
+import org.junit.Test;
2
+import org.junit.runner.RunWith;
3
+import org.junit.runners.Parameterized;
4
+
5
+import java.util.Arrays;
6
+import java.util.Collection;
7
+
8
+import static org.junit.Assert.assertEquals;
9
+
10
+@RunWith(Parameterized.class)
11
+public class AtbashTest {
12
+
13
+    private String input;
14
+    private String expectedOutput;
15
+
16
+    @Parameterized.Parameters
17
+    public static Collection<Object[]> data() {
18
+        return Arrays.asList(new Object[][]{
19
+                {"no", "ml"},
20
+                {"yes", "bvh"},
21
+                {"OMG", "lnt"},
22
+                {"mindblowingly", "nrmwy oldrm tob"},
23
+                {"Testing, 1 2 3, testing.", "gvhgr mt123 gvhgr mt"},
24
+                {"Truth is fiction.", "gifgs rhurx grlm"},
25
+                {"The quick brown fox jumps over the lazy dog.", "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"}
26
+        });
27
+    }
28
+
29
+    public AtbashTest(String input, String expectedOutput) {
30
+        this.input = input;
31
+        this.expectedOutput = expectedOutput;
32
+    }
33
+
34
+    @Test
35
+    public void test() {
36
+        assertEquals(expectedOutput, Atbash.encode(input));
37
+    }
38
+}

+ 4
- 1
config.json Целия файл

@@ -23,7 +23,10 @@
23 23
     "prime-factors",
24 24
     "raindrops",
25 25
     "allergies",
26
-    "strain"
26
+    "strain",
27
+    "atbash-cipher",
28
+    "accumulate",
29
+    "crypto-square"
27 30
   ],
28 31
   "deprecated": [
29 32
   ],

+ 11
- 0
crypto-square/build.gradle Целия файл

@@ -0,0 +1,11 @@
1
+apply plugin: "java"
2
+apply plugin: "eclipse"
3
+apply plugin: "idea"
4
+
5
+repositories {
6
+  mavenCentral()
7
+}
8
+
9
+dependencies {
10
+  testCompile "junit:junit:4.10"
11
+}

+ 72
- 0
crypto-square/example.java Целия файл

@@ -0,0 +1,72 @@
1
+import java.util.ArrayList;
2
+import java.util.List;
3
+
4
+public class Crypto {
5
+
6
+    private String normalizedPlaintext;
7
+    private int squareSize;
8
+
9
+    public Crypto(String text) {
10
+        this.normalizedPlaintext = normalizeText(text);
11
+        this.squareSize = calculateSquareSize(normalizedPlaintext);
12
+    }
13
+
14
+    public String getNormalizedPlaintext() {
15
+        return normalizedPlaintext;
16
+    }
17
+
18
+    public int getSquareSize() {
19
+        return squareSize;
20
+    }
21
+
22
+    private static String normalizeText(String text) {
23
+        return text.toLowerCase().codePoints()
24
+                .filter(x -> Character.isLetterOrDigit(x))
25
+                .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
26
+                .toString();
27
+    }
28
+
29
+    private static int calculateSquareSize(String text) {
30
+        return (int) Math.ceil(Math.sqrt(text.length()));
31
+    }
32
+
33
+    public List<String> getPlaintextSegments() {
34
+        return getSegmentText(normalizedPlaintext, squareSize);
35
+    }
36
+
37
+    private static List<String> getSegmentText(String text, int squareSize) {
38
+        List<String> segments = new ArrayList<>();
39
+        int index = 0;
40
+
41
+        while (index < text.length()) {
42
+            if (index + squareSize < text.length()) {
43
+                segments.add(text.substring(index, index + squareSize));
44
+            } else {
45
+                segments.add(text.substring(index));
46
+            }
47
+            index += squareSize;
48
+        }
49
+
50
+        return segments;
51
+    }
52
+
53
+    public String getCipherText() {
54
+        StringBuilder cipherText = new StringBuilder(normalizedPlaintext.length());
55
+
56
+        for (int index = 0; index < squareSize; index++) {
57
+            for (String segment : getPlaintextSegments()) {
58
+                if (index < segment.length()) {
59
+                    cipherText.append(segment.charAt(index));
60
+                }
61
+            }
62
+        }
63
+
64
+        return cipherText.toString();
65
+    }
66
+
67
+    public String getNormalizedCipherText() {
68
+        String cipher = getCipherText();
69
+
70
+        return String.join(" ", getSegmentText(cipher, squareSize - 1));
71
+    }
72
+}

+ 0
- 0
crypto-square/src/main/java/.keep Целия файл


+ 2
- 0
crypto-square/src/main/java/Crypto.java Целия файл

@@ -0,0 +1,2 @@
1
+public class Crypto {
2
+}

+ 129
- 0
crypto-square/src/test/java/CryptoSquareTest.java Целия файл

@@ -0,0 +1,129 @@
1
+import org.junit.Test;
2
+
3
+import java.util.Arrays;
4
+import java.util.List;
5
+
6
+import static org.junit.Assert.assertEquals;
7
+
8
+public class CryptoSquareTest {
9
+
10
+    @Test
11
+    public void strangeCharactersAreStrippedDuringNormalization() {
12
+        Crypto crypto = new Crypto("s#$%^&plunk");
13
+        String expectedOutput = "splunk";
14
+
15
+        assertEquals(expectedOutput, crypto.getNormalizedPlaintext());
16
+    }
17
+
18
+    @Test
19
+    public void lettersAreLowerCasedDuringNormalization() {
20
+        Crypto crypto = new Crypto("WHOA HEY!");
21
+        String expectedOutput = "whoahey";
22
+
23
+        assertEquals(expectedOutput, crypto.getNormalizedPlaintext());
24
+    }
25
+
26
+    @Test
27
+    public void numbersAreKeptDuringNormalization() {
28
+        Crypto crypto = new Crypto("1, 2, 3, GO!");
29
+        String expectedOutput = "123go";
30
+
31
+        assertEquals(expectedOutput, crypto.getNormalizedPlaintext());
32
+    }
33
+
34
+    @Test
35
+    public void smallestSquareSizeIs2() {
36
+        Crypto crypto = new Crypto("1234");
37
+        int expectedOutput = 2;
38
+
39
+        assertEquals(expectedOutput, crypto.getSquareSize());
40
+    }
41
+
42
+    @Test
43
+    public void sizeOfTextWhoseLengthIsPerfectSquareIsItsSquareRoot() {
44
+        Crypto crypto = new Crypto("123456789");
45
+        int expectedOutput = 3;
46
+
47
+        assertEquals(expectedOutput, crypto.getSquareSize());
48
+    }
49
+
50
+    @Test
51
+    public void sizeOfTextWhoseLengthIsNoPerfectSquareIsNextBiggestSquareRoot() {
52
+        Crypto crypto = new Crypto("123456789abc");
53
+        int expectedOutput = 4;
54
+
55
+        assertEquals(expectedOutput, crypto.getSquareSize());
56
+    }
57
+
58
+    @Test
59
+    public void sizeIsDeterminedByNormalizedText() {
60
+        Crypto crypto = new Crypto("Oh hey, this is nuts!");
61
+        int expectedOutput = 4;
62
+
63
+        assertEquals(expectedOutput, crypto.getSquareSize());
64
+    }
65
+
66
+    @Test
67
+    public void segmentsAreSplitBySquareSize() {
68
+        Crypto crypto = new Crypto("Never vex thine heart with idle woes");
69
+        List<String> expectedOutput = Arrays.asList(new String[]{"neverv", "exthin", "eheart", "withid", "lewoes"});
70
+
71
+        assertEquals(expectedOutput, crypto.getPlaintextSegments());
72
+    }
73
+
74
+    @Test
75
+    public void segmentsAreSplitBySquareSizeUntilTextRunsOut() {
76
+        Crypto crypto = new Crypto("ZOMG! ZOMBIES!!!");
77
+        List<String> expectedOutput = Arrays.asList(new String[]{"zomg", "zomb", "ies"});
78
+
79
+        assertEquals(expectedOutput, crypto.getPlaintextSegments());
80
+    }
81
+
82
+    @Test
83
+    public void cipherTextCombinesTextByColumn() {
84
+        Crypto crypto = new Crypto("First, solve the problem. Then, write the code.");
85
+        String expectedOutput = "foeewhilpmrervrticseohtottbeedshlnte";
86
+
87
+        assertEquals(expectedOutput, crypto.getCipherText());
88
+    }
89
+
90
+    @Test
91
+    public void cipherTextSkipsCellsWithNoText() {
92
+        Crypto crypto = new Crypto("Time is an illusion. Lunchtime doubly so.");
93
+        String expectedOutput = "tasneyinicdsmiohooelntuillibsuuml";
94
+
95
+        assertEquals(expectedOutput, crypto.getCipherText());
96
+    }
97
+
98
+    @Test
99
+    public void normalizedCipherTextIsSplitByHeightOfSquare() {
100
+        Crypto crypto = new Crypto("Vampires are people too!");
101
+        String expectedOutput = "vrel aepe mset paoo irpo";
102
+
103
+        assertEquals(expectedOutput, crypto.getNormalizedCipherText());
104
+    }
105
+
106
+    @Test
107
+    public void normalizedCipherNotExactlyDivisibleBy5SpillsIntoSmallerSegment() {
108
+        Crypto crypto = new Crypto("Madness, and then illumination.");
109
+        String expectedOutput = "msemo aanin dninn dlaet ltshu i";
110
+
111
+        assertEquals(expectedOutput, crypto.getNormalizedCipherText());
112
+    }
113
+
114
+    @Test
115
+    public void normalizedCipherIsSplitIntoSegmentsOfCorrectSize() {
116
+        Crypto crypto = new Crypto("If man was meant to stay on the ground god would have given us roots");
117
+        String expectedOutput = "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghns seoau";
118
+
119
+        assertEquals(expectedOutput, crypto.getNormalizedCipherText());
120
+    }
121
+
122
+    @Test
123
+    public void normalizedCipherTextIsSplitIntoSegmentsOfCorrectSizeWithPunctuation() {
124
+        Crypto crypto = new Crypto("Have a nice day. Feed the dog & chill out!");
125
+        String expectedOutput = "hifei acedl veeol eddgo aatcu nyhht";
126
+
127
+        assertEquals(expectedOutput, crypto.getNormalizedCipherText());
128
+    }
129
+}

+ 32
- 25
space-age/example.java Целия файл

@@ -1,25 +1,32 @@
1
+import java.math.BigDecimal;
2
+
1 3
 public class SpaceAge {
2 4
 
3 5
     private enum Planet {
4
-        EARTH, MERCURY, VENUS, MARS, JUPITER, SATURN, URANUS, NEPTUNE
6
+        EARTH(1.0),
7
+        MERCURY(0.2408467),
8
+        VENUS(0.61519726),
9
+        MARS(1.8808158),
10
+        JUPITER(11.862615),
11
+        SATURN(29.447498),
12
+        URANUS(84.016846),
13
+        NEPTUNE(164.79132);
14
+
15
+        private final double relativeOrbitalPeriod;
16
+
17
+        Planet(double relativeOrbitalPeriod) {
18
+            this.relativeOrbitalPeriod = relativeOrbitalPeriod;
19
+        }
20
+
21
+        public double getRelativeOrbitalPeriod() {
22
+            return relativeOrbitalPeriod;
23
+        }
5 24
     }
6 25
 
7
-    private double seconds;
8
-
9 26
     private static final double EARTH_ORBITAL_PERIOD_IN_SECONDS = 31557600.0;
10 27
     private static final int PRECISION = 2;
11
-    private static final Map<Planet, Double> relativeOrbitalPeriods = new HashMap<>();
12
-
13
-    static {
14
-        relativeOrbitalPeriods.put(Planet.EARTH, 1.0);
15
-        relativeOrbitalPeriods.put(Planet.MERCURY, 0.2408467);
16
-        relativeOrbitalPeriods.put(Planet.VENUS, 0.61519726);
17
-        relativeOrbitalPeriods.put(Planet.MARS, 1.8808158);
18
-        relativeOrbitalPeriods.put(Planet.JUPITER, 11.862615);
19
-        relativeOrbitalPeriods.put(Planet.SATURN, 29.447498);
20
-        relativeOrbitalPeriods.put(Planet.URANUS, 84.016846);
21
-        relativeOrbitalPeriods.put(Planet.NEPTUNE, 164.79132);
22
-    }
28
+
29
+    private double seconds;
23 30
 
24 31
     public SpaceAge(double seconds) {
25 32
         this.seconds = seconds;
@@ -30,39 +37,39 @@ public class SpaceAge {
30 37
     }
31 38
 
32 39
     public double onEarth() {
33
-        return calculateAge(relativeOrbitalPeriods.get(Planet.EARTH));
40
+        return calculateAge(Planet.EARTH);
34 41
     }
35 42
 
36 43
     public double onMercury() {
37
-        return calculateAge(relativeOrbitalPeriods.get(Planet.MERCURY));
44
+        return calculateAge(Planet.MERCURY);
38 45
     }
39 46
 
40 47
     public double onVenus() {
41
-        return calculateAge(relativeOrbitalPeriods.get(Planet.VENUS));
48
+        return calculateAge(Planet.VENUS);
42 49
     }
43 50
 
44 51
     public double onMars() {
45
-        return calculateAge(relativeOrbitalPeriods.get(Planet.MARS));
52
+        return calculateAge(Planet.MARS);
46 53
     }
47 54
 
48 55
     public double onJupiter() {
49
-        return calculateAge(relativeOrbitalPeriods.get(Planet.JUPITER));
56
+        return calculateAge(Planet.JUPITER);
50 57
     }
51 58
 
52 59
     public double onSaturn() {
53
-        return calculateAge(relativeOrbitalPeriods.get(Planet.SATURN));
60
+        return calculateAge(Planet.SATURN);
54 61
     }
55 62
 
56 63
     public double onUranus() {
57
-        return calculateAge(relativeOrbitalPeriods.get(Planet.URANUS));
64
+        return calculateAge(Planet.URANUS);
58 65
     }
59 66
 
60 67
     public double onNeptune() {
61
-        return calculateAge(relativeOrbitalPeriods.get(Planet.NEPTUNE));
68
+        return calculateAge(Planet.NEPTUNE);
62 69
     }
63 70
 
64
-    private double calculateAge(double relativeOrbitalPeriod) {
65
-        double age = seconds / (EARTH_ORBITAL_PERIOD_IN_SECONDS * relativeOrbitalPeriod);
71
+    private double calculateAge(Planet planet) {
72
+        double age = seconds / (EARTH_ORBITAL_PERIOD_IN_SECONDS * planet.getRelativeOrbitalPeriod());
66 73
 
67 74
         return new BigDecimal(age).setScale(PRECISION, BigDecimal.ROUND_HALF_UP).doubleValue();
68 75
     }

+ 19
- 9
strain/example.java Целия файл

@@ -1,16 +1,26 @@
1
-import java.util.Collection;
1
+import java.util.ArrayList;
2
+import java.util.List;
2 3
 import java.util.function.Predicate;
3
-import java.util.stream.Collectors;
4 4
 
5 5
 public class Strain {
6 6
 
7
-	public static <T> Collection<T> keep(Collection<T> coll, Predicate<T> func)
8
-	{
9
-		return coll.stream().filter(func).collect(Collectors.toList());
7
+	public static <T> List<T> keep(List<T> collection, Predicate<T> predicate) {
8
+		return filter(collection, predicate);
10 9
 	}
11
-	
12
-	public static <T> Collection<T> discard(Collection<T> coll, Predicate<T> func)
13
-	{
14
-		return coll.stream().filter(func.negate()).collect(Collectors.toList());
10
+
11
+	public static <T> List<T> discard(List<T> collection, Predicate<T> predicate) {
12
+		return filter(collection, predicate.negate());
13
+	}
14
+
15
+	public static <T> List<T> filter(List<T> collection, Predicate<T> predicate) {
16
+		List<T> filteredCollection = new ArrayList<>();
17
+
18
+		for (T item : collection) {
19
+			if (predicate.test(item)) {
20
+				filteredCollection.add(item);
21
+			}
22
+		}
23
+
24
+		return filteredCollection;
15 25
 	}
16 26
 }

strain/src/main/java/example.java → strain/src/main/java/Strain.java Целия файл


+ 113
- 115
strain/src/test/java/StrainTest.java Целия файл

@@ -1,123 +1,121 @@
1
-package strain;
1
+import org.junit.Assert;
2
+import org.junit.Test;
2 3
 
3 4
 import java.util.Arrays;
4 5
 import java.util.LinkedList;
5 6
 import java.util.List;
6 7
 
7
-import org.junit.Assert;
8
-import org.junit.Test;
9
-
10 8
 public class StrainTest {
11 9
 
12
-	@Test
13
-	public void emptyKeep() {
14
-		List<Integer> expected = new LinkedList<>();
15
-		List<Integer> test = new LinkedList<>();
16
-		Assert.assertEquals(expected, Strain.keep(test, x -> x < 10));
17
-	}
18
-
19
-	@Test
20
-	public void keepEverything() {
21
-		List<Integer> expected = Arrays.asList(1, 2, 3);
22
-		List<Integer> test = Arrays.asList(1, 2, 3);
23
-		Assert.assertEquals(expected, Strain.keep(test, x -> x < 10));
24
-	}
25
-
26
-	@Test
27
-	public void keepFirstAndLast() {
28
-		List<Integer> expected = Arrays.asList(1, 3);
29
-		List<Integer> test = Arrays.asList(1, 2, 3);
30
-		Assert.assertEquals(expected, Strain.keep(test, x -> x % 2 != 0));
31
-	}
32
-
33
-	@Test
34
-	public void keepNeitherFirstNorLast() {
35
-		List<Integer> expected = Arrays.asList(2, 4);
36
-		List<Integer> test = Arrays.asList(1, 2, 3, 4, 5);
37
-		Assert.assertEquals(expected, Strain.keep(test, x -> x % 2 == 0));
38
-	}
39
-
40
-	@Test
41
-	public void KeepStrings() {
42
-		List<String> words = Arrays
43
-				.asList("apple zebra banana zombies cherimoya zelot".split(" "));
44
-		List<String> expected = Arrays.asList("zebra", "zombies", "zelot");
45
-		Assert.assertEquals(expected,
46
-				Strain.keep(words, x -> x.startsWith("z")));
47
-	}
48
-
49
-	@Test
50
-	public void KeepArrays() {
51
-		List<List<Integer>> actual = Arrays.asList(
52
-				Arrays.asList(1, 2, 3),
53
-				Arrays.asList(5, 5, 5), 
54
-				Arrays.asList(5, 1, 2),
55
-				Arrays.asList(2, 1, 2), 
56
-				Arrays.asList(1, 5, 2),
57
-				Arrays.asList(2, 2, 1), 
58
-				Arrays.asList(1, 2, 5));
59
-		List<List<Integer>> expected = Arrays.asList(
60
-				Arrays.asList(5, 5, 5),
61
-				Arrays.asList(5, 1, 2), 
62
-				Arrays.asList(1, 5, 2),
63
-				Arrays.asList(1, 2, 5));
64
-		Assert.assertEquals(expected,
65
-				Strain.keep(actual, col -> col.contains(5)));
66
-	}
67
-
68
-	@Test
69
-	public void emptyDiscard() {
70
-		List<Integer> expected = new LinkedList<>();
71
-		List<Integer> test = new LinkedList<>();
72
-		Assert.assertEquals(expected, Strain.discard(test, x -> x < 10));
73
-	}
74
-
75
-	@Test
76
-	public void discardNothing() {
77
-		List<Integer> expected = Arrays.asList(1, 2, 3);
78
-		List<Integer> test = Arrays.asList(1, 2, 3);
79
-		Assert.assertEquals(expected, Strain.discard(test, x -> x > 10));
80
-	}
81
-
82
-	@Test
83
-	public void discardFirstAndLast() {
84
-		List<Integer> expected = Arrays.asList(2);
85
-		List<Integer> test = Arrays.asList(1, 2, 3);
86
-		Assert.assertEquals(expected, Strain.discard(test, x -> x % 2 != 0));
87
-
88
-	}
89
-
90
-	@Test
91
-	public void discardNeitherFirstNorLast() {
92
-		List<Integer> expected = Arrays.asList(1, 3, 5);
93
-		List<Integer> test = Arrays.asList(1, 2, 3, 4, 5);
94
-		Assert.assertEquals(expected, Strain.discard(test, x -> x % 2 == 0));
95
-	}
96
-
97
-	@Test
98
-	public void discardStrings() {
99
-		List<String> words = Arrays
100
-				.asList("apple zebra banana zombies cherimoya zelot".split(" "));
101
-		List<String> expected = Arrays.asList("apple", "banana", "cherimoya");
102
-		Assert.assertEquals(expected,
103
-				Strain.discard(words, x -> x.startsWith("z")));
104
-	}
105
-
106
-	@Test
107
-	public void discardArrays() {
108
-		List<List<Integer>> actual = Arrays.asList(
109
-				Arrays.asList(1, 2, 3),
110
-				Arrays.asList(5, 5, 5),
111
-				Arrays.asList(5, 1, 2),
112
-				Arrays.asList(2, 1, 2),
113
-				Arrays.asList(1, 5, 2),
114
-				Arrays.asList(2, 2, 1),
115
-				Arrays.asList(1, 2, 5));
116
-		List<List<Integer>> expected = Arrays.asList(
117
-				Arrays.asList(1, 2, 3),
118
-				Arrays.asList(2, 1, 2),
119
-				Arrays.asList(2, 2, 1));
120
-		Assert.assertEquals(expected,
121
-				Strain.discard(actual, col -> col.contains(5)));
122
-	}
10
+    @Test
11
+    public void emptyKeep() {
12
+        List<Integer> input = new LinkedList<>();
13
+        List<Integer> expectedOutput = new LinkedList<>();
14
+        Assert.assertEquals(expectedOutput, Strain.keep(input, x -> x < 10));
15
+    }
16
+
17
+    @Test
18
+    public void keepEverything() {
19
+        List<Integer> input = Arrays.asList(1, 2, 3);
20
+        List<Integer> expectedOutput = Arrays.asList(1, 2, 3);
21
+        Assert.assertEquals(expectedOutput, Strain.keep(input, x -> x < 10));
22
+    }
23
+
24
+    @Test
25
+    public void keepFirstAndLast() {
26
+        List<Integer> input = Arrays.asList(1, 2, 3);
27
+        List<Integer> expectedOutput = Arrays.asList(1, 3);
28
+        Assert.assertEquals(expectedOutput, Strain.keep(input, x -> x % 2 != 0));
29
+    }
30
+
31
+    @Test
32
+    public void keepNeitherFirstNorLast() {
33
+        List<Integer> input = Arrays.asList(1, 2, 3, 4, 5);
34
+        List<Integer> expectedOutput = Arrays.asList(2, 4);
35
+        Assert.assertEquals(expectedOutput, Strain.keep(input, x -> x % 2 == 0));
36
+    }
37
+
38
+    @Test
39
+    public void KeepStrings() {
40
+        List<String> words = Arrays
41
+                .asList("apple zebra banana zombies cherimoya zelot".split(" "));
42
+        List<String> expectedOutput = Arrays.asList("zebra", "zombies", "zelot");
43
+        Assert.assertEquals(expectedOutput,
44
+                Strain.keep(words, x -> x.startsWith("z")));
45
+    }
46
+
47
+    @Test
48
+    public void KeepArrays() {
49
+        List<List<Integer>> actual = Arrays.asList(
50
+                Arrays.asList(1, 2, 3),
51
+                Arrays.asList(5, 5, 5),
52
+                Arrays.asList(5, 1, 2),
53
+                Arrays.asList(2, 1, 2),
54
+                Arrays.asList(1, 5, 2),
55
+                Arrays.asList(2, 2, 1),
56
+                Arrays.asList(1, 2, 5));
57
+        List<List<Integer>> expectedOutput = Arrays.asList(
58
+                Arrays.asList(5, 5, 5),
59
+                Arrays.asList(5, 1, 2),
60
+                Arrays.asList(1, 5, 2),
61
+                Arrays.asList(1, 2, 5));
62
+        Assert.assertEquals(expectedOutput,
63
+                Strain.keep(actual, col -> col.contains(5)));
64
+    }
65
+
66
+    @Test
67
+    public void emptyDiscard() {
68
+        List<Integer> input = new LinkedList<>();
69
+        List<Integer> expectedOutput = new LinkedList<>();
70
+        Assert.assertEquals(expectedOutput, Strain.discard(input, x -> x < 10));
71
+    }
72
+
73
+    @Test
74
+    public void discardNothing() {
75
+        List<Integer> input = Arrays.asList(1, 2, 3);
76
+        List<Integer> expectedOutput = Arrays.asList(1, 2, 3);
77
+        Assert.assertEquals(expectedOutput, Strain.discard(input, x -> x > 10));
78
+    }
79
+
80
+    @Test
81
+    public void discardFirstAndLast() {
82
+        List<Integer> input = Arrays.asList(1, 2, 3);
83
+        List<Integer> expectedOutput = Arrays.asList(2);
84
+        Assert.assertEquals(expectedOutput, Strain.discard(input, x -> x % 2 != 0));
85
+
86
+    }
87
+
88
+    @Test
89
+    public void discardNeitherFirstNorLast() {
90
+        List<Integer> input = Arrays.asList(1, 2, 3, 4, 5);
91
+        List<Integer> expectedOutput = Arrays.asList(1, 3, 5);
92
+        Assert.assertEquals(expectedOutput, Strain.discard(input, x -> x % 2 == 0));
93
+    }
94
+
95
+    @Test
96
+    public void discardStrings() {
97
+        List<String> words = Arrays
98
+                .asList("apple zebra banana zombies cherimoya zelot".split(" "));
99
+        List<String> expectedOutput = Arrays.asList("apple", "banana", "cherimoya");
100
+        Assert.assertEquals(expectedOutput,
101
+                Strain.discard(words, x -> x.startsWith("z")));
102
+    }
103
+
104
+    @Test
105
+    public void discardArrays() {
106
+        List<List<Integer>> actual = Arrays.asList(
107
+                Arrays.asList(1, 2, 3),
108
+                Arrays.asList(5, 5, 5),
109
+                Arrays.asList(5, 1, 2),
110
+                Arrays.asList(2, 1, 2),
111
+                Arrays.asList(1, 5, 2),
112
+                Arrays.asList(2, 2, 1),
113
+                Arrays.asList(1, 2, 5));
114
+        List<List<Integer>> expectedOutput = Arrays.asList(
115
+                Arrays.asList(1, 2, 3),
116
+                Arrays.asList(2, 1, 2),
117
+                Arrays.asList(2, 2, 1));
118
+        Assert.assertEquals(expectedOutput,
119
+                Strain.discard(actual, col -> col.contains(5)));
120
+    }
123 121
 }