diff options
Diffstat (limited to '')
| -rw-r--r-- | src/cpu/cpu.spec.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/cpu/cpu.spec.ts b/src/cpu/cpu.spec.ts index b1bc876..969b51c 100644 --- a/src/cpu/cpu.spec.ts +++ b/src/cpu/cpu.spec.ts @@ -26,6 +26,23 @@ describe('cpu', () => { ]); }); + it('should correctly sort the events when added in reverse order', () => { + const cpu = new CPU(new Uint16Array(1024), 0x1000); + const events: ITestEvent[] = []; + for (const i of [10, 4, 1]) { + cpu.addClockEvent(() => events.push([i, cpu.cycles]), i); + } + for (let i = 0; i < 10; i++) { + cpu.cycles++; + cpu.tick(); + } + expect(events).toEqual([ + [1, 1], + [4, 4], + [10, 10], + ]); + }); + describe('updateClockEvent', () => { it('should update the number of cycles for the given clock event', () => { const cpu = new CPU(new Uint16Array(1024), 0x1000); @@ -65,6 +82,20 @@ describe('cpu', () => { [10, 10], ]); }); + + it('should return false if the provided clock event is not scheduled', () => { + const cpu = new CPU(new Uint16Array(1024), 0x1000); + const event4 = cpu.addClockEvent(() => 0, 4); + const event10 = cpu.addClockEvent(() => 0, 10); + cpu.addClockEvent(() => 0, 1); + + // Both event should be successfully removed + expect(cpu.clearClockEvent(event4)).toBe(true); + expect(cpu.clearClockEvent(event10)).toBe(true); + // And now we should get false, as these events have already been removed + expect(cpu.clearClockEvent(event4)).toBe(false); + expect(cpu.clearClockEvent(event10)).toBe(false); + }); }); }); }); |
