Skip to content

Commit 6d99c94

Browse files
author
Julien Letrouit
committed
Reworked the engine to allow for more flexibility at tested expressions, as well as better messages from the Sensei. Also, simpler engine code.
1 parent 39dc4c4 commit 6d99c94

44 files changed

Lines changed: 1710 additions & 1523 deletions

Some content is hidden

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

src/main/java/engine/Assertions.java

Lines changed: 132 additions & 147 deletions
Large diffs are not rendered by default.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package engine;
2+
3+
/**
4+
* Asserts something about student's code before koan tests are run.
5+
*/
6+
public interface BeforeTestAssertion {
7+
/**
8+
* Validates that the structure of student code for a given Koan is correct, and display feedback using the given Printer.
9+
* @param p The printer to give feedback through.
10+
* @return Whether or not the assertion is successful or not.
11+
*/
12+
boolean validate(final Printer p, final Locale locale, final Koan koan);
13+
}

src/main/java/engine/Color.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,34 @@
33
/**
44
* Console text coloring.
55
*/
6-
public class Color {
6+
public final class Color {
77
private static final String RESET = "\033[0m";
88

99
private static final String RED = "\033[0;31m";
1010
private static final String GREEN = "\033[0;32m";
1111
private static final String CYAN = "\033[0;36m";
1212

13-
public static Local<String> red(Local<String> text) {
13+
public static Localizable<String> red(final Localizable<String> text) {
1414
return text.map(Color::red);
1515
}
1616

17-
public static Local<String> green(Local<String> text) {
17+
public static Localizable<String> green(final Localizable<String> text) {
1818
return text.map(Color::green);
1919
}
2020

21-
public static Local<String> cyan(Local<String> text) {
21+
public static Localizable<String> cyan(final Localizable<String> text) {
2222
return text.map(Color::cyan);
2323
}
2424

25-
public static String red(String text) {
25+
public static String red(final String text) {
2626
return String.format("%s%s%s", RED, text, RESET);
2727
}
2828

29-
public static String green(String text) {
29+
public static String green(final String text) {
3030
return String.format("%s%s%s", GREEN, text, RESET);
3131
}
3232

33-
public static String cyan(String text) {
33+
public static String cyan(final String text) {
3434
return String.format("%s%s%s", CYAN, text, RESET);
3535
}
3636
}

src/main/java/engine/ConsolePrinter.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/main/java/engine/Factories.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/main/java/engine/FormatParam.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
* A functional interface offering the possibility to format a piece of feedback to the user given the koan's result.
55
*/
66
public interface FormatParam {
7-
String format(KoanResult res);
7+
String format(final KoanResult res);
88

99
/**
1010
* Creates a FormatParam taking the stdIn input for the given index, convert it to an int, and increment it by the given increment.
1111
*
1212
* Ex: if input 0 contains "3", then paramPlus(0, 10) will return "13".
1313
*/
14-
static FormatParam addToStdInInput(int inputIndex, int increment) {
14+
static FormatParam addToStdInInput(final int inputIndex, final int increment) {
1515
return res ->
1616
res.inputLine(inputIndex)
1717
.map(line -> {
1818
try {
19-
int value = Integer.parseInt(line);
19+
final int value = Integer.parseInt(line);
2020
return String.valueOf(value + increment);
2121
} catch(NumberFormatException nfe) {
2222
// Ignore
@@ -26,7 +26,7 @@ static FormatParam addToStdInInput(int inputIndex, int increment) {
2626
.orElse("");
2727
}
2828

29-
static FormatParam stdInInput(int inputIndex) {
29+
static FormatParam stdInInput(final int inputIndex) {
3030
return res -> res.inputLine(inputIndex).orElse("");
3131
}
3232
}

src/main/java/engine/Global.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/main/java/engine/Helpers.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.util.Scanner;
99

1010
public class Helpers {
11-
private static Random rng = new Random();
11+
private static final Random rng = new Random();
1212
private static Scanner scanner = null;
1313

1414
static void cleanupStdInForKoan() {
@@ -25,26 +25,26 @@ public static String readLine() {
2525
return scanner.nextLine();
2626
}
2727

28-
static void setupRandomForKoan(long seed) {
28+
static void setupRandomForKoan(final long seed) {
2929
rng.setSeed(seed);
3030
}
3131

3232
public static double random() {
3333
return rng.nextDouble();
3434
}
3535

36-
static String formatSequence(Locale locale, double[] toFormat) {
36+
static String formatSequence(final Locale locale, final double[] toFormat) {
3737
return formatSequence(
3838
locale,
3939
Arrays.stream(toFormat).mapToObj(Double::toString).toArray(String[]::new)
4040
);
4141
}
4242

43-
static String formatSequence(Locale locale, Object[] toFormat) {
43+
static String formatSequence(final Locale locale, final Object[] toFormat) {
4444
if (toFormat == null || toFormat.length == 0) {
4545
return "";
4646
}
47-
var result = new StringBuilder();
47+
final var result = new StringBuilder();
4848
result.append(toFormat[0]);
4949

5050
if (toFormat.length > 1) {
@@ -58,8 +58,8 @@ static String formatSequence(Locale locale, Object[] toFormat) {
5858
return result.toString();
5959
}
6060

61-
static boolean isInstantiable(Class<?> clasz) {
62-
int modifiers = clasz.getModifiers();
61+
static boolean isInstantiable(final Class<?> clasz) {
62+
final int modifiers = clasz.getModifiers();
6363
return
6464
Modifier.isPublic(modifiers) &&
6565
!clasz.isInterface() &&

0 commit comments

Comments
 (0)