Просмотр исходного кода

Merge branch 'master' into BinarySearchUseGenerics

FridaTveit 9 лет назад
Родитель
Сommit
d6e66977a2

+ 34
- 0
CONTRIBUTING.md Просмотреть файл

8
   * [The Problem Submodules](#the-problem-submodules)
8
   * [The Problem Submodules](#the-problem-submodules)
9
 * [Advanced: Complete Local Setup](#advanced-complete-local-setup)
9
 * [Advanced: Complete Local Setup](#advanced-complete-local-setup)
10
   * [Tip: `gradle clean` before `exercism fetch`](#tip-gradle-clean-before-exercism-fetch)
10
   * [Tip: `gradle clean` before `exercism fetch`](#tip-gradle-clean-before-exercism-fetch)
11
+* [Adding a New Exercise](#adding-a-new-exercise)
11
 
12
 
12
 ## Overview
13
 ## Overview
13
 
14
 
15
 
16
 
16
 If, at any point, you're having any trouble, pop in the [Gitter exercism/java room](https://gitter.im/exercism/java) or the [Gitter exercism/dev room](https://gitter.im/exercism/dev) for help.
17
 If, at any point, you're having any trouble, pop in the [Gitter exercism/java room](https://gitter.im/exercism/java) or the [Gitter exercism/dev room](https://gitter.im/exercism/dev) for help.
17
 
18
 
19
+For general guidelines about contributing to Exercism see the [Exercism contributing guide](https://github.com/exercism/docs/tree/master/contributing-to-language-tracks).
18
 
20
 
19
 ## Before Making Your Pull Request
21
 ## Before Making Your Pull Request
20
 
22
 
132
 cd ~/workspace/exercism/exercises
134
 cd ~/workspace/exercism/exercises
133
 exercism fetch java bob
135
 exercism fetch java bob
134
 ```
136
 ```
137
+
138
+## Adding a New Exercise
139
+
140
+The easiest way to add a new exercise to the Java track is to port an exercise from another track.
141
+That means that you take an exercise that has already been implemented in another language and you implement it in this track.
142
+
143
+To add a completely new exercise you need to open a pull request to the [problem specifications repository](https://github.com/exercism/problem-specifications/tree/master/exercises).
144
+Any completely new exercise needs to be added and accepted there before it can be added to the Java track.
145
+
146
+There is a [general Exercism guide for porting an exercise to a new language](https://github.com/exercism/docs/blob/master/you-can-help/implement-an-exercise-from-specification.md).
147
+Please review this before porting an exercise to the Java track.
148
+ 
149
+See [here](http://exercism.io/languages/java/todo) for a list of exercises that have yet to be implemented on the Java track and can therefore be ported to this track.
150
+Please make sure no one else has a pull request open to implement your chosen exercise before you start.
151
+Also please make a [dibs pull request](https://github.com/exercism/docs/blob/master/you-can-help/implement-an-exercise-from-specification.md#avoiding-duplicate-work) to make it clear to others that you are working on this exercise.
152
+
153
+The Java specific details you need to know about adding an exercise are:
154
+
155
+1. Please add an entry to the `exercises` array in `config.json`. You can find details about what should be in that entry [here](https://github.com/exercism/docs/blob/master/language-tracks/configuration/exercises.md).
156
+You can also look at other entries in `config.json` as examples and try to mimic them.
157
+
158
+2. Please add an entry for your exercise to `settings.gradle`.
159
+This should just be `include 'exercise-name'`.
160
+This list is in alphabetical order so please add your exercise so that it maintains this order.
161
+
162
+3. Please add an exercise submodule for your exercise.
163
+See [The Problem Submodules](#the-problem-submodules) section for what needs to be in this.
164
+The `build.gradle` file can just be copied from any other exercise submodule.
165
+See the [POLICIES doc](https://github.com/exercism/java/blob/master/POLICIES.md#starter-implementations) for an explanation of when you need to add a starter implementation.
166
+
167
+Hopefully that should be enough information to help you port an exercise to the Java track.
168
+Feel free to open an issue or post in the [Gitter exercism/java room](https://gitter.im/exercism/java) if you have any questions and we'll try and answer as soon as we can.

+ 203
- 36
config.json Просмотреть файл

199
       "core": true,
199
       "core": true,
200
       "difficulty": 4,
200
       "difficulty": 4,
201
       "slug": "matrix",
201
       "slug": "matrix",
202
-      "topics": null,
202
+      "topics": [
203
+        "loops",
204
+        "arrays",
205
+        "pattern_matching",
206
+        "integers",
207
+        "strings",
208
+        "type_conversion"
209
+      ],
203
       "unlocked_by": null,
210
       "unlocked_by": null,
204
       "uuid": "c1d4e0b4-6a0f-4be9-8222-345966621f53"
211
       "uuid": "c1d4e0b4-6a0f-4be9-8222-345966621f53"
205
     },
212
     },
229
       "core": false,
236
       "core": false,
230
       "difficulty": 4,
237
       "difficulty": 4,
231
       "slug": "sieve",
238
       "slug": "sieve",
232
-      "topics": null,
239
+      "topics": [
240
+        "loops",
241
+        "lists",
242
+        "integers",
243
+        "algorithms",
244
+        "mathematics"
245
+      ],
233
       "unlocked_by": "difference-of-squares",
246
       "unlocked_by": "difference-of-squares",
234
       "uuid": "6791d01f-bae4-4b63-ae76-86529ac49e36"
247
       "uuid": "6791d01f-bae4-4b63-ae76-86529ac49e36"
235
     },
248
     },
250
       "core": true,
263
       "core": true,
251
       "difficulty": 4,
264
       "difficulty": 4,
252
       "slug": "rotational-cipher",
265
       "slug": "rotational-cipher",
253
-      "topics": null,
266
+      "topics": [
267
+        "integers",
268
+        "strings",
269
+        "cryptography"
270
+      ],
254
       "unlocked_by": null,
271
       "unlocked_by": null,
255
       "uuid": "9eb41883-55ef-4681-b5ac-5c2259302772"
272
       "uuid": "9eb41883-55ef-4681-b5ac-5c2259302772"
256
     },
273
     },
258
       "core": false,
275
       "core": false,
259
       "difficulty": 4,
276
       "difficulty": 4,
260
       "slug": "kindergarten-garden",
277
       "slug": "kindergarten-garden",
261
-      "topics": null,
278
+      "topics": [
279
+        "loops",
280
+        "arrays",
281
+        "strings",
282
+        "logic",
283
+        "pattern_recognition",
284
+        "enumerations",
285
+        "lists"
286
+      ],
262
       "unlocked_by": "matrix",
287
       "unlocked_by": "matrix",
263
       "uuid": "0b92ffee-c092-4ab1-ad78-76c8cf80e1b5"
288
       "uuid": "0b92ffee-c092-4ab1-ad78-76c8cf80e1b5"
264
     },
289
     },
266
       "core": false,
291
       "core": false,
267
       "difficulty": 4,
292
       "difficulty": 4,
268
       "slug": "collatz-conjecture",
293
       "slug": "collatz-conjecture",
269
-      "topics": null,
294
+      "topics": [
295
+        "exception_handling",
296
+        "recursion",
297
+        "conditionals",
298
+        "integers",
299
+        "mathematics"
300
+      ],
270
       "unlocked_by": "triangle",
301
       "unlocked_by": "triangle",
271
       "uuid": "1500d39a-c9d9-4d3a-9e77-fdc1837fc6ad"
302
       "uuid": "1500d39a-c9d9-4d3a-9e77-fdc1837fc6ad"
272
     },
303
     },
274
       "core": false,
305
       "core": false,
275
       "difficulty": 4,
306
       "difficulty": 4,
276
       "slug": "nth-prime",
307
       "slug": "nth-prime",
277
-      "topics": null,
308
+      "topics": [
309
+        "arrays",
310
+        "exception_handling",
311
+        "lists",
312
+        "loops",
313
+        "integers"
314
+      ],
278
       "unlocked_by": "triangle",
315
       "unlocked_by": "triangle",
279
       "uuid": "2c69db99-648d-4bd7-8012-1fbdeff6ca0a"
316
       "uuid": "2c69db99-648d-4bd7-8012-1fbdeff6ca0a"
280
     },
317
     },
282
       "core": true,
319
       "core": true,
283
       "difficulty": 4,
320
       "difficulty": 4,
284
       "slug": "saddle-points",
321
       "slug": "saddle-points",
285
-      "topics": null,
322
+      "topics": [
323
+        "arrays",
324
+        "conditionals",
325
+        "integers",
326
+        "lists",
327
+        "loops",
328
+        "mathematics",
329
+        "matrices",
330
+        "sets"
331
+      ],
286
       "unlocked_by": null,
332
       "unlocked_by": null,
287
       "uuid": "8dfc2f0d-1141-46e9-95e2-6f35ccf6f160"
333
       "uuid": "8dfc2f0d-1141-46e9-95e2-6f35ccf6f160"
288
     },
334
     },
291
       "difficulty": 4,
337
       "difficulty": 4,
292
       "slug": "diamond",
338
       "slug": "diamond",
293
       "topics": [
339
       "topics": [
294
-		"strings",
295
-		"loops",
296
-		"arrays",
297
-		"lists",
298
-		"text_formatting"
299
-		],
340
+        "strings",
341
+        "loops",
342
+        "arrays",
343
+        "lists",
344
+        "text_formatting"
345
+      ],
300
       "unlocked_by": "two-fer",
346
       "unlocked_by": "two-fer",
301
       "uuid": "ecbd997b-86f4-4e11-9ff0-706ac2899415"
347
       "uuid": "ecbd997b-86f4-4e11-9ff0-706ac2899415"
302
     },
348
     },
317
       "core": true,
363
       "core": true,
318
       "difficulty": 5,
364
       "difficulty": 5,
319
       "slug": "flatten-array",
365
       "slug": "flatten-array",
320
-      "topics": null,
366
+      "topics": [
367
+        "arrays",
368
+        "lists",
369
+        "loops",
370
+        "recursion"
371
+      ],
321
       "unlocked_by": null,
372
       "unlocked_by": null,
322
       "uuid": "a732a838-8170-458a-a85e-d6b4c46f97a1"
373
       "uuid": "a732a838-8170-458a-a85e-d6b4c46f97a1"
323
     },
374
     },
367
       "core": true,
418
       "core": true,
368
       "difficulty": 5,
419
       "difficulty": 5,
369
       "slug": "word-count",
420
       "slug": "word-count",
370
-      "topics": null,
421
+      "topics": [
422
+        "strings",
423
+        "maps",
424
+        "loops",
425
+        "conditionals",
426
+        "integers"
427
+      ],
371
       "unlocked_by": null,
428
       "unlocked_by": null,
372
       "uuid": "3603b770-87a5-4758-91f3-b4d1f9075bc1"
429
       "uuid": "3603b770-87a5-4758-91f3-b4d1f9075bc1"
373
     },
430
     },
383
       "core": true,
440
       "core": true,
384
       "difficulty": 5,
441
       "difficulty": 5,
385
       "slug": "robot-name",
442
       "slug": "robot-name",
386
-      "topics": null,
443
+      "topics": [
444
+        "regular_expressions",
445
+        "strings",
446
+        "randomness",
447
+        "text_formatting",
448
+        "pattern_matching"
449
+      ],
387
       "unlocked_by": null,
450
       "unlocked_by": null,
388
       "uuid": "d7c2eed9-64c7-4c4a-b45d-c787d460337f"
451
       "uuid": "d7c2eed9-64c7-4c4a-b45d-c787d460337f"
389
     },
452
     },
391
       "core": false,
454
       "core": false,
392
       "difficulty": 5,
455
       "difficulty": 5,
393
       "slug": "prime-factors",
456
       "slug": "prime-factors",
394
-      "topics": null,
457
+      "topics": [
458
+        "arrays",
459
+        "conditionals",
460
+        "integers",
461
+        "lists",
462
+        "loops",
463
+        "mathematics"
464
+      ],
395
       "unlocked_by": "triangle",
465
       "unlocked_by": "triangle",
396
       "uuid": "599c08ec-7338-46ed-99f8-a76f78f724e6"
466
       "uuid": "599c08ec-7338-46ed-99f8-a76f78f724e6"
397
     },
467
     },
441
       "core": false,
511
       "core": false,
442
       "difficulty": 5,
512
       "difficulty": 5,
443
       "slug": "bracket-push",
513
       "slug": "bracket-push",
444
-      "topics": null,
514
+      "topics": [
515
+        "stacks",
516
+        "strings"
517
+      ],
445
       "unlocked_by": "flatten-array",
518
       "unlocked_by": "flatten-array",
446
       "uuid": "85aa50ac-0141-49eb-bc6f-62f3f7a97647"
519
       "uuid": "85aa50ac-0141-49eb-bc6f-62f3f7a97647"
447
     },
520
     },
463
       "core": false,
536
       "core": false,
464
       "difficulty": 5,
537
       "difficulty": 5,
465
       "slug": "atbash-cipher",
538
       "slug": "atbash-cipher",
466
-      "topics": null,
539
+      "topics": [
540
+        "strings",
541
+        "cryptography",
542
+        "security"
543
+      ],
467
       "unlocked_by": "rotational-cipher",
544
       "unlocked_by": "rotational-cipher",
468
       "uuid": "d36ce010-210f-4e9a-9d6c-cb933e0a59af"
545
       "uuid": "d36ce010-210f-4e9a-9d6c-cb933e0a59af"
469
     },
546
     },
518
       "difficulty": 6,
595
       "difficulty": 6,
519
       "slug": "food-chain",
596
       "slug": "food-chain",
520
       "topics": [
597
       "topics": [
521
-       	"arrays",
522
-       	"lists",
523
-       	"strings"
524
-       ],
598
+        "arrays",
599
+        "lists",
600
+        "strings"
601
+      ],
525
       "unlocked_by": "two-fer",
602
       "unlocked_by": "two-fer",
526
       "uuid": "dd3e6fd6-5359-4978-acd7-c39374cead4d"
603
       "uuid": "dd3e6fd6-5359-4978-acd7-c39374cead4d"
527
     },
604
     },
566
       "core": false,
643
       "core": false,
567
       "difficulty": 6,
644
       "difficulty": 6,
568
       "slug": "grade-school",
645
       "slug": "grade-school",
569
-      "topics": null,
646
+      "topics": [
647
+        "conditionals",
648
+        "strings",
649
+        "lists",
650
+        "maps",
651
+        "sorting"
652
+      ],
570
       "unlocked_by": "word-count",
653
       "unlocked_by": "word-count",
571
       "uuid": "b4af5da1-601f-4b0f-bfb8-4a381851090c"
654
       "uuid": "b4af5da1-601f-4b0f-bfb8-4a381851090c"
572
     },
655
     },
574
       "core": false,
657
       "core": false,
575
       "difficulty": 6,
658
       "difficulty": 6,
576
       "slug": "robot-simulator",
659
       "slug": "robot-simulator",
577
-      "topics": null,
660
+      "topics": [
661
+        "classes",
662
+        "logic",
663
+        "loops",
664
+        "enumerations"
665
+      ],
578
       "unlocked_by": "secret-handshake",
666
       "unlocked_by": "secret-handshake",
579
       "uuid": "993bde9d-7774-4e7a-a381-9eee75f28ecb"
667
       "uuid": "993bde9d-7774-4e7a-a381-9eee75f28ecb"
580
     },
668
     },
622
       "core": false,
710
       "core": false,
623
       "difficulty": 6,
711
       "difficulty": 6,
624
       "slug": "all-your-base",
712
       "slug": "all-your-base",
625
-      "topics": null,
713
+      "topics": [
714
+        "loops",
715
+        "mathematics",
716
+        "integers",
717
+        "arrays",
718
+        "conditionals",
719
+        "exception_handling"
720
+      ],
626
       "unlocked_by": "saddle-points",
721
       "unlocked_by": "saddle-points",
627
       "uuid": "f7c2e4b5-1995-4dfe-b827-c9aff8ac5332"
722
       "uuid": "f7c2e4b5-1995-4dfe-b827-c9aff8ac5332"
628
     },
723
     },
646
       "core": true,
741
       "core": true,
647
       "difficulty": 6,
742
       "difficulty": 6,
648
       "slug": "linked-list",
743
       "slug": "linked-list",
649
-      "topics": null,
744
+      "topics": [
745
+        "algorithms",
746
+        "lists",
747
+        "generics"
748
+      ],
650
       "unlocked_by": null,
749
       "unlocked_by": null,
651
       "uuid": "7ba5084d-3b75-4406-a0d7-87c26387f9c0"
750
       "uuid": "7ba5084d-3b75-4406-a0d7-87c26387f9c0"
652
     },
751
     },
653
     {
752
     {
654
       "core": false,
753
       "core": false,
754
+      "difficulty": 6,
755
+      "slug": "tournament",
756
+      "topics": [
757
+        "loops",
758
+        "maps",
759
+        "sorting",
760
+        "parsing",
761
+        "text_formatting"
762
+      ],
763
+      "unlocked_by": "matrix",
764
+      "uuid": "99191d53-0fed-f680-de7a-55cfb872de17bc58629"
765
+    },
766
+    {
767
+      "core": false,
655
       "difficulty": 7,
768
       "difficulty": 7,
656
       "slug": "anagram",
769
       "slug": "anagram",
657
       "topics": [
770
       "topics": [
669
       "core": false,
782
       "core": false,
670
       "difficulty": 7,
783
       "difficulty": 7,
671
       "slug": "sublist",
784
       "slug": "sublist",
672
-      "topics": null,
785
+      "topics": [
786
+        "lists",
787
+        "searching",
788
+        "loops",
789
+        "generics",
790
+        "enumeration"
791
+      ],
673
       "unlocked_by": "linked-list",
792
       "unlocked_by": "linked-list",
674
       "uuid": "d2aedbd7-092a-43d0-8a5e-ae3ebd5b9c7f"
793
       "uuid": "d2aedbd7-092a-43d0-8a5e-ae3ebd5b9c7f"
675
     },
794
     },
708
       "core": false,
827
       "core": false,
709
       "difficulty": 7,
828
       "difficulty": 7,
710
       "slug": "meetup",
829
       "slug": "meetup",
711
-      "topics": null,
830
+      "topics": [
831
+        "conditionals",
832
+        "dates",
833
+        "loops",
834
+        "enumerations"
835
+      ],
712
       "unlocked_by": "gigasecond",
836
       "unlocked_by": "gigasecond",
713
       "uuid": "602511d5-7e89-4def-b072-4dd311816810"
837
       "uuid": "602511d5-7e89-4def-b072-4dd311816810"
714
     },
838
     },
716
       "core": false,
840
       "core": false,
717
       "difficulty": 7,
841
       "difficulty": 7,
718
       "slug": "crypto-square",
842
       "slug": "crypto-square",
719
-      "topics": null,
843
+      "topics": [
844
+        "strings",
845
+        "text_formatting",
846
+        "mathematics",
847
+        "cryptography",
848
+        "security",
849
+        "lists"
850
+      ],
720
       "unlocked_by": "rotational-cipher",
851
       "unlocked_by": "rotational-cipher",
721
       "uuid": "162bebdc-9bf2-43c0-8460-a91f5fc16147"
852
       "uuid": "162bebdc-9bf2-43c0-8460-a91f5fc16147"
722
     },
853
     },
736
       "core": false,
867
       "core": false,
737
       "difficulty": 7,
868
       "difficulty": 7,
738
       "slug": "clock",
869
       "slug": "clock",
739
-      "topics": null,
870
+      "topics": [
871
+        "equality",
872
+        "integers",
873
+        "logic",
874
+        "object_oriented_programming",
875
+        "strings",
876
+        "time"
877
+      ],
740
       "unlocked_by": "saddle-points",
878
       "unlocked_by": "saddle-points",
741
       "uuid": "97c8fcd4-85b6-41cb-9de2-b4e1b4951222"
879
       "uuid": "97c8fcd4-85b6-41cb-9de2-b4e1b4951222"
742
     },
880
     },
772
       "core": false,
910
       "core": false,
773
       "difficulty": 8,
911
       "difficulty": 8,
774
       "slug": "book-store",
912
       "slug": "book-store",
775
-      "topics": null,
913
+      "topics": [
914
+        "integers",
915
+        "lists",
916
+        "algorithms",
917
+        "mathematics",
918
+        "floating_point_numbers"
919
+      ],
776
       "unlocked_by": "flatten-array",
920
       "unlocked_by": "flatten-array",
777
       "uuid": "e5f05d00-fe5b-4d78-b2fa-934c1c9afb32"
921
       "uuid": "e5f05d00-fe5b-4d78-b2fa-934c1c9afb32"
778
     },
922
     },
780
       "core": false,
924
       "core": false,
781
       "difficulty": 8,
925
       "difficulty": 8,
782
       "slug": "simple-cipher",
926
       "slug": "simple-cipher",
783
-      "topics": null,
927
+      "topics": [
928
+        "strings",
929
+        "cryptography",
930
+        "security",
931
+        "mathematics",
932
+        "randomness",
933
+        "exception_handling"
934
+      ],
784
       "unlocked_by": "rotational-cipher",
935
       "unlocked_by": "rotational-cipher",
785
       "uuid": "f654831f-c34b-44f5-9dd5-054efbb486f2"
936
       "uuid": "f654831f-c34b-44f5-9dd5-054efbb486f2"
786
     },
937
     },
788
       "core": false,
939
       "core": false,
789
       "difficulty": 8,
940
       "difficulty": 8,
790
       "slug": "complex-numbers",
941
       "slug": "complex-numbers",
791
-      "topics": null,
942
+      "topics": [
943
+        "mathematics",
944
+        "floating_point_numbers",
945
+        "classes"
946
+      ],
792
       "unlocked_by": "triangle",
947
       "unlocked_by": "triangle",
793
       "uuid": "52d11278-0d65-4b5b-b387-1374fced3243"
948
       "uuid": "52d11278-0d65-4b5b-b387-1374fced3243"
794
     },
949
     },
804
       "core": false,
959
       "core": false,
805
       "difficulty": 8,
960
       "difficulty": 8,
806
       "slug": "change",
961
       "slug": "change",
807
-      "topics": null,
962
+      "topics": [
963
+        "algorithms",
964
+        "integers",
965
+        "exception_handling",
966
+        "lists"
967
+      ],
808
       "unlocked_by": "flatten-array",
968
       "unlocked_by": "flatten-array",
809
       "uuid": "bac1f4bc-eea9-43c1-8e95-097347f5925e"
969
       "uuid": "bac1f4bc-eea9-43c1-8e95-097347f5925e"
810
     },
970
     },
812
       "core": false,
972
       "core": false,
813
       "difficulty": 8,
973
       "difficulty": 8,
814
       "slug": "palindrome-products",
974
       "slug": "palindrome-products",
815
-      "topics": null,
975
+      "topics": [
976
+        "conditionals",
977
+        "integers",
978
+        "lists",
979
+        "loops",
980
+        "maps",
981
+        "mathematics"
982
+      ],
816
       "unlocked_by": "saddle-points",
983
       "unlocked_by": "saddle-points",
817
       "uuid": "873c05de-b5f5-4c5b-97f0-d1ede8a82832"
984
       "uuid": "873c05de-b5f5-4c5b-97f0-d1ede8a82832"
818
     },
985
     },

+ 4
- 7
config/maintainers.json Просмотреть файл

49
     },
49
     },
50
     {
50
     {
51
       "alumnus": false,
51
       "alumnus": false,
52
-      "avatar_url": null,
53
-      "bio": null,
52
+      "bio": "I'm a software developer working for Softwire, a UK based software company. I love programming in pretty much any language (possibly with the exception of C++) but Java is probably the language I have the most experience with.",
54
       "github_username": "FridaTveit",
53
       "github_username": "FridaTveit",
55
-      "link_text": null,
56
-      "link_url": null,
57
-      "name": null,
58
-      "show_on_website": false
54
+      "name": "Frida Johanne Tveit",
55
+      "show_on_website": true
59
     }
56
     }
60
   ]
57
   ]
61
-}
58
+}

exercises/binary-search-tree/.meta/src/reference/java/BST.java → exercises/binary-search-tree/.meta/src/reference/java/BinarySearchTree.java Просмотреть файл

5
 import java.util.List;
5
 import java.util.List;
6
 import java.util.Queue;
6
 import java.util.Queue;
7
 
7
 
8
-public class BST<T extends Comparable<T>> {
8
+public class BinarySearchTree<T extends Comparable<T>> {
9
 
9
 
10
     public static class Node<T> {
10
     public static class Node<T> {
11
 
11
 

exercises/binary-search-tree/src/test/java/BSTTest.java → exercises/binary-search-tree/src/test/java/BinarySearchTreeTest.java Просмотреть файл

6
 import static org.junit.Assert.assertNotNull;
6
 import static org.junit.Assert.assertNotNull;
7
 import org.junit.Ignore;
7
 import org.junit.Ignore;
8
 import org.junit.Test;
8
 import org.junit.Test;
9
+import org.junit.Before;
9
 
10
 
10
-public class BSTTest {
11
+public class BinarySearchTreeTest {
12
+    private BinarySearchTree<Integer> binarySearchTree;
13
+
14
+    @Before
15
+    public void setUp() {
16
+        binarySearchTree = new BinarySearchTree<>();
17
+    }
11
 
18
 
12
     @Test
19
     @Test
13
     public void dataIsRetained() {
20
     public void dataIsRetained() {
14
-        BST<Integer> bst = new BST<>();
15
         final int actual = 4;
21
         final int actual = 4;
16
-        bst.insert(actual);
17
-        final BST.Node<Integer> root = bst.getRoot();
22
+        binarySearchTree.insert(actual);
23
+        final BinarySearchTree.Node<Integer> root = binarySearchTree.getRoot();
18
         assertNotNull(root);
24
         assertNotNull(root);
19
         final int expected = root.getData();
25
         final int expected = root.getData();
20
         assertEquals(expected, actual);
26
         assertEquals(expected, actual);
23
     @Ignore("Remove to run test")
29
     @Ignore("Remove to run test")
24
     @Test
30
     @Test
25
     public void insertsLess() {
31
     public void insertsLess() {
26
-        BST<Integer> bst = new BST<>();
27
         final int expectedRoot = 4;
32
         final int expectedRoot = 4;
28
         final int expectedLeft = 2;
33
         final int expectedLeft = 2;
29
 
34
 
30
-        bst.insert(expectedRoot);
31
-        bst.insert(expectedLeft);
35
+        binarySearchTree.insert(expectedRoot);
36
+        binarySearchTree.insert(expectedLeft);
32
 
37
 
33
-        final BST.Node<Integer> root = bst.getRoot();
38
+        final BinarySearchTree.Node<Integer> root = binarySearchTree.getRoot();
34
         assertNotNull(root);
39
         assertNotNull(root);
35
-        final BST.Node<Integer> left = root.getLeft();
40
+        final BinarySearchTree.Node<Integer> left = root.getLeft();
36
         assertNotNull(left);
41
         assertNotNull(left);
37
 
42
 
38
         final int actualRoot = root.getData();
43
         final int actualRoot = root.getData();
44
     @Ignore("Remove to run test")
49
     @Ignore("Remove to run test")
45
     @Test
50
     @Test
46
     public void insertsSame() {
51
     public void insertsSame() {
47
-        BST<Integer> bst = new BST<>();
48
         final int expectedRoot = 4;
52
         final int expectedRoot = 4;
49
         final int expectedLeft = 4;
53
         final int expectedLeft = 4;
50
 
54
 
51
-        bst.insert(expectedRoot);
52
-        bst.insert(expectedLeft);
55
+        binarySearchTree.insert(expectedRoot);
56
+        binarySearchTree.insert(expectedLeft);
53
 
57
 
54
-        final BST.Node<Integer> root = bst.getRoot();
58
+        final BinarySearchTree.Node<Integer> root = binarySearchTree.getRoot();
55
         assertNotNull(root);
59
         assertNotNull(root);
56
-        final BST.Node<Integer> left = root.getLeft();
60
+        final BinarySearchTree.Node<Integer> left = root.getLeft();
57
         assertNotNull(left);
61
         assertNotNull(left);
58
 
62
 
59
         final int actualRoot = root.getData();
63
         final int actualRoot = root.getData();
65
     @Ignore("Remove to run test")
69
     @Ignore("Remove to run test")
66
     @Test
70
     @Test
67
     public void insertsRight() {
71
     public void insertsRight() {
68
-        BST<Integer> bst = new BST<>();
69
         final int expectedRoot = 4;
72
         final int expectedRoot = 4;
70
         final int expectedRight = 5;
73
         final int expectedRight = 5;
71
 
74
 
72
-        bst.insert(expectedRoot);
73
-        bst.insert(expectedRight);
75
+        binarySearchTree.insert(expectedRoot);
76
+        binarySearchTree.insert(expectedRight);
74
 
77
 
75
-        final BST.Node<Integer> root = bst.getRoot();
78
+        final BinarySearchTree.Node<Integer> root = binarySearchTree.getRoot();
76
         assertNotNull(root);
79
         assertNotNull(root);
77
-        final BST.Node<Integer> right = root.getRight();
80
+        final BinarySearchTree.Node<Integer> right = root.getRight();
78
         assertNotNull(right);
81
         assertNotNull(right);
79
 
82
 
80
         final int actualRoot = root.getData();
83
         final int actualRoot = root.getData();
86
     @Ignore("Remove to run test")
89
     @Ignore("Remove to run test")
87
     @Test
90
     @Test
88
     public void createsComplexTree() {
91
     public void createsComplexTree() {
89
-        BST<Integer> bst = new BST<>();
90
         List<Integer> expected = Collections.unmodifiableList(
92
         List<Integer> expected = Collections.unmodifiableList(
91
                 Arrays.asList(4, 2, 6, 1, 3, 5, 7)
93
                 Arrays.asList(4, 2, 6, 1, 3, 5, 7)
92
         );
94
         );
94
         List<Integer> treeData = Collections.unmodifiableList(
96
         List<Integer> treeData = Collections.unmodifiableList(
95
                 Arrays.asList(4, 2, 6, 1, 3, 7, 5)
97
                 Arrays.asList(4, 2, 6, 1, 3, 7, 5)
96
         );
98
         );
97
-        treeData.forEach(bst::insert);
99
+        treeData.forEach(binarySearchTree::insert);
98
 
100
 
99
-        List<Integer> actual = bst.getAsLevelOrderList();
101
+        List<Integer> actual = binarySearchTree.getAsLevelOrderList();
100
         assertEquals(expected, actual);
102
         assertEquals(expected, actual);
101
     }
103
     }
102
 
104
 
103
     @Ignore("Remove to run test")
105
     @Ignore("Remove to run test")
104
     @Test
106
     @Test
105
     public void sortsSingleElement() {
107
     public void sortsSingleElement() {
106
-        BST<Integer> bst = new BST<>();
107
         List<Integer> expected = Collections.unmodifiableList(
108
         List<Integer> expected = Collections.unmodifiableList(
108
                 Collections.singletonList(4)
109
                 Collections.singletonList(4)
109
         );
110
         );
110
 
111
 
111
-        bst.insert(4);
112
+        binarySearchTree.insert(4);
112
 
113
 
113
-        List<Integer> actual = bst.getAsSortedList();
114
+        List<Integer> actual = binarySearchTree.getAsSortedList();
114
         assertEquals(expected, actual);
115
         assertEquals(expected, actual);
115
     }
116
     }
116
 
117
 
117
     @Ignore("Remove to run test")
118
     @Ignore("Remove to run test")
118
     @Test
119
     @Test
119
     public void sortsCollectionOfTwoIfSecondInsertedIsSmallerThanFirst() {
120
     public void sortsCollectionOfTwoIfSecondInsertedIsSmallerThanFirst() {
120
-        BST<Integer> bst = new BST<>();
121
         List<Integer> expected = Collections.unmodifiableList(
121
         List<Integer> expected = Collections.unmodifiableList(
122
                 Arrays.asList(2, 4)
122
                 Arrays.asList(2, 4)
123
         );
123
         );
124
 
124
 
125
-        bst.insert(4);
126
-        bst.insert(2);
125
+        binarySearchTree.insert(4);
126
+        binarySearchTree.insert(2);
127
 
127
 
128
-        List<Integer> actual = bst.getAsSortedList();
128
+        List<Integer> actual = binarySearchTree.getAsSortedList();
129
         assertEquals(expected, actual);
129
         assertEquals(expected, actual);
130
     }
130
     }
131
 
131
 
132
     @Ignore("Remove to run test")
132
     @Ignore("Remove to run test")
133
     @Test
133
     @Test
134
     public void sortsCollectionOfTwoIfSecondInsertedIsBiggerThanFirst() {
134
     public void sortsCollectionOfTwoIfSecondInsertedIsBiggerThanFirst() {
135
-        BST<Integer> bst = new BST<>();
136
         List<Integer> expected = Collections.unmodifiableList(
135
         List<Integer> expected = Collections.unmodifiableList(
137
                 Arrays.asList(4, 5)
136
                 Arrays.asList(4, 5)
138
         );
137
         );
139
 
138
 
140
-        bst.insert(4);
141
-        bst.insert(5);
139
+        binarySearchTree.insert(4);
140
+        binarySearchTree.insert(5);
142
 
141
 
143
-        List<Integer> actual = bst.getAsSortedList();
142
+        List<Integer> actual = binarySearchTree.getAsSortedList();
144
         assertEquals(expected, actual);
143
         assertEquals(expected, actual);
145
     }
144
     }
146
 
145
 
147
     @Ignore("Remove to run test")
146
     @Ignore("Remove to run test")
148
     @Test
147
     @Test
149
     public void iteratesOverComplexTree() {
148
     public void iteratesOverComplexTree() {
150
-        BST<Integer> bst = new BST<>();
151
         List<Integer> expected = Collections.unmodifiableList(
149
         List<Integer> expected = Collections.unmodifiableList(
152
                 Arrays.asList(1, 2, 3, 4, 5, 6, 7)
150
                 Arrays.asList(1, 2, 3, 4, 5, 6, 7)
153
         );
151
         );
155
         List<Integer> treeData = Collections.unmodifiableList(
153
         List<Integer> treeData = Collections.unmodifiableList(
156
                 Arrays.asList(4, 2, 1, 3, 6, 7, 5)
154
                 Arrays.asList(4, 2, 1, 3, 6, 7, 5)
157
         );
155
         );
158
-        treeData.forEach(bst::insert);
156
+        treeData.forEach(binarySearchTree::insert);
159
 
157
 
160
-        List<Integer> actual = bst.getAsSortedList();
158
+        List<Integer> actual = binarySearchTree.getAsSortedList();
161
         assertEquals(expected, actual);
159
         assertEquals(expected, actual);
162
     }
160
     }
163
 }
161
 }

+ 7
- 3
exercises/largest-series-product/src/main/java/LargestSeriesProductCalculator.java Просмотреть файл

1
-public class LargestSeriesProductCalculator {
2
-
3
-
1
+class LargestSeriesProductCalculator {
2
+    LargestSeriesProductCalculator(String inputNumber) {
3
+        throw new UnsupportedOperationException ("Delete this statement and write your own implementation.");
4
+    }
4
 
5
 
6
+    long calculateLargestProductForSeriesLength(int numberOfDigits) {
7
+        throw new UnsupportedOperationException ("Delete this statement and write your own implementation.");
8
+    }
5
 }
9
 }

+ 23
- 0
exercises/matrix/src/main/java/Matrix.java Просмотреть файл

1
+
2
+class Matrix {
3
+
4
+    Matrix(String matrixAsString) {
5
+        throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
6
+    }
7
+
8
+    int[] getRow(int rowNumber) {
9
+        throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
10
+    }
11
+
12
+    int[] getColumn(int columnNumber) {
13
+        throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
14
+    }
15
+
16
+    int getRowsCount() {
17
+        throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
18
+    }
19
+
20
+    int getColumnsCount() {
21
+        throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
22
+    }
23
+}

+ 19
- 15
exercises/robot-simulator/src/main/java/GridPosition.java Просмотреть файл

9
         this.y = y;
9
         this.y = y;
10
     }
10
     }
11
 
11
 
12
-    /*
13
-     * This equals method is of deliberately narrow scope (only allows comparison with another GridPosition) to increase
14
-     * readability. In general, one should provide a full implementation of Object.equals(Object obj) and a
15
-     * corresponding implementation of Object.hashCode(). See
16
-     *
17
-     * https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#equals(java.lang.Object)
18
-     *
19
-     * and
20
-     *
21
-     * https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#hashCode()
22
-     *
23
-     * for more information.
24
-     */
25
-    boolean equals(final GridPosition gridPosition) {
26
-        return this.x == gridPosition.x && this.y == gridPosition.y;
12
+    @Override
13
+    public int hashCode() {
14
+        final int prime = 31;
15
+        int result = 1;
16
+        result = prime * result + x;
17
+        result = prime * result + y;
18
+        return result;
27
     }
19
     }
28
 
20
 
21
+    @Override
22
+    public boolean equals(Object obj) {
23
+        if (this == obj) {
24
+            return true;
25
+        } else if (obj == null || getClass() != obj.getClass()) {
26
+            return false;
27
+        } else if (x != ((GridPosition) obj).x || y != ((GridPosition)obj).y) {
28
+            return false;
29
+        } else {
30
+            return true;
31
+        }
32
+    }
29
 }
33
 }

+ 7
- 1
exercises/saddle-points/.meta/src/reference/java/MatrixCoordinate.java Просмотреть файл

1
-class MatrixCoordinate {
1
+class MatrixCoordinate implements Comparable<MatrixCoordinate> {
2
     private final int row;
2
     private final int row;
3
     private final int col;
3
     private final int col;
4
 
4
 
30
         result = 31 * result + col;
30
         result = 31 * result + col;
31
         return result;
31
         return result;
32
     }
32
     }
33
+
34
+    @Override
35
+    public int compareTo(MatrixCoordinate o) {
36
+        int rowComparison = Integer.compare(row, o.row);
37
+        return (rowComparison == 0) ? Integer.compare(col, o.col) : rowComparison;
38
+    }
33
 }
39
 }

+ 7
- 1
exercises/saddle-points/src/main/java/MatrixCoordinate.java Просмотреть файл

1
-class MatrixCoordinate {
1
+class MatrixCoordinate implements Comparable<MatrixCoordinate> {
2
     private final int row;
2
     private final int row;
3
     private final int col;
3
     private final int col;
4
 
4
 
30
         result = 31 * result + col;
30
         result = 31 * result + col;
31
         return result;
31
         return result;
32
     }
32
     }
33
+
34
+    @Override
35
+    public int compareTo(MatrixCoordinate o) {
36
+        int rowComparison = Integer.compare(row, o.row);
37
+        return (rowComparison == 0) ? Integer.compare(col, o.col) : rowComparison;
38
+    }
33
 }
39
 }

+ 1
- 0
exercises/settings.gradle Просмотреть файл

75
 include 'strain'
75
 include 'strain'
76
 include 'sublist'
76
 include 'sublist'
77
 include 'sum-of-multiples'
77
 include 'sum-of-multiples'
78
+include 'tournament'
78
 include 'transpose'
79
 include 'transpose'
79
 include 'triangle'
80
 include 'triangle'
80
 include 'trinary'
81
 include 'trinary'

+ 25
- 25
exercises/simple-linked-list/src/test/java/SimpleLinkedListTest.java Просмотреть файл

15
 
15
 
16
     @Test
16
     @Test
17
     public void aNewListIsEmpty() {
17
     public void aNewListIsEmpty() {
18
-        SimpleLinkedList list = new SimpleLinkedList();
18
+        SimpleLinkedList<Integer> list = new SimpleLinkedList<>();
19
         assertThat(list.size(), is(0));
19
         assertThat(list.size(), is(0));
20
     }
20
     }
21
 
21
 
22
     @Ignore("Remove to run test")
22
     @Ignore("Remove to run test")
23
     @Test
23
     @Test
24
     public void canCreateFromArray() {
24
     public void canCreateFromArray() {
25
-        Integer[] values = new Integer[]{1, 2, 3};
26
-        SimpleLinkedList list = new SimpleLinkedList(values);
25
+        Character[] values = new Character[]{'1', '2', '3'};
26
+        SimpleLinkedList<Character> list = new SimpleLinkedList<Character>(values);
27
         assertThat(list.size(), is(3));
27
         assertThat(list.size(), is(3));
28
     }
28
     }
29
 
29
 
31
     @Test
31
     @Test
32
     public void popOnEmptyListWillThrow() {
32
     public void popOnEmptyListWillThrow() {
33
         expectedException.expect(NoSuchElementException.class);
33
         expectedException.expect(NoSuchElementException.class);
34
-        SimpleLinkedList list = new SimpleLinkedList();
34
+        SimpleLinkedList<String> list = new SimpleLinkedList<String>();
35
         list.pop();
35
         list.pop();
36
     }
36
     }
37
 
37
 
38
     @Ignore("Remove to run test")
38
     @Ignore("Remove to run test")
39
     @Test
39
     @Test
40
     public void popReturnsLastAddedElement() {
40
     public void popReturnsLastAddedElement() {
41
-        SimpleLinkedList list = new SimpleLinkedList();
41
+        SimpleLinkedList<Integer> list = new SimpleLinkedList<Integer>();
42
         list.push(9);
42
         list.push(9);
43
         list.push(8);
43
         list.push(8);
44
         assertThat(list.size(), is(2));
44
         assertThat(list.size(), is(2));
50
     @Ignore("Remove to run test")
50
     @Ignore("Remove to run test")
51
     @Test
51
     @Test
52
     public void reverseReversesList() {
52
     public void reverseReversesList() {
53
-        SimpleLinkedList list = new SimpleLinkedList();
54
-        list.push(9);
55
-        list.push(8);
56
-        list.push(7);
57
-        list.push(6);
58
-        list.push(5);
53
+        SimpleLinkedList<String> list = new SimpleLinkedList<String>();
54
+        list.push("9");
55
+        list.push("8");
56
+        list.push("7");
57
+        list.push("6");
58
+        list.push("5");
59
         list.reverse();
59
         list.reverse();
60
-        assertThat(list.pop(), is(9));
61
-        assertThat(list.pop(), is(8));
62
-        assertThat(list.pop(), is(7));
63
-        assertThat(list.pop(), is(6));
64
-        assertThat(list.pop(), is(5));
60
+        assertThat(list.pop(), is("9"));
61
+        assertThat(list.pop(), is("8"));
62
+        assertThat(list.pop(), is("7"));
63
+        assertThat(list.pop(), is("6"));
64
+        assertThat(list.pop(), is("5"));
65
     }
65
     }
66
 
66
 
67
     @Ignore("Remove to run test")
67
     @Ignore("Remove to run test")
68
     @Test
68
     @Test
69
     public void canReturnListAsArray() {
69
     public void canReturnListAsArray() {
70
-        SimpleLinkedList list = new SimpleLinkedList();
71
-        list.push(9);
72
-        list.push(8);
73
-        list.push(7);
74
-        list.push(6);
75
-        list.push(5);
76
-        Integer[] expected = {5, 6, 7, 8, 9};
77
-        assertArrayEquals(expected, list.asArray(Integer.class));
70
+        SimpleLinkedList<Character> list = new SimpleLinkedList<Character>();
71
+        list.push('9');
72
+        list.push('8');
73
+        list.push('7');
74
+        list.push('6');
75
+        list.push('5');
76
+        Character[] expected = {'5', '6', '7', '8', '9'};
77
+        assertArrayEquals(expected, list.asArray(Character.class));
78
     }
78
     }
79
 
79
 
80
     @Ignore("Remove to run test")
80
     @Ignore("Remove to run test")
81
     @Test
81
     @Test
82
     public void canReturnEmptyListAsEmptyArray() {
82
     public void canReturnEmptyListAsEmptyArray() {
83
-        SimpleLinkedList list = new SimpleLinkedList();
83
+        SimpleLinkedList<Object> list = new SimpleLinkedList<Object>();
84
         Object[] expected = {};
84
         Object[] expected = {};
85
         assertArrayEquals(expected, list.asArray(Object.class));
85
         assertArrayEquals(expected, list.asArray(Object.class));
86
     }
86
     }

+ 5
- 0
exercises/tournament/.meta/src/reference/java/Result.java Просмотреть файл

1
+enum Result {
2
+    WIN,
3
+    DRAW,
4
+    LOSS
5
+}

+ 41
- 0
exercises/tournament/.meta/src/reference/java/TeamResult.java Просмотреть файл

1
+class TeamResult {
2
+
3
+    private int wins;
4
+    private int losses;
5
+    private int draws;
6
+
7
+    TeamResult() {
8
+        wins = 0;
9
+        losses = 0;
10
+        draws = 0;
11
+    }
12
+
13
+    int getPlayed() {
14
+        return wins + losses + draws;
15
+    }
16
+
17
+    int getPoints() {
18
+        return wins * 3 + draws;
19
+    }
20
+
21
+    int getWins() {
22
+        return wins;
23
+    }
24
+
25
+    int getLosses() {
26
+        return losses;
27
+    }
28
+
29
+    int getDraws() {
30
+        return draws;
31
+    }
32
+
33
+    void applyResult(final Result result) {
34
+        switch (result) {
35
+            case WIN: wins++; break;
36
+            case DRAW: draws++; break;
37
+            case LOSS: losses++; break;
38
+        }
39
+    }
40
+
41
+}

+ 62
- 0
exercises/tournament/.meta/src/reference/java/Tournament.java Просмотреть файл

1
+import java.util.HashMap;
2
+import java.util.Map;
3
+import java.util.regex.Pattern;
4
+
5
+class Tournament {
6
+
7
+    private static Pattern separatorPattern = Pattern.compile(";");
8
+    private static Pattern newlinePattern = Pattern.compile("\\n");
9
+
10
+    private Map<String, TeamResult> results;
11
+
12
+    Tournament() {
13
+        results = new HashMap<>();
14
+    }
15
+
16
+    String printTable() {
17
+        StringBuilder sb = new StringBuilder();
18
+        sb.append(String.format("%-30s | %2s | %2s | %2s | %2s | %2s\n",
19
+                "Team", "MP", "W", "D", "L", "P"));
20
+        results.entrySet()
21
+                .stream()
22
+                .sorted(Tournament::comparator)
23
+                .forEach(e -> sb.append(
24
+                        String.format("%-30s | %2d | %2d | %2d | %2d | %2d\n",
25
+                                e.getKey(), e.getValue().getPlayed(), e.getValue().getWins(), e.getValue().getDraws(),
26
+                                e.getValue().getLosses(), e.getValue().getPoints())));
27
+        return sb.toString();
28
+    }
29
+
30
+    private static int comparator(Map.Entry<String, TeamResult> teamA, Map.Entry<String, TeamResult> teamB) {
31
+        int compareByPoints = Integer.compare(teamB.getValue().getPoints(), teamA.getValue().getPoints());
32
+        return compareByPoints == 0 ? teamA.getKey().compareTo(teamB.getKey()) : compareByPoints;
33
+    }
34
+
35
+    void applyResults(final String resultString) {
36
+        String[] matches = newlinePattern.split(resultString);
37
+        for (String matchString: matches) {
38
+            String[] column = separatorPattern.split(matchString);
39
+            final TeamResult home = results.getOrDefault(column[0], new TeamResult());
40
+            final TeamResult away = results.getOrDefault(column[1], new TeamResult());
41
+            final Result result = Result.valueOf(column[2].toUpperCase());
42
+            switch (result) {
43
+                case WIN:
44
+                    home.applyResult(Result.WIN);
45
+                    away.applyResult(Result.LOSS);
46
+                    break;
47
+                case LOSS:
48
+                    home.applyResult(Result.LOSS);
49
+                    away.applyResult(Result.WIN);
50
+                    break;
51
+                case DRAW:
52
+                    home.applyResult(Result.DRAW);
53
+                    away.applyResult(Result.DRAW);
54
+                    break;
55
+            }
56
+            results.put(column[0], home);
57
+            results.put(column[1], away);
58
+        }
59
+    }
60
+
61
+
62
+}

+ 78
- 0
exercises/tournament/README.md Просмотреть файл

1
+# Tournament
2
+
3
+Tally the results of a small football competition.
4
+
5
+Based on an input file containing which team played against which and what the
6
+outcome was, create a file with a table like this:
7
+
8
+```
9
+Team                           | MP |  W |  D |  L |  P
10
+Devastating Donkeys            |  3 |  2 |  1 |  0 |  7
11
+Allegoric Alaskans             |  3 |  2 |  0 |  1 |  6
12
+Blithering Badgers             |  3 |  1 |  0 |  2 |  3
13
+Courageous Californians        |  3 |  0 |  1 |  2 |  1
14
+```
15
+
16
+What do those abbreviations mean?
17
+
18
+- MP: Matches Played
19
+- W: Matches Won
20
+- D: Matches Drawn (Tied)
21
+- L: Matches Lost
22
+- P: Points
23
+
24
+A win earns a team 3 points. A draw earns 1. A loss earns 0.
25
+
26
+The outcome should be ordered by points, descending. In case of a tie, teams are ordered alphabetically.
27
+
28
+###
29
+
30
+Input
31
+
32
+Your tallying program will receive input that looks like:
33
+
34
+```
35
+Allegoric Alaskans;Blithering Badgers;win
36
+Devastating Donkeys;Courageous Californians;draw
37
+Devastating Donkeys;Allegoric Alaskans;win
38
+Courageous Californians;Blithering Badgers;loss
39
+Blithering Badgers;Devastating Donkeys;loss
40
+Allegoric Alaskans;Courageous Californians;win
41
+```
42
+
43
+The result of the match refers to the first team listed. So this line
44
+
45
+```
46
+Allegoric Alaskans;Blithering Badgers;win
47
+```
48
+
49
+Means that the Allegoric Alaskans beat the Blithering Badgers.
50
+
51
+This line:
52
+
53
+```
54
+Courageous Californians;Blithering Badgers;loss
55
+```
56
+
57
+Means that the Blithering Badgers beat the Courageous Californians.
58
+
59
+And this line:
60
+
61
+```
62
+Devastating Donkeys;Courageous Californians;draw
63
+```
64
+
65
+Means that the Devastating Donkeys and Courageous Californians tied.
66
+
67
+
68
+To run the tests:
69
+
70
+```sh
71
+$ gradle test
72
+```
73
+
74
+For more detailed info about the Java track see the [help page](http://exercism.io/languages/java).
75
+
76
+
77
+## Submitting Incomplete Solutions
78
+It's possible to submit an incomplete solution so you can see how others have completed the exercise.

+ 18
- 0
exercises/tournament/build.gradle Просмотреть файл

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
+}

.Rhistory → exercises/tournament/src/main/java/.keep Просмотреть файл


+ 160
- 0
exercises/tournament/src/test/java/TournamentTest.java Просмотреть файл

1
+import org.junit.Before;
2
+import org.junit.Ignore;
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.assertEquals;
6
+
7
+public class TournamentTest {
8
+
9
+    private Tournament tournament;
10
+
11
+    @Before
12
+    public void setUp() {
13
+        tournament = new Tournament();
14
+    }
15
+
16
+    @Test
17
+    public void justTheHeaderIfNoInput() {
18
+        assertEquals("Team                           | MP |  W |  D |  L |  P\n", tournament.printTable());
19
+    }
20
+
21
+    @Ignore("Remove to run test")
22
+    @Test
23
+    public void aWinIsThreePointsALossIsZeroPoints() {
24
+        tournament.applyResults("Allegoric Alaskans;Blithering Badgers;win");
25
+        assertEquals(
26
+                "Team                           | MP |  W |  D |  L |  P\n" +
27
+                "Allegoric Alaskans             |  1 |  1 |  0 |  0 |  3\n" +
28
+                "Blithering Badgers             |  1 |  0 |  0 |  1 |  0\n",
29
+                tournament.printTable());
30
+    }
31
+
32
+    @Ignore("Remove to run test")
33
+    @Test
34
+    public void aWinCanAlsoBeExpressedAsALoss() {
35
+        tournament.applyResults("Blithering Badgers;Allegoric Alaskans;loss");
36
+        assertEquals(
37
+                "Team                           | MP |  W |  D |  L |  P\n" +
38
+                "Allegoric Alaskans             |  1 |  1 |  0 |  0 |  3\n" +
39
+                "Blithering Badgers             |  1 |  0 |  0 |  1 |  0\n",
40
+                tournament.printTable());
41
+    }
42
+
43
+    @Ignore("Remove to run test")
44
+    @Test
45
+    public void aDifferentTeamCanWin() {
46
+        tournament.applyResults("Blithering Badgers;Allegoric Alaskans;win");
47
+        assertEquals(
48
+                "Team                           | MP |  W |  D |  L |  P\n" +
49
+                "Blithering Badgers             |  1 |  1 |  0 |  0 |  3\n" +
50
+                "Allegoric Alaskans             |  1 |  0 |  0 |  1 |  0\n",
51
+                tournament.printTable());
52
+    }
53
+
54
+    @Ignore("Remove to run test")
55
+    @Test
56
+    public void aDrawIsOnePointEach() {
57
+        tournament.applyResults( "Allegoric Alaskans;Blithering Badgers;draw");
58
+        assertEquals(
59
+                "Team                           | MP |  W |  D |  L |  P\n" +
60
+                "Allegoric Alaskans             |  1 |  0 |  1 |  0 |  1\n" +
61
+                "Blithering Badgers             |  1 |  0 |  1 |  0 |  1\n",
62
+                tournament.printTable());
63
+    }
64
+
65
+    @Ignore("Remove to run test")
66
+    @Test
67
+    public void thereCanBeMoreThanOneMatch() {
68
+        tournament.applyResults(
69
+                "Allegoric Alaskans;Blithering Badgers;win\n" +
70
+                "Allegoric Alaskans;Blithering Badgers;win");
71
+        assertEquals(
72
+                "Team                           | MP |  W |  D |  L |  P\n" +
73
+                "Allegoric Alaskans             |  2 |  2 |  0 |  0 |  6\n" +
74
+                "Blithering Badgers             |  2 |  0 |  0 |  2 |  0\n",
75
+                tournament.printTable());
76
+    }
77
+
78
+    @Ignore("Remove to run test")
79
+    @Test
80
+    public void thereCanBeMoreThanOneWinner() {
81
+        tournament.applyResults(
82
+                "Allegoric Alaskans;Blithering Badgers;loss\n" +
83
+                "Allegoric Alaskans;Blithering Badgers;win");
84
+        assertEquals(
85
+                "Team                           | MP |  W |  D |  L |  P\n" +
86
+                "Allegoric Alaskans             |  2 |  1 |  0 |  1 |  3\n" +
87
+                "Blithering Badgers             |  2 |  1 |  0 |  1 |  3\n",
88
+                tournament.printTable());
89
+    }
90
+
91
+    @Ignore("Remove to run test")
92
+    @Test
93
+    public void thereCanBeMoreThanTwoTeams() {
94
+        tournament.applyResults(
95
+                "Allegoric Alaskans;Blithering Badgers;win\n" +
96
+                "Blithering Badgers;Courageous Californians;win\n" +
97
+                "Courageous Californians;Allegoric Alaskans;loss");
98
+        assertEquals(
99
+                "Team                           | MP |  W |  D |  L |  P\n" +
100
+                "Allegoric Alaskans             |  2 |  2 |  0 |  0 |  6\n" +
101
+                "Blithering Badgers             |  2 |  1 |  0 |  1 |  3\n" +
102
+                "Courageous Californians        |  2 |  0 |  0 |  2 |  0\n",
103
+                tournament.printTable());
104
+    }
105
+
106
+    @Ignore("Remove to run test")
107
+    @Test
108
+    public void typicalInput() {
109
+        tournament.applyResults(
110
+                "Allegoric Alaskans;Blithering Badgers;win\n" +
111
+                "Devastating Donkeys;Courageous Californians;draw\n" +
112
+                "Devastating Donkeys;Allegoric Alaskans;win\n" +
113
+                "Courageous Californians;Blithering Badgers;loss\n" +
114
+                "Blithering Badgers;Devastating Donkeys;loss\n" +
115
+                "Allegoric Alaskans;Courageous Californians;win");
116
+        assertEquals(
117
+                "Team                           | MP |  W |  D |  L |  P\n" +
118
+                "Devastating Donkeys            |  3 |  2 |  1 |  0 |  7\n" +
119
+                "Allegoric Alaskans             |  3 |  2 |  0 |  1 |  6\n" +
120
+                "Blithering Badgers             |  3 |  1 |  0 |  2 |  3\n" +
121
+                "Courageous Californians        |  3 |  0 |  1 |  2 |  1\n",
122
+                tournament.printTable());
123
+    }
124
+
125
+    @Ignore("Remove to run test")
126
+    @Test
127
+    public void incompleteCompetition() {
128
+        tournament.applyResults(
129
+                "Allegoric Alaskans;Blithering Badgers;loss\n" +
130
+                "Devastating Donkeys;Allegoric Alaskans;loss\n" +
131
+                "Courageous Californians;Blithering Badgers;draw\n" +
132
+                "Allegoric Alaskans;Courageous Californians;win");
133
+        assertEquals(
134
+                "Team                           | MP |  W |  D |  L |  P\n" +
135
+                "Allegoric Alaskans             |  3 |  2 |  0 |  1 |  6\n" +
136
+                "Blithering Badgers             |  2 |  1 |  1 |  0 |  4\n" +
137
+                "Courageous Californians        |  2 |  0 |  1 |  1 |  1\n" +
138
+                "Devastating Donkeys            |  1 |  0 |  0 |  1 |  0\n",
139
+                tournament.printTable());
140
+    }
141
+
142
+    @Ignore("Remove to run test")
143
+    @Test
144
+    public void tiesBrokenAlphabetically() {
145
+        tournament.applyResults(
146
+                "Courageous Californians;Devastating Donkeys;win\n" +
147
+                "Allegoric Alaskans;Blithering Badgers;win\n" +
148
+                "Devastating Donkeys;Allegoric Alaskans;loss\n" +
149
+                "Courageous Californians;Blithering Badgers;win\n" +
150
+                "Blithering Badgers;Devastating Donkeys;draw\n" +
151
+                "Allegoric Alaskans;Courageous Californians;draw");
152
+        assertEquals(
153
+                "Team                           | MP |  W |  D |  L |  P\n" +
154
+                "Allegoric Alaskans             |  3 |  2 |  1 |  0 |  7\n" +
155
+                "Courageous Californians        |  3 |  2 |  1 |  0 |  7\n" +
156
+                "Blithering Badgers             |  3 |  0 |  1 |  2 |  1\n" +
157
+                "Devastating Donkeys            |  3 |  0 |  1 |  2 |  1\n",
158
+                tournament.printTable());
159
+    }
160
+}