Chip-8_Go/pkg/chip8/chip8_test.go

57 lines
1.1 KiB
Go
Raw Normal View History

2020-10-10 21:29:53 +01:00
package chip8
import (
"testing"
)
func slicesEqual(x, y []uint8) bool {
if len(x) != len(y) {
return false
}
for i, xi := range x {
if xi != y[i] {
return false
}
}
return true
}
// This test is kinda shit, there's so much stuff we ain't testing
// Maybe fix
func TestCreateCPU(t *testing.T) {
prog := []uint8{1, 2, 3, 4}
new_cpu := NewCHIP8(prog)
if !slicesEqual(new_cpu.memory[200:204], prog) {
t.Errorf("CPU not initalized properly")
}
}
func TestClearDisplay(t *testing.T) {
cpu := Chip8{}
for i := range cpu.graphics {
cpu.graphics[i] = uint8(i % 255)
}
cpu.clearDisplay()
graphics_array := cpu.GetGraphicsBuffer()
graphics_slice := graphics_array[:]
empty_slice := make([]uint8, len(cpu.graphics))
if !slicesEqual(graphics_slice, empty_slice) {
t.Errorf("Graphics buffer not cleared properly")
}
}
func TestLeaveFunction(t *testing.T) {
cpu := Chip8{pc: 50}
cpu.stack = append(cpu.stack, 1, 2, 3, 4, 5)
cpu.leaveFunction()
if cpu.pc != 4 && len(cpu.stack) != 4 {
t.Errorf("TestLeaveFunction not in expected state")
}
}
func TestPasses(t *testing.T) {
if 1 != 1 {
t.Errorf("We should never get this!")
}
}