-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test Instructions and slim opMove code.
- Loading branch information
1 parent
8251691
commit f9a065d
Showing
6 changed files
with
79 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package parser | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestNewInstruction(t *testing.T) { | ||
sourceCode := "g><+-.,[]" | ||
program := []Instruction{ | ||
Instruction{opNoop, 0}, | ||
Instruction{opAddDp, 1}, | ||
Instruction{opAddDp, -1}, | ||
Instruction{opAddVal, 1}, | ||
Instruction{opAddVal, -1}, | ||
Instruction{opOut, 1}, | ||
Instruction{opIn, 1}, | ||
Instruction{opJmpZ, 0}, | ||
Instruction{opJmpNz, 0}, | ||
} | ||
|
||
for idx, val := range []byte(sourceCode) { | ||
t.Run(program[idx].String(), func(t *testing.T) { | ||
got := NewInstruction(val) | ||
want := program[idx] | ||
|
||
if !reflect.DeepEqual(got, want) { | ||
t.Errorf("got %v want %v", got, want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestSameOp(t *testing.T) { | ||
opsList := []Opcode{ | ||
opNoop, | ||
opAddDp, | ||
opAddVal, | ||
opOut, | ||
opIn, | ||
opJmpZ, | ||
opJmpNz, | ||
opZero, | ||
opMove, | ||
} | ||
|
||
for row, rval := range opsList { | ||
for col, cval := range opsList { | ||
t.Run(fmt.Sprintf("%d-%d", row, col), func(t *testing.T) { | ||
rinst := Instruction{rval, col} | ||
cinst := Instruction{cval, row} | ||
want := row == col | ||
|
||
if rinst.SameOp(cinst) != want { | ||
t.Errorf("testing %v vs %v want %v", rinst, cinst, want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.