You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,3 +79,15 @@ We expressed above a concern for saving student's attention / motivation / time.
79
79
Pull requests for translations, curiculum tweaks or new capabilities are welcome.
80
80
81
81
When submitting bugs, please submit a zip file of the koans in a state exhibiting the issue.
82
+
83
+
## Testing
84
+
85
+
Testing this kind of project is challenging for a few reasons, main ones being:
86
+
87
+
1. By design, we don't have a build tool (Gradle or Maven for example), nor access to any libraries. So no JUnit on hand.
88
+
2. We would not want to include solutions to the koans within the project, because the students might stumble on them, which would affect their learning.
89
+
90
+
For 1., we have created a mini test framework in `engine.test.runner` in order to run unit and integration tests of the koans engine. Tests are located in `engine.test`. To run those tests, simply run the `engine.test.runner.TestRunner.main` method.
91
+
92
+
For 2., we have created a [brother project](https://github.com/jletroui/FrcJavaKoansTests) testing the koans themselves.
Copy file name to clipboardExpand all lines: src/main/java/bonuses/english/AboutInterfaces.java
+20-19Lines changed: 20 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -101,8 +101,8 @@ public class AboutInterfaces {
101
101
*
102
102
* --------- TIPS --------------
103
103
*
104
-
* Sometimes, it is tedious to create a class file to implement an interface just for one occasion.
105
-
* In these situation, you can implement the interface in an anonymous class. It is anonymous, because it does not have a name.
104
+
* Sometimes, creating a file and a public class is a lot of work when we implement a simple interface, and we only use it in a single place.
105
+
* In such a situation, you can implement the interface in an anonymous class. It is anonymous, because it does not have a name.
106
106
* That class is instantiated immediately where it is created. For example:
107
107
*
108
108
* public Weapon toss() {
@@ -115,7 +115,7 @@ public class AboutInterfaces {
115
115
* }
116
116
*
117
117
* When looking at this code, you could be tempted to believe there is a constructor for the interface Weapon, but there is not.
118
-
* We are really creating a class, for which there exists a single object.
118
+
* We are really creating a class, for which the only place we will create objects is this 'toss()' method.
119
119
* The constructor with empty parameters is the one of this nameless class.
120
120
* We can now get and use the tossed weapon this way:
121
121
*
@@ -139,7 +139,7 @@ public class AboutInterfaces {
139
139
*
140
140
* --------- TIPS --------------
141
141
*
142
-
* When an interface have only one method, there is an even shorter form to implement it. You can use what is called a 'lambda method'.
142
+
* When an interface have only one method, there is an even shorter form to implement it. You can create what is called a "lambda method".
143
143
* A 'lambda method' is a stripped down version of a method. Since our example interface 'Weapon' has only a single method 'hit()', we can use this shortcut:
144
144
*
145
145
* For example:
@@ -155,17 +155,17 @@ public class AboutInterfaces {
155
155
* Weapon tossedWeapon = toss();
156
156
* tossedWeapon.hit(zombie);
157
157
*
158
-
* The general syntax for lambda method returning void, or having a body with multiple lines:
158
+
* The general syntax for lambda method having a body with multiple lines is:
159
159
*
160
160
* ([param1Name], [param2Name], ...) -> {
161
161
* // Lambda method body here
162
162
* }
163
163
*
164
-
* If your lambda is having a single expression, you can even skip the parentheses and the 'return':
164
+
* If your lambda is having a single expression, you can even skip the curly brackets and the 'return' statement:
165
165
*
166
166
* ([param1Name], [param2Name], ...) -> // expression here
167
167
*
168
-
* Here are some example of methods and their lambda equivalent (assuming the interface has only one method in it):
168
+
* Here are some example of methods and their lambda equivalent (assuming the interface has only one of these methods in its contract):
169
169
*
170
170
* This interface implementation:
171
171
*
@@ -175,9 +175,7 @@ public class AboutInterfaces {
175
175
*
176
176
* Can be replaced by this lambda:
177
177
*
178
-
* () -> {
179
-
* System.out.println("hello");
180
-
* }
178
+
* () -> System.out.println("hello")
181
179
*
182
180
* This interface implementation:
183
181
*
@@ -223,27 +221,30 @@ public class AboutInterfaces {
223
221
*
224
222
* --------- TIPS --------------
225
223
*
226
-
* Since lambda methods are so useful, a lot of interfaces already exist in the Java standard library, and we don't have to create them ourselves.
224
+
* Note: the {@link java.lang.String} notation allows to show a link to a class in a comment. To see the class, you can [CTRL] + clic on its name.
227
225
*
228
-
* For example:
226
+
* Since lambda methods are so useful, a lot of simple interfaces already exist in the Java standard library, and we don't have to create them ourselves.
227
+
* For example, an interface with a method having the same signature as the 'combine()' method already exists. It is called the {@link java.util.function.IntBinaryOperator}.
228
+
*
229
+
* Other examples:
229
230
*
230
231
* For a lambda taking no parameter, and returning nothing, {@link java.lang.Runnable}:
* The reverse functions, taking nothing as a parameter, but returning something exist as well: {@link java.util.function.IntSupplier}, {@link java.util.function.DoubleSupplier}. etc...
243
+
* The reverse methods, taking no parameter, but returning something exist as well: {@link java.util.function.IntSupplier}, {@link java.util.function.DoubleSupplier}. etc...
* There is also a lot of case where you would need to test a number somehow. This is where interfaces like {@link java.util.function.IntPredicate} shine:
247
+
* There is also a lot of case where you would need to test if a number respect a certain condition. This is where "predicate" interfaces like {@link java.util.function.IntPredicate} shine:
247
248
*
248
249
* IntPredicate isPositive = (number) -> number >= 0;
Copy file name to clipboardExpand all lines: src/main/java/bonuses/french/AboutInterfaces.java
+48-47Lines changed: 48 additions & 47 deletions
Original file line number
Diff line number
Diff line change
@@ -94,28 +94,28 @@ public class AboutInterfaces {
94
94
/**
95
95
* # Anonymous interface implementation
96
96
*
97
-
* Write a method 'getAnonymousCombining' which returns an anonymous implementation of 'bonuses.teachingmaterial.Combining'.
98
-
* The implementation of the combine() method devrait retourner the second number subtracted from the first.
97
+
* Écris une méthode 'getAnonymousCombining' qui retourne une implémentation anonyme de 'bonuses.teachingmaterial.Combining'.
98
+
* L'implémentation de la méthode combine() devrait retourner le 2ème nombre soustrait du 1er.
99
99
*
100
100
* --------- TIPS --------------
101
101
*
102
-
* Sometimes, it is tedious to create a class file to implement an interface just for one occasion.
103
-
* In these situation, you can implement the interface in an anonymous class. It is anonymous, because it does not have a name.
104
-
* That class is instantiated immediately where it is created. For example:
102
+
* Parfois, créer un fichier et une classe publique représente beaucoup de travail lorsque l'on implémente une interface simple, et qu'on l'utilise à un seul endroit dans le code.
103
+
* Dans cette situation, tu peux implémenter une interface dans une classe anonyme. La classe est anonyme car elle n'a pas de nom.
104
+
* Cette classe est instantiée en un object immédiatement où elle est définie. Par exemple:
105
105
*
106
106
* public Weapon toss() {
107
107
* return new Weapon() {
108
108
* @Override
109
109
* public void hit(Monster monster) {
110
-
* // Some code computing and applying damage to the monster, applying some tear and wear on the weapon, etc...
110
+
* // Du code qui calcule et applique le dommage, applique de l'usure à l'arme, etc...
111
111
* }
112
112
* }
113
113
* }
114
114
*
115
-
* When looking at this code, you could be tempted to believe there is a constructor for the interface Weapon, but there is not.
116
-
* We are really creating a class, for which there exists a single object.
117
-
* The constructor with empty parameters is the one of this nameless class.
118
-
* We can now get and use the tossed weapon this way:
115
+
* Quand on considère ce code, on pourrait être tenté de croire qu'il y a un constructeur pour l'interface 'Weapon', mais évidemment, une interface n'a pas de constructeur, puisque c'est un simple "contrat".
116
+
* Ici, nous créons vraiment une classe, pour laquelle le seul endroit où des objets vont être créés est la méthode 'toss()'.
117
+
* Le constructeur sans paramètre est celui de cette classe sans nom.
118
+
* Nous pouvons maintenant utiliser cette arme envoyée de cette manière:
119
119
*
120
120
* Weapon tossedWeapon = toss();
121
121
* tossedWeapon.hit(zombie);
@@ -130,64 +130,62 @@ public class AboutInterfaces {
130
130
131
131
132
132
/**
133
-
* # Lambda methods
133
+
* # Méthodes lambda
134
134
*
135
-
* Write a method 'getLambdaCombining' which returns an lambda method implementing 'bonuses.teachingmaterial.Combining'.
136
-
* The implementation of the combine() method devrait retourner the first number subtracted from the second.
135
+
* Écris une méthode 'getLambdaCombining' qui retourne une méthode lambda implémentant 'bonuses.teachingmaterial.Combining'.
136
+
* L'implémentation de la méthode combine() devrait retourner le 1er nombre soustrait du 2ème.
137
137
*
138
138
* --------- TIPS --------------
139
139
*
140
-
* When an interface have only one method, there is an even shorter form to implement it. You can use what is called a 'lambda method'.
141
-
* A 'lambda method' is a stripped down version of a method. Since our example interface 'Weapon' has only a single method 'hit()', we can use this shortcut:
140
+
* Quand une interface a une seule méthode, il exist une forme encore plus courte pour l'implémenter. Tu peux créer ce que l'on appelle une "méthode lambda".
141
+
* Une "méthode lambda" est une version raccourcie d'une méthode. Comme notre interface exemple 'Weapon' ne contient qu'une seule méthode 'hit()', nous pouvons utiliser ce raccourci.
142
142
*
143
-
* For example:
143
+
* Par example:
144
144
*
145
145
* public Weapon toss() {
146
146
* return (monster) -> {
147
-
* // Some code computing and applying damage to the monster, applying some tear and wear on the weapon, etc..
147
+
* // Du code qui calcule et applique le dommage, applique de l'usure à l'arme, etc...
148
148
* };
149
149
* }
150
150
*
151
-
* We can now get and use the tossed weapon this way:
151
+
* Nous pouvons maintenant utiliser cette arme envoyée de cette manière:
152
152
*
153
153
* Weapon tossedWeapon = toss();
154
154
* tossedWeapon.hit(zombie);
155
155
*
156
-
* The general syntax for lambda method returning void, or having a body with multiple lines:
156
+
* La syntaxe générale pour une méthode lambda dont l'implémentation est constituée de plusieurs lignes est la suivante:
157
157
*
158
-
* ([param1Name], [param2Name], ...) -> {
159
-
* // Lambda method body here
158
+
* ([nomParam1], [nomParam2], ...) -> {
159
+
* // Corps de la méthode lambda ici
160
160
* }
161
161
*
162
-
* If your lambda is having a single expression, you can even skip the parentheses and the 'return':
162
+
* Si ta lambda a une seule expression, tu peux même enlever les accolades et l'instruction 'return':
163
163
*
164
-
* ([param1Name], [param2Name], ...) -> // expression here
* Here are some example of methods and their lambda equivalent (assuming the interface has only one method in it):
166
+
* Voici quelques exemples de méthodes et leur équivalent lambda (en supposant que l'interface n'a qu'une seule de ces méthodes dans son contrat):
167
167
*
168
-
* This interface implementation:
168
+
* L'implémentation de cette méthode:
169
169
*
170
170
* public void sayHello() {
171
171
* System.out.println("hello");
172
172
* }
173
173
*
174
-
* Can be replaced by this lambda:
174
+
* Peut être remplacée par cette lambda:
175
175
*
176
-
* () -> {
177
-
* System.out.println("hello");
178
-
* }
176
+
* () -> System.out.println("hello")
179
177
*
180
-
* This interface implementation:
178
+
* L'implémentation de cette méthode:
181
179
*
182
180
* public int square(int x) {
183
181
* return x * x;
184
182
* }
185
183
*
186
-
* Can be replaced by this lambda:
184
+
* Peut être remplacée par cette lambda:
187
185
*
188
186
* (x) -> x * x
189
187
*
190
-
* This interface implementation:
188
+
* L'implémentation de cette méthode:
191
189
*
192
190
* public int min(int x, int y) {
193
191
* if (x < y) {
@@ -196,7 +194,7 @@ public class AboutInterfaces {
196
194
* return y;
197
195
* }
198
196
*
199
-
* Can be replaced by this lambda:
197
+
* Peut être remplacée par cette lambda:
200
198
*
201
199
* (x, y) -> {
202
200
* if (x < y) {
@@ -215,39 +213,42 @@ public class AboutInterfaces {
215
213
216
214
217
215
/**
218
-
* # Common lambda interfaces
216
+
* # Interfaces lambda communes
219
217
*
220
-
* Write a method 'getIsEven' which returns a lambda method testing if an integer is even.
218
+
* Écris une méthode 'getIsEven' qui retourne une méthode lambda testant si un entier est pair.
221
219
*
222
220
* --------- TIPS --------------
223
221
*
224
-
* Since lambda methods are so useful, a lot of interfaces already exist in the Java standard library, and we don't have to create them ourselves.
222
+
* Note: la notation {@link java.lang.String} permet de montrer un lien vers une classe dans un commentaire. Pour voir la classe, tu peux faire un [CTRL] + clic sur le nom de la classe.
223
+
*
224
+
* Comme les méthodes lambdas sont si pratiques, beaucoup d'interfaces simples existent déjà dans la librairie standard de Java. Nous n'avons pas besoin de les créer nous même.
225
+
* Par exemple, une interface avec une méthode ayant la même signature que 'combine()' existe déjà. C'est {@link java.util.function.IntBinaryOperator}.
225
226
*
226
-
* For example:
227
+
* D'autres exemples:
227
228
*
228
-
* For a lambda taking no parameter, and returning nothing, {@link java.lang.Runnable}:
229
+
* Pour une lambda sans paramètre, et ne retournant rien, {@link java.lang.Runnable}:
* The reverse functions, taking nothing as a parameter, but returning something exist as well: {@link java.util.function.IntSupplier}, {@link java.util.function.DoubleSupplier}. etc...
241
+
* Les methodes inverses, ne prenant aucun paramètre, mais retournant un résultat, existent aussi: {@link java.util.function.IntSupplier}, {@link java.util.function.DoubleSupplier}. etc...
* There is also a lot of case where you would need to test a number somehow. This is where interfaces like {@link java.util.function.IntPredicate} shine:
245
+
* Un cas courant est lorsque nous avons besoin de tester si un nombre respecte une condition. C'est là que les interfaces "prédicat" brillent, comme {@link java.util.function.IntPredicate}:
245
246
*
246
247
* IntPredicate isPositive = (number) -> number >= 0;
247
248
*
248
-
* For the exercise, you can use the modulo operator, %, which computes the remainder of an integer division:
249
+
* Pour cet exercice, tu peux utiliser l'opérateur modulo, %, qui calcule le reste d'une division entière:
0 commit comments