Ad
  • Custom User Avatar

    the interpreter is only instantiated once so each read should be using the exisiting stacks.

  • Custom User Avatar

    There is definetly something off with random tests, here are couple of examples
    .-+++++.--.-.-.+,561..,800+-,316,535+
    Expected: '04210561561', instead got: '5321561561'

    Expected string doesn't make sense to me:
    we ignore first print, initialize stack A with 0, then do +1 +1 +1 +1 +1 and print number, it should be 5
    Here you can see that expected value ignores rule about printing undefined value.

    This is funny one:
    ++.+-**-.+,361*,374-+.+*+-,525+-
    Expected: '40374', instead got: '10374'

    I would get that it might ask for 2 as first character by using logic demonstrated in previous example, but 4? Where this come from?
    I actually have a theory that might help to fix test, its seems stat current number might not reset between tests. Here is couple of examples of tests

    +-,436.++-.++,544.,15.*+..++-+-
    Test Passed: Value == '436437544011'

    You can see that current number at the end of the program is 2 (+..++-+-)
    ++.+-**-
    .+,361,374-+.+*+-,525+-
    ✘ Expected: '40374', instead got: '10374'

    this test fails, as if it start with not uninitialized state, but with current number set to 2 (leaked from previus test)

    Tests for another example:
    +,899,885--.+.,959+-+-,412+++--+,168+,724
    ✔ Test Passed: Value == '883884'
    current number is 724
    .,441+++-,987-+++-.*+++++
    ✘ Expected: '724988', instead got: '988'

    it prints 724 from previous example right of the bat.
    It may be that current selected stack also get leaked to new tests.

    I've tried to recreate this tests running it like this:
    var inter = new Interpreter();
    Test.assertEquals(inter.read('+-,436.++-.++,544.,15.+..++-+-'),'436437544011','');
    Test.assertEquals(inter.read('++.+-**-
    .+,361,374-+.++-,525+-'),'10374','');
    Test.assertEquals(inter.read('+,899,885--.+.,959+-+-,412+++-
    -+,168*+,724'),'883884','');
    Test.assertEquals(inter.read('.,441+++-,987-+++-.*+++++'),'988','');

    and tests pass. Each read() call gets new state with empty output, so at this point I am pretty sure that I don't have a problem with output or state from previous run affect next one.