Skip to content

Commit

Permalink
Fix getCommandIndex and getCommandCount for when run is finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Dec 10, 2016
1 parent 0e802be commit 354ed37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/main/groovy/net/zomis/brainf/model/BrainfuckCode.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ class BrainfuckCode {
// source.getCommand(commandIndex)
}

@Deprecated
int getCommandCount() {
source.capacity()
def lastToken = rootTree.tokens.last();
return lastToken.info.position + lastToken.info.length
}

@Deprecated
Expand All @@ -119,6 +119,10 @@ class BrainfuckCode {
}

public int getCommandIndex() {
if (enteredTrees.isEmpty()) {
// No more commands to run so we are finished
return commandCount;
}
Syntax syntax = getCurrentSyntax();
Token token = syntax.tokens.get(positionInSyntax);
return token.info.position;
Expand Down
5 changes: 4 additions & 1 deletion src/test/groovy/net/zomis/brainf/BrainTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,11 @@ $ bf '+' * 3

@Test
public void simpleCommands() {
useCode("+>++>+++<")
String code = "+>++>+++<";
useCode(code)
assert brain.code.commandIndex == 0
brain.run(new UntilEndStrategy());
assert brain.code.commandCount == code.length()
assert brain.code.commandCount == brain.code.commandIndex
assert 1 == brain.memory.memoryIndex
assert 2 == brain.memory.value
Expand Down

0 comments on commit 354ed37

Please sign in to comment.