The RobotSimulator tests (groovy/exercises at main · exercism/groovy · GitHub practice/robot-simulator/src/test/groovy/RobotSimulatorSpec.groovy) rely on properties, and properties in Groovy do not include private fields.
I was a bit surprised and confused when something as incomplete as
class RobotSimulator {
private int x, y
private String direction
RobotSimulator(int x, int y, String direction) {
this.x = x
this.y = y
this.direction = direction
}
def move(String commands) {
commands.each {
}
}
}
suddenly passed all the tests.
There’s also no note in the stub or README not to make any field private, and I’d argue that making the internal state private (especially given that it cannot be final) is a good coding practice.
Should the stub instead define the getters (.x()
, .y()
, .direction()
) that the tests rely on? In this case, no extra tests are required.
Or should the stub have a @EqualsAndHashCode(includeFields=true)
class annotation, and the tests rely on object equality? We can add an extra test to avoid falsifying the tests, ensuring objects with different initial values are not equal.