#KJ0 | Test is not reproducible in number literal stage of interpreter challenge

For Stage #KJ0, it’s possible to pass the test if the random numbers somehow doesn’t include a trailing zero

Sometimes my code passes if I get “lucky” with the random number even if I deliberately comment out the code that handles the trailing zero.

there should be an explicit test case for the trailing zero requirement

error logs:

[tester::#KJ0] [test-2] Expected line #1 on stdout to be "NUMBER 42.40 42.4", got "NUMBER 42.4 42.4"

Let’s first review what a lexeme is:

The lexemes are the raw substrings of the source code.

Then the structure of a token:

class Token {
  final TokenType type;
  final String lexeme;
  final Object literal;

  public String toString() {
    return type + " " + lexeme + " " + literal;
  }
}

In the case of “NUMBER 42.40 42.4”, the lexeme is "42.40". It is just a raw string from the source code, and you don’t need to change it in any way:

Does this make sense?

Yes, thanks for the clarification.

However, I think my concern is still valid because I initially had a successful codecrafters test then when I tried to run the test again it failed even though I just added a debug print.

So that meant my code was wrong but the test also gave a false positive when it succeeded initially. Am I correct?

Yes, you’re right! Sorry I didn’t understand your point completely, but now I do.

We’re adding a test case in this PR.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.