-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
47 lines (37 loc) · 876 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"testing"
)
var ch *Chip8
func TestMain(m *testing.M) {
var tab [4096]uint8
ch = &Chip8{pc: 0, memory: tab}
ch.Initialize(fontset)
m.Run()
}
func TestFetchOpcode(t *testing.T) {
expected := uint16(0xA2F0)
c := Chip8{pc: 0}
c.memory[c.pc] = 0xA2
c.memory[c.pc+1] = 0xF0
c.fetchOpcode()
if c.opcode != expected {
t.Errorf("Opcode different than expected %#04x (expected: %#04x)", c.opcode, expected)
}
}
func Test1NNN(t *testing.T) {
expected := uint16(0x024e)
ch.opcode = 0x124e
ch.decodeOpcode()
if ch.pc != expected {
t.Errorf("Opcode different than expected %#04x (expected: %#04x)", ch.opcode, expected)
}
}
func Test6XNN(t *testing.T) {
expected := uint8(0x01)
ch.opcode = 0x6801
ch.decodeOpcode()
if ch.V[8] != expected {
t.Errorf("Value different than expected %#04x (expected: %#04x)", ch.V[8], expected)
}
}