Test and implement Memory interface explicitly.

This commit is contained in:
Ariejan de Vroom 2014-08-21 10:02:38 +02:00
parent 3747d8ce41
commit 96f9605ce4
4 changed files with 21 additions and 8 deletions

View File

@ -18,6 +18,10 @@ func TestNewAcia6551(t *testing.T) {
assert.Equal(t, 0x4, acia.Size())
}
func TestAciaAsMemory(t *testing.T) {
assert.Implements(t, (*Memory)(nil), new(Acia6551))
}
func TestAciaReset(t *testing.T) {
a := AciaSubject()

View File

@ -6,6 +6,10 @@ import (
"github.com/stretchr/testify/assert"
)
func TestRamAsMemory(t *testing.T) {
assert.Implements(t, (*Memory)(nil), new(Ram))
}
func TestRamSize(t *testing.T) {
ram, _ := NewRam(0x8000) // 32 kB
assert.Equal(t, 0x8000, ram.Size())

4
rom.go
View File

@ -29,10 +29,10 @@ func (r *Rom) Size() uint16 {
return uint16(len(r.data))
}
func (r *Rom) Read(address uint16) byte {
func (r *Rom) ReadByte(address uint16) byte {
return r.data[address]
}
func (r *Rom) Write(address uint16, data byte) {
func (r *Rom) WriteByte(address uint16, data byte) {
panic(fmt.Errorf("Trying to write to ROM at 0x%04X", address))
}

View File

@ -1,17 +1,22 @@
package i6502
import (
"github.com/stretchr/testify/assert"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRomAsMemory(t *testing.T) {
assert.Implements(t, (*Memory)(nil), new(Rom))
}
func Test8kRoms(t *testing.T) {
rom, err := NewRom("test/8kb.rom")
assert.Nil(t, err)
assert.Equal(t, 0x2000, rom.Size())
assert.Equal(t, 0x01, rom.Read(0x0000))
assert.Equal(t, 0xFF, rom.Read(0x2000-1))
assert.Equal(t, 0x01, rom.ReadByte(0x0000))
assert.Equal(t, 0xFF, rom.ReadByte(0x2000-1))
}
func TestRomWritePanic(t *testing.T) {
@ -19,7 +24,7 @@ func TestRomWritePanic(t *testing.T) {
// Writing to rom should panic
assert.Panics(t, func() {
rom.Write(0x1337, 0x42)
rom.WriteByte(0x1337, 0x42)
}, "Writing to Rom should panic")
}
@ -28,8 +33,8 @@ func Test16kRom(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, 0x4000, rom.Size())
assert.Equal(t, 0x01, rom.Read(0x0000))
assert.Equal(t, 0xFF, rom.Read(0x4000-1))
assert.Equal(t, 0x01, rom.ReadByte(0x0000))
assert.Equal(t, 0xFF, rom.ReadByte(0x4000-1))
}
func TestRomNotFound(t *testing.T) {