webai/archive/test-ioset.ts

32 lines
739 B
TypeScript
Raw Permalink Normal View History

2024-08-13 04:02:53 +00:00
import IOSet from '../site/snake/ioset';
import { addTest, assert, assertArrayEqual } from './tests';
2024-08-09 22:46:24 +00:00
function testOrderMaintained() {
2024-08-13 04:02:53 +00:00
const s = new IOSet();
s.add('A');
s.add('B');
s.add('C');
s.add('D');
s.add('E');
s.add('F');
assert(s.size === 6);
assertArrayEqual(Array.from(s), ['A', 'B', 'C', 'D', 'E', 'F']);
2024-08-09 22:46:24 +00:00
}
addTest(testOrderMaintained);
function testOrderMaintainedWithDelete() {
2024-08-13 04:02:53 +00:00
const s = new IOSet();
s.add('A');
s.add('B');
s.add('C');
s.add('D');
s.add('E');
s.delete('D');
s.add('F');
s.delete('B');
s.add('G');
assert(s.size === 5);
assertArrayEqual(Array.from(s), ['A', 'C', 'E', 'F', 'G']);
2024-08-09 22:46:24 +00:00
}
addTest(testOrderMaintainedWithDelete);