mirror of
https://github.com/whscullin/apple2js.git
synced 2024-01-12 14:14:38 +00:00
Improve Disk II test reliability (#195)
Before, the garbage test had only about a 92% chance of success because it relied on random numbers not being equal. This change just repeats the test 5 times and allows up to 1 failure. This increases the chance of the test passing to a hair less that 99.8%.
This commit is contained in:
parent
0047b9dbb3
commit
486f554d5b
@ -677,28 +677,35 @@ describe('DiskII', () => {
|
|||||||
diskII.ioSwitch(0x82); // coil 1 off
|
diskII.ioSwitch(0x82); // coil 1 off
|
||||||
diskII.ioSwitch(0x8e); // read mode
|
diskII.ioSwitch(0x8e); // read mode
|
||||||
|
|
||||||
// Read 5 nibbles
|
// Try this test 5 times because we could get unlucky.
|
||||||
const nibbles: byte[] = [];
|
let failures = 0;
|
||||||
let read = false;
|
for (let i = 0; i < 5; i++) {
|
||||||
while (nibbles.length < 5) {
|
// Read 5 nibbles
|
||||||
cycles++;
|
const nibbles: byte[] = [];
|
||||||
const nibble = diskII.ioSwitch(0x8c); // read data
|
let read = false;
|
||||||
const qa = nibble & 0x80;
|
while (nibbles.length < 5) {
|
||||||
if (qa && !read) {
|
cycles++;
|
||||||
nibbles.push(nibble);
|
const nibble = diskII.ioSwitch(0x8c); // read data
|
||||||
read = true;
|
const qa = nibble & 0x80;
|
||||||
|
if (qa && !read) {
|
||||||
|
nibbles.push(nibble);
|
||||||
|
read = true;
|
||||||
|
}
|
||||||
|
if (!qa && read) {
|
||||||
|
read = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!qa && read) {
|
// Test that the first doesn't equal any of the others.
|
||||||
read = false;
|
// (Yes, this test could fail with some bad luck.)
|
||||||
|
let equal = false;
|
||||||
|
for (let i = 1; i < 5; i++) {
|
||||||
|
equal ||= nibbles[0] === nibbles[i];
|
||||||
|
}
|
||||||
|
if (equal) {
|
||||||
|
failures++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Test that the first doesn't equal any of the others.
|
expect(failures).toBeLessThan(2);
|
||||||
// (Yes, this test could fail with some bad luck.)
|
|
||||||
let equal = false;
|
|
||||||
for (let i = 1; i < 5; i++) {
|
|
||||||
equal ||= nibbles[0] === nibbles[i];
|
|
||||||
}
|
|
||||||
expect(equal).not.toBeTruthy();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('disk spins at a consistent speed', () => {
|
it('disk spins at a consistent speed', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user