Skip to content

Commit 69e8ba1

Browse files
FridaTveitsjwarner-bp
authored andcommitted
Add hints to exercises without starter implementation (exercism#1084)
* Add hints to exercises without starter implementation As exercises with difficulty 5 are the first exercises without starter implementation, they should have a hints file explaining how to fix the compiler errors that occur when an exercise doesn't have any starter implementation. This should be detailed in the policies doc. * flatten-array: regenerate README Also update description for how to generate readme as it was lacking detail.
1 parent 3eb6e52 commit 69e8ba1

4 files changed

Lines changed: 134 additions & 2 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ You can do this by:
171171

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

174-
3. Run `configlet generate . --only name_of_new_exercise` from the root of this repository.
174+
3. Run `configlet generate . --only name_of_new_exercise --spec-path path_to_problem_specifications` from the root of this repository.
175175

176176
* Check if there is canonical data for the exercise you're adding.
177177
This can be found at `https://github.com/exercism/problem-specifications/tree/master/exercises/EXERCISE-SLUG/canonical-data.json`.

‎POLICIES.md‎

Lines changed: 13 additions & 1 deletion
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)
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)
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) |
@@ -79,3 +79,15 @@ References: [[1](https://github.com/exercism/java/issues/395#issue-215734887)]
7979
> 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.
8080
8181
References: [[1](https://github.com/exercism/java/issues/697)]
82+
83+
### Add hint for the first exercises without starter implementation
84+
85+
> According to the starter implementation policy, any exercise with difficulty 4 or lower should have starter implementation.
86+
> Any exercise with difficulty 5 or above will have no starter implementation (unless its signature is very complicated).
87+
> This could be confusing to users when tackling their first exercise with difficulty 5 when they are used to starter implementation being provided.
88+
89+
> Therefore a hints.md file should be added to the .meta directory for every exercise with difficulty 5.
90+
> This file should explain what they need to do when there is no starter implementation.
91+
> The files should all be the same so you can copy it from any other exercise with difficulty 5, e.g. [flatten-array](https://github.com/exercism/java/tree/master/exercises/flatten-array/.meta/hints.md).
92+
93+
> 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.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Since this exercise has difficulty 5 it doesn't come with any starter implementation.
2+
This is so that you get to practice creating classes and methods which is an important part of programming in Java.
3+
It does mean that when you first try to run the tests, they won't compile.
4+
They will give you an error similar to:
5+
```
6+
path-to-exercism-dir\exercism\java\name-of-exercise\src\test\java\ExerciseClassNameTest.java:14: error: cannot find symbol
7+
ExerciseClassName exerciseClassName = new ExerciseClassName();
8+
^
9+
symbol: class ExerciseClassName
10+
location: class ExerciseClassNameTest
11+
```
12+
This error occurs because the test refers to a class that hasn't been created yet (`ExerciseClassName`).
13+
To resolve the error you need to add a file matching the class name in the error to the `src/main/java` directory.
14+
For example, for the error above you would add a file called `ExerciseClassName.java`.
15+
16+
When you try to run the tests again you will get slightly different errors.
17+
You might get an error similar to:
18+
```
19+
constructor ExerciseClassName in class ExerciseClassName cannot be applied to given types;
20+
ExerciseClassName exerciseClassName = new ExerciseClassName("some argument");
21+
^
22+
required: no arguments
23+
found: String
24+
reason: actual and formal argument lists differ in length
25+
```
26+
This error means that you need to add a [constructor](https://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html) to your new class.
27+
If you don't add a constructor, Java will add a default one for you.
28+
This default constructor takes no arguments.
29+
So if the tests expect your class to have a constructor which takes arguments, then you need to create this constructor yourself.
30+
In the example above you could add:
31+
```
32+
ExerciseClassName(String input) {
33+
34+
}
35+
```
36+
That should make the error go away, though you might need to add some more code to your constructor to make the test pass!
37+
38+
You might also get an error similar to:
39+
```
40+
error: cannot find symbol
41+
assertEquals(expectedOutput, exerciseClassName.someMethod());
42+
^
43+
symbol: method someMethod()
44+
location: variable exerciseClassName of type ExerciseClassName
45+
```
46+
This error means that you need to add a method called `someMethod` to your new class.
47+
In the example above you would add:
48+
```
49+
String someMethod() {
50+
return "";
51+
}
52+
```
53+
Make sure the return type matches what the test is expecting.
54+
You can find out which return type it should have by looking at the type of object it's being compared to in the tests.
55+
Or you could set your method to return some random type (e.g. `void`), and run the tests again.
56+
The new error should tell you which type it's expecting.
57+
58+
After having resolved these errors you should be ready to start making the tests pass!

‎exercises/flatten-array/README.md‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,68 @@ input: [1,[2,3,null,4],[null],5]
1010

1111
output: [1,2,3,4,5]
1212

13+
# Java Tips
14+
15+
Since this exercise has difficulty 5 it doesn't come with any starter implementation.
16+
This is so that you get to practice creating classes and methods which is an important part of programming in Java.
17+
It does mean that when you first try to run the tests, they won't compile.
18+
They will give you an error similar to:
19+
```
20+
path-to-exercism-dir\exercism\java\name-of-exercise\src\test\java\ExerciseClassNameTest.java:14: error: cannot find symbol
21+
ExerciseClassName exerciseClassName = new ExerciseClassName();
22+
^
23+
symbol: class ExerciseClassName
24+
location: class ExerciseClassNameTest
25+
```
26+
This error occurs because the test refers to a class that hasn't been created yet (`ExerciseClassName`).
27+
To resolve the error you need to add a file matching the class name in the error to the `src/main/java` directory.
28+
For example, for the error above you would add a file called `ExerciseClassName.java`.
29+
30+
When you try to run the tests again you will get slightly different errors.
31+
You might get an error similar to:
32+
```
33+
constructor ExerciseClassName in class ExerciseClassName cannot be applied to given types;
34+
ExerciseClassName exerciseClassName = new ExerciseClassName("some argument");
35+
^
36+
required: no arguments
37+
found: String
38+
reason: actual and formal argument lists differ in length
39+
```
40+
This error means that you need to add a [constructor](https://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html) to your new class.
41+
If you don't add a constructor, Java will add a default one for you.
42+
This default constructor takes no arguments.
43+
So if the tests expect your class to have a constructor which takes arguments, then you need to create this constructor yourself.
44+
In the example above you could add:
45+
```
46+
ExerciseClassName(String input) {
47+
48+
}
49+
```
50+
That should make the error go away, though you might need to add some more code to your constructor to make the test pass!
51+
52+
You might also get an error similar to:
53+
```
54+
error: cannot find symbol
55+
assertEquals(expectedOutput, exerciseClassName.someMethod());
56+
^
57+
symbol: method someMethod()
58+
location: variable exerciseClassName of type ExerciseClassName
59+
```
60+
This error means that you need to add a method called `someMethod` to your new class.
61+
In the example above you would add:
62+
```
63+
String someMethod() {
64+
return "";
65+
}
66+
```
67+
Make sure the return type matches what the test is expecting.
68+
You can find out which return type it should have by looking at the type of object it's being compared to in the tests.
69+
Or you could set your method to return some random type (e.g. `void`), and run the tests again.
70+
The new error should tell you which type it's expecting.
71+
72+
After having resolved these errors you should be ready to start making the tests pass!
73+
74+
1375
# Running the tests
1476

1577
You can run all the tests for an exercise by entering

0 commit comments

Comments
 (0)