Skip to content

Commit da4c3dd

Browse files
Merge pull request exercism#1 from exercism/master
Merge
2 parents 0500481 + f2335d4 commit da4c3dd

107 files changed

Lines changed: 3304 additions & 661 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CONTRIBUTING.md‎

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* [Advanced: Complete Local Setup](#advanced-complete-local-setup)
1010
* [Tip: `gradle clean` before `exercism fetch`](#tip-gradle-clean-before-exercism-fetch)
1111
* [Adding a New Exercise](#adding-a-new-exercise)
12+
* [Updating the READMEs](#updating-the-readmes)
13+
* [Checking tests are up to date](#checking-tests-are-up-to-date)
1214

1315
## Overview
1416

@@ -22,14 +24,13 @@ For general guidelines about contributing to Exercism see the [Exercism contribu
2224

2325
Hi! Thanks for contributing to the Exercism Java track!
2426

25-
Before opening your pull request, please review the track policies linked below and make sure your changes comply with them all. This helps us focus our review time on the more important aspects of your changes.
27+
Before opening your pull request, please review the [track policies](https://github.com/exercism/java/blob/master/POLICIES.md) and make sure your changes comply with them all. This helps us focus our review time on the more important aspects of your changes.
2628

27-
- [Prefer instance methods](https://github.com/exercism/java/blob/master/POLICIES.md#prefer-instance-methods)
28-
- [Starter implementations](https://github.com/exercism/java/blob/master/POLICIES.md#starter-implementations)
29-
- [Ignore noninitial tests](https://github.com/exercism/java/blob/master/POLICIES.md#ignore-noninitial-tests)
30-
- [Multiple file submissions](https://github.com/exercism/java/blob/master/POLICIES.md#multiple-file-submissions)
29+
Also please only address one issue per pull request. This makes it easier for us to review it, and it means that if we request changes to the fix for one issue, it won't prevent to a fix for another issue being merged.
3130

32-
One last thing to note before you get started. When you fork the repository and you want to sync your fork, you can perform a [`git rebase`](https://git-scm.com/docs/git-rebase). This is preferred over merging the changes because merging leads to a dirty commit history whereas performing a rebase adds in those changes without making extra commit messages. However, this is only preferred, so don't worry about it too much.
31+
It's perfectly fine to have more than one pull request open at a time. In that case it's important to keep the work for each pull request on a separate [branch](https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell) to prevent unrelated commits being added to your pull request. This is good practice to do always, even if you only have one pull request open.
32+
33+
One last thing to note before you get started. When you fork the repository and you want to [sync your fork](https://help.github.com/articles/syncing-a-fork/), you can perform a [`git rebase`](https://git-scm.com/docs/git-rebase). This is preferred over merging the changes because merging leads to a dirty commit history whereas performing a rebase adds in those changes without making extra commit messages. However, this is only preferred, so don't worry about it too much.
3334

3435
## Contributing With Minimal Setup
3536

@@ -146,10 +147,12 @@ Any completely new exercise needs to be added and accepted there before it can b
146147

147148
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).
148149
Please review this before porting an exercise to the Java track.
149-
150+
150151
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.
151152
Please make sure no one else has a pull request open to implement your chosen exercise before you start.
152-
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.
153+
154+
It might also be a good idea to open a WIP pull request to make it clear to others that you are working on this exercise.
155+
This can just be a pull request with an empty commit that states which new exercise you're working on, with WIP (work in progress) in the title so that the maintainers know that it's not ready for review yet.
153156

154157
The Java specific details you need to know about adding an exercise are:
155158

@@ -167,7 +170,7 @@ The `build.gradle` file can just be copied from any other exercise submodule.
167170
The `README.md` file can be generated using [configlet](https://github.com/exercism/configlet/releases).
168171
You can do this by:
169172

170-
1. Download configlet and put it somewhere in your PATH
173+
1. Download configlet and put it somewhere in your [PATH](https://en.wikipedia.org/wiki/PATH_(variable))
171174

172175
2. Clone [the problem-specifications repository](https://github.com/exercism/problem-specifications).
173176

@@ -181,5 +184,37 @@ If there is canonical data available you also need to create a file at `exercise
181184
The canonical data version can be found at the top of the canonical data file for that exercise.
182185
See other exercises, e.g. [acronym](https://github.com/exercism/java/tree/master/exercises/acronym/.meta), for an example `version` file.
183186

187+
* Make sure you've followed the [track policies](https://github.com/exercism/java/blob/master/POLICIES.md), especially the ones for exercise added/updated.
188+
184189
Hopefully that should be enough information to help you port an exercise to the Java track.
185190
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.
191+
192+
## Updating the READMEs
193+
194+
The `README.md` files are generated from the exercise descriptions in [problem specifications](https://github.com/exercism/problem-specifications/tree/master/exercises).
195+
They need to be regenerated regularly so that any changes to the descriptions in problem specifications propagate to our READMEs.
196+
This can be done using [configlet](https://github.com/exercism/configlet/releases):
197+
198+
1. Download configlet and put it somewhere in your [PATH](https://en.wikipedia.org/wiki/PATH_(variable))
199+
200+
2. Clone [the problem-specifications repository](https://github.com/exercism/problem-specifications).
201+
202+
3. Run `configlet generate . --spec-path path_to_problem_specifications` from the root of this repository.
203+
204+
## Checking tests are up to date
205+
206+
The tests for each exercise should follow the canonical data in [problem specifications](https://github.com/exercism/problem-specifications/tree/master/exercises) as closely as possible.
207+
The canonical data can change quite regularly, in which case the [canonical data version](https://github.com/exercism/problem-specifications#test-data-versioning) for that exercise will be updated.
208+
209+
We keep track of which version of the canonical data each exercise implements in a version file, for example: https://github.com/exercism/java/blob/master/exercises/two-fer/.meta/version.
210+
Not all exercises have canonical data in problem specifications.
211+
For those that don't we don't add a version file.
212+
213+
We have [a script](https://github.com/exercism/java/blob/master/scripts/canonical_data_check.sh) which can check if these version are up to date with the ones in problem specification.
214+
This script can be used to check if any version files, tests and reference implementations need updating.
215+
216+
To run this script:
217+
218+
1. Clone [the problem-specifications repository](https://github.com/exercism/problem-specifications).
219+
220+
2. Run `./scripts/canonical_data_check.sh -t . -s --spec-path path_to_problem_specifications` from the root of this repository.

‎POLICIES.md‎

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Our policies are not set-in-stone. They represent directions chosen at a point i
1717

1818
| Track Event | Policies to review |
1919
|:------------|:-----------------|
20-
| Exercise added/updated | [Prefer instance methods](#prefer-instance-methods); [Avoid using final](#avoid-using-final); [Adhere to best practices](#adhere-to-best-practices); [Starter implementations](#starter-implementations); [Ignore noninitial tests](#ignore-noninitial-tests); [Multiple file submissions](#multiple-file-submissions); [Name test class after class under test](#name-test-class-after-class-under-test); [Add hint for the first exercises without starter implementation](#add-hint-for-the-first-exercises-without-starter-implementation)
20+
| Exercise added/updated | [Prefer instance methods](#prefer-instance-methods); [Avoid using final](#avoid-using-final); [Adhere to best practices](#adhere-to-best-practices); [Starter implementations](#starter-implementations); [Ignore noninitial tests](#ignore-noninitial-tests); [Multiple file submissions](#multiple-file-submissions); [Name test class after class under test](#name-test-class-after-class-under-test); [Add hint for the first exercises without starter implementation](#add-hint-for-the-first-exercises-without-starter-implementation); [Reference tutorial in the first exercises](#reference-tutorial-in-the-first-exercises); [Avoid returning null](#avoid-returning-null); [Use ExpectedException](#use-expectedexception)
2121
| Track rearranged | [Starter implementations](#starter-implementations); [Multiple file submissions](#multiple-file-submissions) |
2222
| New issue observed in track | [Good first patches](#good-first-patches) |
2323
| "Good first patch" issue completed | [Good first patches](#good-first-patches) |
@@ -46,7 +46,33 @@ References: [[1](https://github.com/exercism/java/issues/178)], [[2](https://git
4646
### Adhere to best practices
4747

4848
> Ensure that all Java code adheres to the best practices listed below:
49-
> - minimize the accessibility of classes and members ([Effective Java, item 13](http://jtechies.blogspot.com/2012/07/item-13-minimize-accessibility-of.html))
49+
> - Minimize the accessibility of classes and members ([Effective Java, item 13](http://jtechies.blogspot.com/2012/07/item-13-minimize-accessibility-of.html))
50+
> - Always use curly brackest in if statements. This makes your code easier to maintain and easier to read ([Oracle style guide, item 7.4](http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-142311.html#431))
51+
```java
52+
// Please do this
53+
if (condition) {
54+
doSomething();
55+
}
56+
57+
// Please don't do this
58+
if (condition)
59+
doSomething();
60+
61+
if (condition) doSomething();
62+
```
63+
> - Always put opening curly bracket not on a newline ([Oracle style guide, item 7.2](http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-142311.html#431))
64+
```java
65+
// Please do this
66+
for (int i = 0; i < 10; i++) {
67+
...
68+
}
69+
70+
// Please don't do this
71+
for (int i = 0; i < 10; i++)
72+
{
73+
...
74+
}
75+
```
5076

5177
### Ignore noninitial tests
5278

@@ -74,7 +100,7 @@ References: [[1](https://github.com/exercism/java/issues/395#issue-215734887)]
74100

75101
### Name test class after class under test
76102

77-
> If you're testing a class called `SomeClassName` then your test class should be called `SomeClassNameTest`.
103+
> If you're testing a class called `SomeClassName` then your test class should be called `SomeClassNameTest`.
78104
79105
> The exception to this is if the tests are split into several test classes where each test class tests different functionality. In that case each class should be named `SomeClassNameFunctionalityTest` where `Functionality` is the name of the functionality to be tested in that class. See the [clock exercise](https://github.com/exercism/java/tree/master/exercises/clock) as an example.
80106
@@ -93,3 +119,42 @@ References: [[1](https://github.com/exercism/java/issues/697)]
93119
> We add the file to every exercise with difficulty 5 because the structure of the track means that we don't know which exercise will be the first one without starter implementation that a user will be faced with.
94120
95121
References: [[1](https://github.com/exercism/java/issues/1075)]
122+
123+
### Reference tutorial in the first exercises
124+
125+
> The hello world exercise has an extensive tutorial on how to solve exercism exercises.
126+
> This tutorial would probably be useful to have as a reference when solving some of the other earlier exercises as well.
127+
> Therefore any exercise with difficulty less than 3 should have a hints.md file which references [the hello world tutorial](https://github.com/exercism/java/blob/master/exercises/hello-world/TUTORIAL.md).
128+
129+
References: [[1](https://github.com/exercism/java/issues/1389)]
130+
131+
### Avoid returning null
132+
133+
> The [canonical data](https://github.com/exercism/problem-specifications/tree/master/exercises) for each exercise intentionally doesn't deal with error handling.
134+
> When an error has occured or a method can't return anything, the canonical data will just mark that as `"expected": null`.
135+
> This is because error handling varies from language to language, so the canonical data is leaving it up to each language track to decide how to deal with those situations.
136+
> It doesn't mean that the method needs to return `null`.
137+
138+
> In Java it's considered bad practice to return `null`.
139+
> If you return `null` then the user of the method has to remember to check for `null` and they have to look at the implementation of the method to find out that this is necessary.
140+
141+
> It's considered best practice to deal with errors and unexpected circumstances by throwing exceptions.
142+
> If you throw an exception then you force the user to deal with the problem.
143+
> You can either define your own exception (see [the triangle exercise](https://github.com/exercism/java/blob/master/exercises/triangle/.meta/src/reference/java/TriangleException.java) for an example) or use a predefined one (see [the collatz-conjecture exercise](https://github.com/exercism/java/blob/master/exercises/collatz-conjecture/src/test/java/CollatzCalculatorTest.java) for an example).
144+
145+
> Another option is to use [Optionals](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html).
146+
> This can be more suitable if the case you want to deal with isn't an exceptional occurence, but rather an expected scenario, e.g. a search method not finding what it was searching for.
147+
> See [the word-search exercise](https://github.com/exercism/java/blob/master/exercises/word-search/src/test/java/WordSearcherTest.java) for an example where `Optional` is used.
148+
149+
References: [[1](https://www.codebyamir.com/blog/stop-returning-null-in-java)]
150+
151+
### Use ExceptedException
152+
153+
> Some exercises expect exceptions to be thrown in the tests.
154+
> The exercises on this track are all using JUnit's [`ExpectedException`](http://junit.org/junit4/javadoc/4.12/org/junit/rules/ExpectedException.html) `@Rule` feature to support that instead of `@Test(expected = SomeException.class)`.
155+
> `ExpectedException` is more powerful than using the `@Test` annotation, since with `ExpectedException` you can also inspect the exception's error message and other properties.
156+
> To be consistent, please use `ExpectedException` whenever you expect an exception to be thrown.
157+
158+
> See [the triangle tests](https://github.com/exercism/java/blob/master/exercises/triangle/src/test/java/TriangleTest.java) for an example of where `ExpectedException` is used.
159+
160+
References: [[1](https://github.com/junit-team/junit4/wiki/Exception-testing)]

‎config.json‎

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
"loops",
198198
"strings"
199199
],
200-
"unlocked_by": "rna-transcription",
200+
"unlocked_by": "two-fer",
201201
"uuid": "331073b3-bd1a-4868-b767-a64ce9fd9d97"
202202
},
203203
{
@@ -395,6 +395,17 @@
395395
"unlocked_by": null,
396396
"uuid": "8dfc2f0d-1141-46e9-95e2-6f35ccf6f160"
397397
},
398+
{
399+
"core": false,
400+
"difficulty": 4,
401+
"slug": "error-handling",
402+
"topics": [
403+
"exception_handling",
404+
"optional_values"
405+
],
406+
"unlocked_by": "triangle",
407+
"uuid": "846ae792-7ca7-43e1-b523-bb1ec9fa08eb"
408+
},
398409
{
399410
"core": false,
400411
"difficulty": 4,
@@ -422,6 +433,21 @@
422433
"unlocked_by": "hello-world",
423434
"uuid": "c3e89c7c-3a8a-4ddc-b653-9b0ff9e1d7d8"
424435
},
436+
{
437+
"core": false,
438+
"difficulty": 4,
439+
"slug": "variable-length-quantity",
440+
"topics": [
441+
"bitwise_operations",
442+
"conditionals",
443+
"exception_handling",
444+
"lists",
445+
"loops",
446+
"transforming"
447+
],
448+
"unlocked_by": "secret-handshake",
449+
"uuid": "d8a2c7ba-2040-4cfe-ab15-f90b3b61dd89"
450+
},
425451
{
426452
"core": true,
427453
"difficulty": 5,
@@ -615,15 +641,16 @@
615641
{
616642
"core": false,
617643
"difficulty": 5,
618-
"slug": "two-bucket",
644+
"slug": "grep",
619645
"topics": [
620-
"algorithms",
621-
"loops",
622-
"conditionals",
623-
"mathematics"
646+
"pattern_matching",
647+
"strings",
648+
"files",
649+
"filtering",
650+
"searching"
624651
],
625-
"unlocked_by": "triangle",
626-
"uuid": "210bf628-b385-443b-8329-3483cc6e8d7e"
652+
"unlocked_by": "robot-name",
653+
"uuid": "9c15ddab-7b52-43d4-b38c-0bf635b363c3"
627654
},
628655
{
629656
"core": false,
@@ -911,6 +938,19 @@
911938
"unlocked_by": "rotational-cipher",
912939
"uuid": "6e4ad4ed-cc02-4132-973d-b9163ba0ea3d"
913940
},
941+
{
942+
"core": false,
943+
"difficulty": 7,
944+
"slug": "two-bucket",
945+
"topics": [
946+
"algorithms",
947+
"loops",
948+
"conditionals",
949+
"mathematics"
950+
],
951+
"unlocked_by": "triangle",
952+
"uuid": "210bf628-b385-443b-8329-3483cc6e8d7e"
953+
},
914954
{
915955
"core": false,
916956
"difficulty": 7,
@@ -1063,6 +1103,32 @@
10631103
"unlocked_by": "linked-list",
10641104
"uuid": "25d2c7a5-1ec8-464a-b3de-ad1b27464ef1"
10651105
},
1106+
{
1107+
"core": false,
1108+
"difficulty": 7,
1109+
"slug": "go-counting",
1110+
"topics": [
1111+
"algorithms",
1112+
"loops",
1113+
"conditionals",
1114+
"games"
1115+
],
1116+
"unlocked_by": "scrabble-score",
1117+
"uuid": "2e760ae2-fadd-4d31-9639-c4554e2826e9"
1118+
},
1119+
{
1120+
"core": false,
1121+
"difficulty": 7,
1122+
"slug": "dominoes",
1123+
"topics": [
1124+
"games",
1125+
"algorithms",
1126+
"lists",
1127+
"exception_handling"
1128+
],
1129+
"unlocked_by": "scrabble-score",
1130+
"uuid": "8e3cb20e-623b-4b4d-8a91-d1a51c0911b5"
1131+
},
10661132
{
10671133
"core": false,
10681134
"difficulty": 8,

‎exercises/acronym/src/test/java/AcronymTest.java‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,40 @@ public class AcronymTest {
77

88
@Test
99
public void basic() {
10-
final String phrase = "Portable Network Graphics";
11-
final String expected = "PNG";
10+
String phrase = "Portable Network Graphics";
11+
String expected = "PNG";
1212
assertEquals(expected, new Acronym(phrase).get());
1313
}
1414

1515
@Ignore("Remove to run test")
1616
@Test
1717
public void lowercaseWords() {
18-
final String phrase = "Ruby on Rails";
19-
final String expected = "ROR";
18+
String phrase = "Ruby on Rails";
19+
String expected = "ROR";
2020
assertEquals(expected, new Acronym(phrase).get());
2121
}
2222

2323
@Ignore("Remove to run test")
2424
@Test
2525
public void punctuation() {
26-
final String phrase = "First In, First Out";
27-
final String expected = "FIFO";
26+
String phrase = "First In, First Out";
27+
String expected = "FIFO";
2828
assertEquals(expected, new Acronym(phrase).get());
2929
}
3030

3131
@Ignore("Remove to run test")
3232
@Test
3333
public void NonAcronymAllCapsWord() {
34-
final String phrase = "GNU Image Manipulation Program";
35-
final String expected = "GIMP";
34+
String phrase = "GNU Image Manipulation Program";
35+
String expected = "GIMP";
3636
assertEquals(expected, new Acronym(phrase).get());
3737
}
3838

3939
@Ignore("Remove to run test")
4040
@Test
4141
public void punctuationWithoutWhitespace() {
42-
final String phrase = "Complementary metal-oxide semiconductor";
43-
final String expected = "CMOS";
42+
String phrase = "Complementary metal-oxide semiconductor";
43+
String expected = "CMOS";
4444
assertEquals(expected, new Acronym(phrase).get());
4545
}
4646

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.0
1+
2.3.0

0 commit comments

Comments
 (0)