Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes tests due to AddressableDevice changes #19

Merged
merged 2 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/RunTests-macOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ on: [pull_request]
jobs:
build:

runs-on: macOS-latest
runs-on: macos-13

steps:
- uses: actions/checkout@v1
- name: Select Xcode 15 beta
run: sudo xcode-select -s /Applications/Xcode_15.app
run: sudo xcode-select -s /Applications/Xcode_15.0.app
- name: Run tests
run: swift test
8 changes: 1 addition & 7 deletions Sources/SwiftNES/AddressableDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ import Foundation

/// A protocol that describes a device that is addressable on a system bus.
protocol AddressableDevice: AnyObject {
/// Returns whether or not the device responds to the specified address.
///
/// - Parameters:
/// - address: The address.
/// - Returns: Whether or not the device responds to the address.
func respondsTo(_ address: Address) -> Bool

/// The address range of the device.
var addressRange: AddressRange { get }
}

Expand Down
12 changes: 1 addition & 11 deletions Sources/SwiftNES/CartridgeConnector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,13 @@ final class CartridgeConnector: AddressableReadWriteDevice {

// MARK: - AddressableReadWriteDevice

@inlinable
func respondsTo(_ address: Address) -> Bool {
addressRange.contains(address)
}

/// The range of addresses that this connector responds to.
let addressRange: AddressRange

func read(from address: Address) -> Value {
guard respondsTo(address) else { return 0 }

return cartridge?.read(from: address) ?? 0
cartridge?.read(from: address) ?? 0
}

func write(_ value: Value, to address: Address) {
guard respondsTo(address) else { return }

cartridge?.write(value, to: address)
}
}
5 changes: 0 additions & 5 deletions Sources/SwiftNES/PixelProcessingUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,6 @@ final class PixelProcessingUnit: AddressableReadWriteDevice {

// MARK: - AddressableReadWriteDevice

@inlinable
func respondsTo(_ address: Address) -> Bool {
RegisterAddress.range.contains(address)
}

let addressRange: AddressRange = RegisterAddress.range

func read(from address: Address) -> Value {
Expand Down
6 changes: 0 additions & 6 deletions Sources/SwiftNES/RandomAccessMemoryDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ final class RandomAccessMemoryDevice: AddressableReadWriteDevice {

// MARK: - Accessing the device

@inlinable
func respondsTo(_ address: Address) -> Bool {
addressRange.contains(address)
}

/// The range of addresses that the device responds to.
let addressRange: AddressRange

func read(from address: Address) -> Value {
Expand Down
16 changes: 2 additions & 14 deletions Tests/SwiftNESTests/BusTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,15 @@ import XCTest
final class BusTests: XCTestCase {

class MockDevice: AddressableReadWriteDevice {
let addressRange: AddressRange = 0x0000...0xffff

func read(from address: Address) -> Value { return values[Int(address)] }

func write(_ data: Value, to address: Address) { values[Int(address)] = data }

func respondsTo(_ address: Address) -> Bool { return address % 2 == 0 ? true : false }

var values: [Value] = Array(repeating: 0x00, count: 0x10000)
}

func testRead() {
let device1 = MockDevice()
let device2 = MockDevice()

}

func testWrite() {

}

func testReadPerformance() throws {
let devices = Array(repeating: MockDevice(), count: 20)
let bus = try Bus(addressableDevices: devices)
Expand Down Expand Up @@ -50,8 +40,6 @@ final class BusTests: XCTestCase {
}

static var allTests = [
("testRead", testRead),
("testWrite", testWrite),
("testReadPerformance", testReadPerformance),
("testWritePerformance", testWritePerformance),
]
Expand Down