mirror of https://github.com/ariejan/i6502.git
Test and implement Memory interface explicitly.
This commit is contained in:
parent
3747d8ce41
commit
96f9605ce4
|
@ -18,6 +18,10 @@ func TestNewAcia6551(t *testing.T) {
|
||||||
assert.Equal(t, 0x4, acia.Size())
|
assert.Equal(t, 0x4, acia.Size())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAciaAsMemory(t *testing.T) {
|
||||||
|
assert.Implements(t, (*Memory)(nil), new(Acia6551))
|
||||||
|
}
|
||||||
|
|
||||||
func TestAciaReset(t *testing.T) {
|
func TestAciaReset(t *testing.T) {
|
||||||
a := AciaSubject()
|
a := AciaSubject()
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,10 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestRamAsMemory(t *testing.T) {
|
||||||
|
assert.Implements(t, (*Memory)(nil), new(Ram))
|
||||||
|
}
|
||||||
|
|
||||||
func TestRamSize(t *testing.T) {
|
func TestRamSize(t *testing.T) {
|
||||||
ram, _ := NewRam(0x8000) // 32 kB
|
ram, _ := NewRam(0x8000) // 32 kB
|
||||||
assert.Equal(t, 0x8000, ram.Size())
|
assert.Equal(t, 0x8000, ram.Size())
|
||||||
|
|
4
rom.go
4
rom.go
|
@ -29,10 +29,10 @@ func (r *Rom) Size() uint16 {
|
||||||
return uint16(len(r.data))
|
return uint16(len(r.data))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Rom) Read(address uint16) byte {
|
func (r *Rom) ReadByte(address uint16) byte {
|
||||||
return r.data[address]
|
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))
|
panic(fmt.Errorf("Trying to write to ROM at 0x%04X", address))
|
||||||
}
|
}
|
||||||
|
|
17
rom_test.go
17
rom_test.go
|
@ -1,17 +1,22 @@
|
||||||
package i6502
|
package i6502
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestRomAsMemory(t *testing.T) {
|
||||||
|
assert.Implements(t, (*Memory)(nil), new(Rom))
|
||||||
|
}
|
||||||
|
|
||||||
func Test8kRoms(t *testing.T) {
|
func Test8kRoms(t *testing.T) {
|
||||||
rom, err := NewRom("test/8kb.rom")
|
rom, err := NewRom("test/8kb.rom")
|
||||||
|
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, 0x2000, rom.Size())
|
assert.Equal(t, 0x2000, rom.Size())
|
||||||
assert.Equal(t, 0x01, rom.Read(0x0000))
|
assert.Equal(t, 0x01, rom.ReadByte(0x0000))
|
||||||
assert.Equal(t, 0xFF, rom.Read(0x2000-1))
|
assert.Equal(t, 0xFF, rom.ReadByte(0x2000-1))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRomWritePanic(t *testing.T) {
|
func TestRomWritePanic(t *testing.T) {
|
||||||
|
@ -19,7 +24,7 @@ func TestRomWritePanic(t *testing.T) {
|
||||||
|
|
||||||
// Writing to rom should panic
|
// Writing to rom should panic
|
||||||
assert.Panics(t, func() {
|
assert.Panics(t, func() {
|
||||||
rom.Write(0x1337, 0x42)
|
rom.WriteByte(0x1337, 0x42)
|
||||||
}, "Writing to Rom should panic")
|
}, "Writing to Rom should panic")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,8 +33,8 @@ func Test16kRom(t *testing.T) {
|
||||||
|
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, 0x4000, rom.Size())
|
assert.Equal(t, 0x4000, rom.Size())
|
||||||
assert.Equal(t, 0x01, rom.Read(0x0000))
|
assert.Equal(t, 0x01, rom.ReadByte(0x0000))
|
||||||
assert.Equal(t, 0xFF, rom.Read(0x4000-1))
|
assert.Equal(t, 0xFF, rom.ReadByte(0x4000-1))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRomNotFound(t *testing.T) {
|
func TestRomNotFound(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue