Robot-simulator tests rely on class properties, excluding private fields

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.

@BNAndras, could you (as the author of the exercise) please share your opinion? :pray:

I’ll defer to @glennj as the track maintainer, but that seems reasonable to me. I should have used getters to test the robot’s position directly instead of comparing two different robots. That would have been more explicit and less error-prone.

Here’s one way to do it (with some extra Groovy/Spock style): Refactor robot-simulator exercise by artamonovkirill · Pull Request #1 · artamonovkirill/groovy · GitHub