trackler 2.2.1.137 → 2.2.1.138
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/problem-specifications/exercises/diffie-hellman/canonical-data.json +72 -0
- data/problem-specifications/exercises/yacht/description.md +2 -2
- data/tracks/csharp/exercises/sgf-parsing/Example.cs +1 -1
- data/tracks/csharp/exercises/sgf-parsing/SgfParsingTest.cs +1 -1
- data/tracks/csharp/exercises/sublist/SublistTest.cs +37 -78
- data/tracks/csharp/generators/Exercises/Sublist.cs +32 -0
- data/tracks/elisp/exercises/bob/README.md +2 -0
- data/tracks/elisp/exercises/bob/bob-test.el +60 -15
- data/tracks/elisp/exercises/bob/example.el +15 -5
- data/tracks/elisp/exercises/hamming/hamming-test.el +1 -1
- data/tracks/fsharp/build.ps1 +3 -3
- data/tracks/fsharp/build.sh +3 -3
- data/tracks/fsharp/exercises/bracket-push/BracketPushTest.fs +5 -1
- data/tracks/fsharp/exercises/isbn-verifier/IsbnVerifierTest.fs +5 -1
- data/tracks/fsharp/exercises/kindergarten-garden/KindergartenGardenTest.fs +1 -1
- data/tracks/fsharp/exercises/pov/PovTest.fs +6 -1
- data/tracks/fsharp/exercises/react/Example.fs +2 -2
- data/tracks/fsharp/exercises/react/React.fsproj +1 -0
- data/tracks/fsharp/exercises/react/ReactTest.fs +55 -33
- data/tracks/fsharp/exercises/series/Example.fs +2 -12
- data/tracks/fsharp/exercises/series/SeriesTest.fs +33 -56
- data/tracks/fsharp/generators/Generators.fs +81 -46
- data/tracks/idris/exercises/rna-transcription/src/{example.idr → Example.idr} +0 -0
- data/tracks/java/config.json +14 -0
- data/tracks/java/exercises/acronym/src/test/java/AcronymTest.java +10 -10
- data/tracks/java/exercises/all-your-base/src/test/java/BaseConverterTest.java +39 -39
- data/tracks/java/exercises/grep/.meta/hints.md +58 -0
- data/tracks/java/exercises/grep/.meta/src/reference/java/GrepTool.java +65 -0
- data/tracks/java/exercises/grep/.meta/version +1 -0
- data/tracks/java/exercises/grep/README.md +145 -0
- data/tracks/java/exercises/grep/build.gradle +18 -0
- data/tracks/java/exercises/grep/src/main/java/.keep +0 -0
- data/tracks/java/exercises/grep/src/test/java/GrepToolTest.java +395 -0
- data/tracks/java/exercises/largest-series-product/src/test/java/LargestSeriesProductCalculatorTest.java +36 -36
- data/tracks/java/exercises/minesweeper/src/test/java/MinesweeperBoardTest.java +36 -36
- data/tracks/java/exercises/phone-number/src/test/java/PhoneNumberTest.java +14 -14
- data/tracks/java/exercises/poker/src/test/java/PokerTest.java +40 -40
- data/tracks/java/exercises/pythagorean-triplet/src/test/java/PythagoreanTripletTest.java +10 -10
- data/tracks/java/exercises/settings.gradle +1 -0
- data/tracks/ocaml/exercises/anagram/example.ml +1 -1
- data/tracks/ocaml/exercises/change/example.ml +1 -1
- data/tracks/ocaml/exercises/custom-set/example.ml +4 -3
- data/tracks/ocaml/exercises/custom-set/test.ml +0 -1
- data/tracks/ocaml/exercises/dominoes/test.ml +1 -1
- data/tracks/ocaml/exercises/etl/example.ml +1 -1
- data/tracks/ocaml/exercises/grade-school/example.ml +1 -1
- data/tracks/ocaml/exercises/palindrome-products/example.ml +2 -2
- data/tracks/ocaml/exercises/prime-factors/example.ml +1 -1
- data/tracks/ocaml/exercises/robot-name/test.ml +1 -1
- data/tracks/ocaml/exercises/triangle/example.ml +1 -1
- data/tracks/ocaml/make-exercise.sh +1 -0
- data/tracks/ocaml/tools/test-generator/src/controller.ml +1 -1
- data/tracks/perl5/exercises/raindrops/.meta/solutions/Raindrops.pm +13 -12
- data/tracks/perl5/exercises/raindrops/raindrops.t +166 -111
- data/tracks/perl6/docs/INSTALLATION.md +1 -3
- data/tracks/perl6/exercises/raindrops/.meta/exercise-data.yaml +5 -5
- data/tracks/perl6/exercises/raindrops/.meta/solutions/Raindrops.pm6 +2 -2
- data/tracks/perl6/exercises/raindrops/Raindrops.pm6 +2 -2
- data/tracks/perl6/exercises/raindrops/raindrops.t +3 -3
- data/tracks/python/exercises/food-chain/example.py +11 -2
- data/tracks/python/exercises/food-chain/food_chain_test.py +48 -45
- data/tracks/python/exercises/pov/pov_test.py +12 -1
- data/tracks/python/exercises/series/README.md +6 -6
- data/tracks/python/exercises/series/example.py +2 -3
- data/tracks/python/exercises/series/series_test.py +27 -28
- data/tracks/python/exercises/sgf-parsing/example.py +1 -1
- data/tracks/python/exercises/sgf-parsing/sgf_parsing_test.py +1 -1
- data/tracks/python/exercises/yacht/README.md +2 -2
- data/tracks/ruby/Gemfile +0 -1
- data/tracks/ruby/README.md +23 -0
- data/tracks/ruby/bin/generate +1 -0
- data/tracks/ruby/exercises/complex-numbers/complex_numbers_test.rb +1 -1
- data/tracks/ruby/lib/generator.rb +1 -2
- data/tracks/ruby/lib/generator/command_line.rb +3 -0
- data/tracks/ruby/lib/generator/command_line/generator_optparser.rb +1 -0
- data/tracks/ruby/lib/generator/exercise.rb +2 -0
- data/tracks/ruby/lib/generator/exercise_case.rb +3 -0
- data/tracks/ruby/lib/generator/files.rb +1 -0
- data/tracks/ruby/lib/generator/files/metadata_files.rb +2 -0
- data/tracks/ruby/lib/generator/files/track_files.rb +1 -0
- data/tracks/ruby/lib/generator/implementation.rb +1 -0
- data/tracks/ruby/lib/generator/repository.rb +3 -0
- data/tracks/ruby/lib/generator/template_values.rb +1 -0
- data/tracks/ruby/test/generator/case_values_test.rb +2 -0
- data/tracks/ruby/test/generator/command_line_test.rb +1 -0
- data/tracks/ruby/test/generator/files/metadata_files_test.rb +2 -0
- data/tracks/ruby/test/generator/files/track_files_test.rb +1 -0
- data/tracks/ruby/test/generator/implementation_test.rb +1 -0
- data/tracks/ruby/test/tasks/exercise_test.rb +1 -0
- data/tracks/ruby/test/tasks/exercise_test_tasks_test.rb +2 -0
- data/tracks/ruby/test/test_helper.rb +1 -3
- data/tracks/rust/config.json +12 -0
- data/tracks/rust/exercises/atbash-cipher/src/lib.rs +9 -0
- data/tracks/rust/exercises/hamming/src/lib.rs +6 -0
- data/tracks/rust/exercises/isogram/src/lib.rs +3 -0
- data/tracks/rust/exercises/luhn/src/lib.rs +4 -0
- data/tracks/rust/exercises/palindrome-products/.meta/test-in-release-mode +1 -0
- data/tracks/rust/exercises/palindrome-products/Cargo.toml +6 -0
- data/tracks/rust/exercises/palindrome-products/README.md +72 -0
- data/tracks/rust/exercises/palindrome-products/example.rs +25 -0
- data/tracks/rust/exercises/palindrome-products/src/lib.rs +22 -0
- data/tracks/rust/exercises/palindrome-products/tests/palindrome-products.rs +57 -0
- data/tracks/rust/exercises/pangram/src/lib.rs +4 -0
- data/tracks/rust/exercises/run-length-encoding/src/lib.rs +7 -0
- data/tracks/rust/exercises/say/src/lib.rs +3 -4
- data/tracks/rust/exercises/scrabble-score/src/lib.rs +4 -0
- data/tracks/rust/exercises/word-count/src/lib.rs +6 -0
- data/tracks/scheme/exercises/hello-world/example.scm +1 -4
- data/tracks/scheme/exercises/hello-world/hello-world-test.scm +1 -5
- data/tracks/scheme/exercises/scrabble-score/scrabble-score-test.scm +2 -2
- data/tracks/typescript/config.json +30 -0
- data/tracks/typescript/exercises/queen-attack/README.md +59 -0
- data/tracks/typescript/exercises/queen-attack/package.json +36 -0
- data/tracks/typescript/exercises/queen-attack/queen-attack.example.ts +56 -0
- data/tracks/typescript/exercises/queen-attack/queen-attack.test.ts +71 -0
- data/tracks/typescript/exercises/queen-attack/queen-attack.ts +0 -0
- data/tracks/typescript/exercises/queen-attack/tsconfig.json +22 -0
- data/tracks/typescript/exercises/queen-attack/tslint.json +127 -0
- data/tracks/typescript/exercises/queen-attack/yarn.lock +2624 -0
- data/tracks/typescript/exercises/spiral-matrix/README.md +56 -0
- data/tracks/typescript/exercises/spiral-matrix/package.json +36 -0
- data/tracks/typescript/exercises/spiral-matrix/spiral-matrix.example.ts +33 -0
- data/tracks/typescript/exercises/spiral-matrix/spiral-matrix.test.ts +49 -0
- data/tracks/typescript/exercises/spiral-matrix/spiral-matrix.ts +0 -0
- data/tracks/typescript/exercises/spiral-matrix/tsconfig.json +22 -0
- data/tracks/typescript/exercises/spiral-matrix/tslint.json +127 -0
- data/tracks/typescript/exercises/spiral-matrix/yarn.lock +2624 -0
- metadata +35 -3
@@ -0,0 +1,18 @@
|
|
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.12"
|
11
|
+
}
|
12
|
+
|
13
|
+
test {
|
14
|
+
testLogging {
|
15
|
+
exceptionFormat = 'full'
|
16
|
+
events = ["passed", "failed", "skipped"]
|
17
|
+
}
|
18
|
+
}
|
File without changes
|
@@ -0,0 +1,395 @@
|
|
1
|
+
import org.junit.After;
|
2
|
+
import org.junit.Before;
|
3
|
+
import org.junit.Ignore;
|
4
|
+
import org.junit.Test;
|
5
|
+
|
6
|
+
import java.io.IOException;
|
7
|
+
import java.nio.charset.Charset;
|
8
|
+
import java.nio.file.Files;
|
9
|
+
import java.nio.file.Path;
|
10
|
+
import java.nio.file.Paths;
|
11
|
+
import java.util.Arrays;
|
12
|
+
import java.util.Collections;
|
13
|
+
import java.util.List;
|
14
|
+
|
15
|
+
import static org.junit.Assert.assertEquals;
|
16
|
+
|
17
|
+
public class GrepToolTest {
|
18
|
+
private GrepTool grepTool;
|
19
|
+
|
20
|
+
@Before
|
21
|
+
public void setUp() throws IOException {
|
22
|
+
List<String> iliadText = Arrays.asList(
|
23
|
+
"Achilles sing, O Goddess! Peleus' son;",
|
24
|
+
"His wrath pernicious, who ten thousand woes",
|
25
|
+
"Caused to Achaia's host, sent many a soul",
|
26
|
+
"Illustrious into Ades premature,",
|
27
|
+
"And Heroes gave (so stood the will of Jove)",
|
28
|
+
"To dogs and to all ravening fowls a prey,",
|
29
|
+
"When fierce dispute had separated once",
|
30
|
+
"The noble Chief Achilles from the son",
|
31
|
+
"Of Atreus, Agamemnon, King of men."
|
32
|
+
);
|
33
|
+
writeToFile("iliad.txt", iliadText);
|
34
|
+
|
35
|
+
List<String> midsummerNightText = Arrays.asList(
|
36
|
+
"I do entreat your grace to pardon me.",
|
37
|
+
"I know not by what power I am made bold,",
|
38
|
+
"Nor how it may concern my modesty,",
|
39
|
+
"In such a presence here to plead my thoughts;",
|
40
|
+
"But I beseech your grace that I may know",
|
41
|
+
"The worst that may befall me in this case,",
|
42
|
+
"If I refuse to wed Demetrius."
|
43
|
+
);
|
44
|
+
writeToFile("midsummer-night.txt", midsummerNightText);
|
45
|
+
|
46
|
+
List<String> paradiseLostText = Arrays.asList(
|
47
|
+
"Of Mans First Disobedience, and the Fruit",
|
48
|
+
"Of that Forbidden Tree, whose mortal tast",
|
49
|
+
"Brought Death into the World, and all our woe,",
|
50
|
+
"With loss of Eden, till one greater Man",
|
51
|
+
"Restore us, and regain the blissful Seat,",
|
52
|
+
"Sing Heav'nly Muse, that on the secret top",
|
53
|
+
"Of Oreb, or of Sinai, didst inspire",
|
54
|
+
"That Shepherd, who first taught the chosen Seed"
|
55
|
+
);
|
56
|
+
writeToFile("paradise-lost.txt", paradiseLostText);
|
57
|
+
|
58
|
+
grepTool = new GrepTool();
|
59
|
+
}
|
60
|
+
|
61
|
+
@After
|
62
|
+
public void tearDown() throws IOException {
|
63
|
+
deleteFile("iliad.txt");
|
64
|
+
deleteFile("midsummer-night.txt");
|
65
|
+
deleteFile("paradise-lost.txt");
|
66
|
+
}
|
67
|
+
|
68
|
+
@Test
|
69
|
+
public void oneFileOneMatchNoFlags() {
|
70
|
+
String expected = "Of Atreus, Agamemnon, King of men.";
|
71
|
+
|
72
|
+
String actual = grepTool.grep(
|
73
|
+
"Agamemnon",
|
74
|
+
Collections.emptyList(),
|
75
|
+
Collections.singletonList("iliad.txt")
|
76
|
+
);
|
77
|
+
|
78
|
+
assertEquals(expected, actual);
|
79
|
+
}
|
80
|
+
|
81
|
+
@Ignore("Remove to run test")
|
82
|
+
@Test
|
83
|
+
public void oneFileOneMatchPrintLineNumbersFlag() {
|
84
|
+
String expected = "2:Of that Forbidden Tree, whose mortal tast";
|
85
|
+
|
86
|
+
String actual = grepTool.grep(
|
87
|
+
"Forbidden",
|
88
|
+
Collections.singletonList("-n"),
|
89
|
+
Collections.singletonList("paradise-lost.txt")
|
90
|
+
);
|
91
|
+
|
92
|
+
assertEquals(expected, actual);
|
93
|
+
}
|
94
|
+
|
95
|
+
@Ignore("Remove to run test")
|
96
|
+
@Test
|
97
|
+
public void oneFileOneMatchCaseInsensitiveFlag() {
|
98
|
+
String expected = "Of that Forbidden Tree, whose mortal tast";
|
99
|
+
|
100
|
+
String actual = grepTool.grep(
|
101
|
+
"FORBIDDEN",
|
102
|
+
Collections.singletonList("-i"),
|
103
|
+
Collections.singletonList("paradise-lost.txt")
|
104
|
+
);
|
105
|
+
|
106
|
+
assertEquals(expected, actual);
|
107
|
+
}
|
108
|
+
|
109
|
+
@Ignore("Remove to run test")
|
110
|
+
@Test
|
111
|
+
public void oneFileOneMatchPrintFileNamesFlag() {
|
112
|
+
String expected = "paradise-lost.txt";
|
113
|
+
|
114
|
+
String actual = grepTool.grep(
|
115
|
+
"Forbidden",
|
116
|
+
Collections.singletonList("-l"),
|
117
|
+
Collections.singletonList("paradise-lost.txt")
|
118
|
+
);
|
119
|
+
|
120
|
+
assertEquals(expected, actual);
|
121
|
+
}
|
122
|
+
|
123
|
+
@Ignore("Remove to run test")
|
124
|
+
@Test
|
125
|
+
public void oneFileOneMatchEntireLinesFlag() {
|
126
|
+
String expected = "With loss of Eden, till one greater Man";
|
127
|
+
|
128
|
+
String actual = grepTool.grep(
|
129
|
+
"With loss of Eden, till one greater Man",
|
130
|
+
Collections.singletonList("-x"),
|
131
|
+
Collections.singletonList("paradise-lost.txt")
|
132
|
+
);
|
133
|
+
|
134
|
+
assertEquals(expected, actual);
|
135
|
+
}
|
136
|
+
|
137
|
+
@Ignore("Remove to run test")
|
138
|
+
@Test
|
139
|
+
public void oneFileOneMatchMultipleFlags() {
|
140
|
+
String expected = "9:Of Atreus, Agamemnon, King of men.";
|
141
|
+
|
142
|
+
String actual = grepTool.grep(
|
143
|
+
"OF ATREUS, Agamemnon, KIng of MEN.",
|
144
|
+
Arrays.asList("-n", "-i", "-x"),
|
145
|
+
Collections.singletonList("iliad.txt")
|
146
|
+
);
|
147
|
+
|
148
|
+
assertEquals(expected, actual);
|
149
|
+
}
|
150
|
+
|
151
|
+
@Ignore("Remove to run test")
|
152
|
+
@Test
|
153
|
+
public void oneFileSeveralMatchesNoFlags() {
|
154
|
+
String expected = "Nor how it may concern my modesty,\n"
|
155
|
+
+ "But I beseech your grace that I may know\n"
|
156
|
+
+ "The worst that may befall me in this case,";
|
157
|
+
|
158
|
+
String actual = grepTool.grep(
|
159
|
+
"may",
|
160
|
+
Collections.emptyList(),
|
161
|
+
Collections.singletonList("midsummer-night.txt")
|
162
|
+
);
|
163
|
+
|
164
|
+
assertEquals(expected, actual);
|
165
|
+
}
|
166
|
+
|
167
|
+
@Ignore("Remove to run test")
|
168
|
+
@Test
|
169
|
+
public void oneFileSeveralMatchesPrintLineNumbersFlag() {
|
170
|
+
String expected = "3:Nor how it may concern my modesty,\n"
|
171
|
+
+ "5:But I beseech your grace that I may know\n"
|
172
|
+
+ "6:The worst that may befall me in this case,";
|
173
|
+
|
174
|
+
String actual = grepTool.grep(
|
175
|
+
"may",
|
176
|
+
Collections.singletonList("-n"),
|
177
|
+
Collections.singletonList("midsummer-night.txt")
|
178
|
+
);
|
179
|
+
|
180
|
+
assertEquals(expected, actual);
|
181
|
+
}
|
182
|
+
|
183
|
+
@Ignore("Remove to run test")
|
184
|
+
@Test
|
185
|
+
public void oneFileSeveralMatchesMatchEntireLineFlag() {
|
186
|
+
String expected = "";
|
187
|
+
|
188
|
+
String actual = grepTool.grep(
|
189
|
+
"may",
|
190
|
+
Collections.singletonList("-x"),
|
191
|
+
Collections.singletonList("midsummer-night.txt")
|
192
|
+
);
|
193
|
+
|
194
|
+
assertEquals(expected, actual);
|
195
|
+
}
|
196
|
+
|
197
|
+
@Ignore("Remove to run test")
|
198
|
+
@Test
|
199
|
+
public void oneFileSeveralMatchesCaseInsensitiveFlag() {
|
200
|
+
String expected = "Achilles sing, O Goddess! Peleus' son;\n"
|
201
|
+
+ "The noble Chief Achilles from the son";
|
202
|
+
|
203
|
+
String actual = grepTool.grep(
|
204
|
+
"ACHILLES",
|
205
|
+
Collections.singletonList("-i"),
|
206
|
+
Collections.singletonList("iliad.txt")
|
207
|
+
);
|
208
|
+
|
209
|
+
assertEquals(expected, actual);
|
210
|
+
}
|
211
|
+
|
212
|
+
@Ignore("Remove to run test")
|
213
|
+
@Test
|
214
|
+
public void oneFileSeveralMatchesInvertedFlag() {
|
215
|
+
String expected = "Brought Death into the World, and all our woe,\n"
|
216
|
+
+ "With loss of Eden, till one greater Man\n"
|
217
|
+
+ "Restore us, and regain the blissful Seat,\n"
|
218
|
+
+ "Sing Heav'nly Muse, that on the secret top\n"
|
219
|
+
+ "That Shepherd, who first taught the chosen Seed";
|
220
|
+
|
221
|
+
String actual = grepTool.grep(
|
222
|
+
"Of",
|
223
|
+
Collections.singletonList("-v"),
|
224
|
+
Collections.singletonList("paradise-lost.txt")
|
225
|
+
);
|
226
|
+
|
227
|
+
assertEquals(expected, actual);
|
228
|
+
}
|
229
|
+
|
230
|
+
@Ignore("Remove to run test")
|
231
|
+
@Test
|
232
|
+
public void oneFileNoMatchesVariousFlags() {
|
233
|
+
String expected = "";
|
234
|
+
|
235
|
+
String actual = grepTool.grep(
|
236
|
+
"Gandalf",
|
237
|
+
Arrays.asList("-n", "-l", "-x", "-i"),
|
238
|
+
Collections.singletonList("iliad.txt")
|
239
|
+
);
|
240
|
+
|
241
|
+
assertEquals(expected, actual);
|
242
|
+
}
|
243
|
+
|
244
|
+
@Ignore("Remove to run test")
|
245
|
+
@Test
|
246
|
+
public void multipleFilesOneMatchNoFlags() {
|
247
|
+
String expected = "iliad.txt:Of Atreus, Agamemnon, King of men.";
|
248
|
+
|
249
|
+
String actual = grepTool.grep(
|
250
|
+
"Agamemnon",
|
251
|
+
Collections.emptyList(),
|
252
|
+
Arrays.asList("iliad.txt", "midsummer-night.txt", "paradise-lost.txt")
|
253
|
+
);
|
254
|
+
|
255
|
+
assertEquals(expected, actual);
|
256
|
+
}
|
257
|
+
|
258
|
+
@Ignore("Remove to run test")
|
259
|
+
@Test
|
260
|
+
public void multipleFilesSeveralMatchesNoFlags() {
|
261
|
+
String expected = "midsummer-night.txt:Nor how it may concern my modesty,\n"
|
262
|
+
+ "midsummer-night.txt:But I beseech your grace that I may know\n"
|
263
|
+
+ "midsummer-night.txt:The worst that may befall me in this case,";
|
264
|
+
|
265
|
+
String actual = grepTool.grep(
|
266
|
+
"may",
|
267
|
+
Collections.emptyList(),
|
268
|
+
Arrays.asList("iliad.txt", "midsummer-night.txt", "paradise-lost.txt")
|
269
|
+
);
|
270
|
+
|
271
|
+
assertEquals(expected, actual);
|
272
|
+
}
|
273
|
+
|
274
|
+
@Ignore("Remove to run test")
|
275
|
+
@Test
|
276
|
+
public void multipleFilesSeveralMatchesPrintLineNumbersFlag() {
|
277
|
+
String expected = "midsummer-night.txt:5:But I beseech your grace that I may know\n"
|
278
|
+
+ "midsummer-night.txt:6:The worst that may befall me in this case,\n"
|
279
|
+
+ "paradise-lost.txt:2:Of that Forbidden Tree, whose mortal tast\n"
|
280
|
+
+ "paradise-lost.txt:6:Sing Heav'nly Muse, that on the secret top";
|
281
|
+
|
282
|
+
String actual = grepTool.grep(
|
283
|
+
"that",
|
284
|
+
Collections.singletonList("-n"),
|
285
|
+
Arrays.asList("iliad.txt", "midsummer-night.txt", "paradise-lost.txt")
|
286
|
+
);
|
287
|
+
|
288
|
+
assertEquals(expected, actual);
|
289
|
+
}
|
290
|
+
|
291
|
+
@Ignore("Remove to run test")
|
292
|
+
@Test
|
293
|
+
public void multipleFilesOneMatchPrintFileNamesFlag() {
|
294
|
+
String expected = "iliad.txt\n"
|
295
|
+
+ "paradise-lost.txt";
|
296
|
+
|
297
|
+
String actual = grepTool.grep(
|
298
|
+
"who",
|
299
|
+
Collections.singletonList("-l"),
|
300
|
+
Arrays.asList("iliad.txt", "midsummer-night.txt", "paradise-lost.txt")
|
301
|
+
);
|
302
|
+
|
303
|
+
assertEquals(expected, actual);
|
304
|
+
}
|
305
|
+
|
306
|
+
@Ignore("Remove to run test")
|
307
|
+
@Test
|
308
|
+
public void multipleFilesSeveralMatchesCaseInsensitiveFlag() {
|
309
|
+
String expected = "iliad.txt:Caused to Achaia's host, sent many a soul\n"
|
310
|
+
+ "iliad.txt:Illustrious into Ades premature,\n"
|
311
|
+
+ "iliad.txt:And Heroes gave (so stood the will of Jove)\n"
|
312
|
+
+ "iliad.txt:To dogs and to all ravening fowls a prey,\n"
|
313
|
+
+ "midsummer-night.txt:I do entreat your grace to pardon me.\n"
|
314
|
+
+ "midsummer-night.txt:In such a presence here to plead my thoughts;\n"
|
315
|
+
+ "midsummer-night.txt:If I refuse to wed Demetrius.\n"
|
316
|
+
+ "paradise-lost.txt:Brought Death into the World, and all our woe,\n"
|
317
|
+
+ "paradise-lost.txt:Restore us, and regain the blissful Seat,\n"
|
318
|
+
+ "paradise-lost.txt:Sing Heav'nly Muse, that on the secret top";
|
319
|
+
|
320
|
+
String actual = grepTool.grep(
|
321
|
+
"TO",
|
322
|
+
Collections.singletonList("-i"),
|
323
|
+
Arrays.asList("iliad.txt", "midsummer-night.txt", "paradise-lost.txt")
|
324
|
+
);
|
325
|
+
|
326
|
+
assertEquals(expected, actual);
|
327
|
+
}
|
328
|
+
|
329
|
+
@Ignore("Remove to run test")
|
330
|
+
@Test
|
331
|
+
public void multipleFilesSeveralMatchesInvertedFlag() {
|
332
|
+
String expected = "iliad.txt:Achilles sing, O Goddess! Peleus' son;\n"
|
333
|
+
+ "iliad.txt:The noble Chief Achilles from the son\n"
|
334
|
+
+ "midsummer-night.txt:If I refuse to wed Demetrius.";
|
335
|
+
|
336
|
+
String actual = grepTool.grep(
|
337
|
+
"a",
|
338
|
+
Collections.singletonList("-v"),
|
339
|
+
Arrays.asList("iliad.txt", "midsummer-night.txt", "paradise-lost.txt")
|
340
|
+
);
|
341
|
+
|
342
|
+
assertEquals(expected, actual);
|
343
|
+
}
|
344
|
+
|
345
|
+
@Ignore("Remove to run test")
|
346
|
+
@Test
|
347
|
+
public void multipleFilesOneMatchEntireLinesFlag() {
|
348
|
+
String expected = "midsummer-night.txt:But I beseech your grace that I may know";
|
349
|
+
|
350
|
+
String actual = grepTool.grep(
|
351
|
+
"But I beseech your grace that I may know",
|
352
|
+
Collections.singletonList("-x"),
|
353
|
+
Arrays.asList("iliad.txt", "midsummer-night.txt", "paradise-lost.txt")
|
354
|
+
);
|
355
|
+
|
356
|
+
assertEquals(expected, actual);
|
357
|
+
}
|
358
|
+
|
359
|
+
@Ignore("Remove to run test")
|
360
|
+
@Test
|
361
|
+
public void multipleFilesOneMatchMultipleFlags() {
|
362
|
+
String expected = "paradise-lost.txt:4:With loss of Eden, till one greater Man";
|
363
|
+
|
364
|
+
String actual = grepTool.grep(
|
365
|
+
"WITH LOSS OF EDEN, TILL ONE GREATER MAN",
|
366
|
+
Arrays.asList("-n", "-i", "-x"),
|
367
|
+
Arrays.asList("iliad.txt", "midsummer-night.txt", "paradise-lost.txt")
|
368
|
+
);
|
369
|
+
|
370
|
+
assertEquals(expected, actual);
|
371
|
+
}
|
372
|
+
|
373
|
+
@Ignore("Remove to run test")
|
374
|
+
@Test
|
375
|
+
public void multipleFilesNoMatchesVariousFlags() {
|
376
|
+
String expected = "";
|
377
|
+
|
378
|
+
String actual = grepTool.grep(
|
379
|
+
"Frodo",
|
380
|
+
Arrays.asList("-n", "-l", "-i", "-x"),
|
381
|
+
Arrays.asList("iliad.txt", "midsummer-night.txt", "paradise-lost.txt")
|
382
|
+
);
|
383
|
+
|
384
|
+
assertEquals(expected, actual);
|
385
|
+
}
|
386
|
+
|
387
|
+
private void writeToFile(String filename, List<String> contents) throws IOException {
|
388
|
+
Path file = Paths.get(filename);
|
389
|
+
Files.write(file, contents, Charset.forName("UTF-8"));
|
390
|
+
}
|
391
|
+
|
392
|
+
private void deleteFile(String filename) throws IOException {
|
393
|
+
Files.deleteIfExists(Paths.get(filename));
|
394
|
+
}
|
395
|
+
}
|
@@ -12,10 +12,10 @@ public class LargestSeriesProductCalculatorTest {
|
|
12
12
|
|
13
13
|
@Test
|
14
14
|
public void testCorrectlyCalculatesLargestProductWhenSeriesLengthEqualsStringToSearchLength() {
|
15
|
-
|
16
|
-
|
15
|
+
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("29");
|
16
|
+
long expectedProduct = 18;
|
17
17
|
|
18
|
-
|
18
|
+
long actualProduct = calculator.calculateLargestProductForSeriesLength(2);
|
19
19
|
|
20
20
|
assertEquals(expectedProduct, actualProduct);
|
21
21
|
}
|
@@ -23,10 +23,10 @@ public class LargestSeriesProductCalculatorTest {
|
|
23
23
|
@Ignore("Remove to run test")
|
24
24
|
@Test
|
25
25
|
public void testCorrectlyCalculatesLargestProductOfLengthTwoWithNumbersInOrder() {
|
26
|
-
|
27
|
-
|
26
|
+
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("0123456789");
|
27
|
+
long expectedProduct = 72;
|
28
28
|
|
29
|
-
|
29
|
+
long actualProduct = calculator.calculateLargestProductForSeriesLength(2);
|
30
30
|
|
31
31
|
assertEquals(expectedProduct, actualProduct);
|
32
32
|
}
|
@@ -34,10 +34,10 @@ public class LargestSeriesProductCalculatorTest {
|
|
34
34
|
@Ignore("Remove to run test")
|
35
35
|
@Test
|
36
36
|
public void testCorrectlyCalculatesLargestProductOfLengthTwoWithNumbersNotInOrder() {
|
37
|
-
|
38
|
-
|
37
|
+
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("576802143");
|
38
|
+
long expectedProduct = 48;
|
39
39
|
|
40
|
-
|
40
|
+
long actualProduct = calculator.calculateLargestProductForSeriesLength(2);
|
41
41
|
|
42
42
|
assertEquals(expectedProduct, actualProduct);
|
43
43
|
}
|
@@ -45,10 +45,10 @@ public class LargestSeriesProductCalculatorTest {
|
|
45
45
|
@Ignore("Remove to run test")
|
46
46
|
@Test
|
47
47
|
public void testCorrectlyCalculatesLargestProductOfLengthThreeWithNumbersInOrder() {
|
48
|
-
|
49
|
-
|
48
|
+
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("0123456789");
|
49
|
+
long expectedProduct = 504;
|
50
50
|
|
51
|
-
|
51
|
+
long actualProduct = calculator.calculateLargestProductForSeriesLength(3);
|
52
52
|
|
53
53
|
assertEquals(expectedProduct, actualProduct);
|
54
54
|
}
|
@@ -56,10 +56,10 @@ public class LargestSeriesProductCalculatorTest {
|
|
56
56
|
@Ignore("Remove to run test")
|
57
57
|
@Test
|
58
58
|
public void testCorrectlyCalculatesLargestProductOfLengthThreeWithNumbersNotInOrder() {
|
59
|
-
|
60
|
-
|
59
|
+
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("1027839564");
|
60
|
+
long expectedProduct = 270;
|
61
61
|
|
62
|
-
|
62
|
+
long actualProduct = calculator.calculateLargestProductForSeriesLength(3);
|
63
63
|
|
64
64
|
assertEquals(expectedProduct, actualProduct);
|
65
65
|
}
|
@@ -67,10 +67,10 @@ public class LargestSeriesProductCalculatorTest {
|
|
67
67
|
@Ignore("Remove to run test")
|
68
68
|
@Test
|
69
69
|
public void testCorrectlyCalculatesLargestProductOfLengthFiveWithNumbersInOrder() {
|
70
|
-
|
71
|
-
|
70
|
+
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("0123456789");
|
71
|
+
long expectedProduct = 15120;
|
72
72
|
|
73
|
-
|
73
|
+
long actualProduct = calculator.calculateLargestProductForSeriesLength(5);
|
74
74
|
|
75
75
|
assertEquals(expectedProduct, actualProduct);
|
76
76
|
}
|
@@ -78,12 +78,12 @@ public class LargestSeriesProductCalculatorTest {
|
|
78
78
|
@Ignore("Remove to run test")
|
79
79
|
@Test
|
80
80
|
public void testCorrectlyCalculatesLargestProductInLongStringToSearchV1() {
|
81
|
-
|
81
|
+
LargestSeriesProductCalculator calculator
|
82
82
|
= new LargestSeriesProductCalculator("73167176531330624919225119674426574742355349194934");
|
83
83
|
|
84
|
-
|
84
|
+
long expectedProduct = 23520;
|
85
85
|
|
86
|
-
|
86
|
+
long actualProduct = calculator.calculateLargestProductForSeriesLength(6);
|
87
87
|
|
88
88
|
assertEquals(expectedProduct, actualProduct);
|
89
89
|
}
|
@@ -91,10 +91,10 @@ public class LargestSeriesProductCalculatorTest {
|
|
91
91
|
@Ignore("Remove to run test")
|
92
92
|
@Test
|
93
93
|
public void testCorrectlyCalculatesLargestProductOfZeroIfAllDigitsAreZeroes() {
|
94
|
-
|
95
|
-
|
94
|
+
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("0000");
|
95
|
+
long expectedProduct = 0;
|
96
96
|
|
97
|
-
|
97
|
+
long actualProduct = calculator.calculateLargestProductForSeriesLength(2);
|
98
98
|
|
99
99
|
assertEquals(expectedProduct, actualProduct);
|
100
100
|
}
|
@@ -102,10 +102,10 @@ public class LargestSeriesProductCalculatorTest {
|
|
102
102
|
@Ignore("Remove to run test")
|
103
103
|
@Test
|
104
104
|
public void testCorrectlyCalculatesLargestProductOfZeroIfAllSeriesOfGivenLengthContainZero() {
|
105
|
-
|
106
|
-
|
105
|
+
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("99099");
|
106
|
+
long expectedProduct = 0;
|
107
107
|
|
108
|
-
|
108
|
+
long actualProduct = calculator.calculateLargestProductForSeriesLength(3);
|
109
109
|
|
110
110
|
assertEquals(expectedProduct, actualProduct);
|
111
111
|
}
|
@@ -113,7 +113,7 @@ public class LargestSeriesProductCalculatorTest {
|
|
113
113
|
@Ignore("Remove to run test")
|
114
114
|
@Test
|
115
115
|
public void testSeriesLengthLongerThanLengthOfStringToTestIsRejected() {
|
116
|
-
|
116
|
+
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("123");
|
117
117
|
|
118
118
|
expectedException.expect(IllegalArgumentException.class);
|
119
119
|
expectedException.expectMessage(
|
@@ -125,10 +125,10 @@ public class LargestSeriesProductCalculatorTest {
|
|
125
125
|
@Ignore("Remove to run test")
|
126
126
|
@Test
|
127
127
|
public void testCorrectlyCalculatesLargestProductOfLength0ForEmptyStringToSearch() {
|
128
|
-
|
129
|
-
|
128
|
+
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("");
|
129
|
+
long expectedProduct = 1;
|
130
130
|
|
131
|
-
|
131
|
+
long actualProduct = calculator.calculateLargestProductForSeriesLength(0);
|
132
132
|
|
133
133
|
assertEquals(expectedProduct, actualProduct);
|
134
134
|
}
|
@@ -136,10 +136,10 @@ public class LargestSeriesProductCalculatorTest {
|
|
136
136
|
@Ignore("Remove to run test")
|
137
137
|
@Test
|
138
138
|
public void testCorrectlyCalculatesLargestProductOfLength0ForNonEmptyStringToSearch() {
|
139
|
-
|
140
|
-
|
139
|
+
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("123");
|
140
|
+
long expectedProduct = 1;
|
141
141
|
|
142
|
-
|
142
|
+
long actualProduct = calculator.calculateLargestProductForSeriesLength(0);
|
143
143
|
|
144
144
|
assertEquals(expectedProduct, actualProduct);
|
145
145
|
}
|
@@ -147,7 +147,7 @@ public class LargestSeriesProductCalculatorTest {
|
|
147
147
|
@Ignore("Remove to run test")
|
148
148
|
@Test
|
149
149
|
public void testEmptyStringToSearchAndSeriesOfNonZeroLengthIsRejected() {
|
150
|
-
|
150
|
+
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("");
|
151
151
|
|
152
152
|
expectedException.expect(IllegalArgumentException.class);
|
153
153
|
expectedException.expectMessage(
|
@@ -168,7 +168,7 @@ public class LargestSeriesProductCalculatorTest {
|
|
168
168
|
@Ignore("Remove to run test")
|
169
169
|
@Test
|
170
170
|
public void testNegativeSeriesLengthIsRejected() {
|
171
|
-
|
171
|
+
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("12345");
|
172
172
|
|
173
173
|
expectedException.expect(IllegalArgumentException.class);
|
174
174
|
expectedException.expectMessage("Series length must be non-negative.");
|