summaryrefslogtreecommitdiff
path: root/src/vm/core.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/vm/core.test.js')
-rw-r--r--src/vm/core.test.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/vm/core.test.js b/src/vm/core.test.js
new file mode 100644
index 0000000..84aab6f
--- /dev/null
+++ b/src/vm/core.test.js
@@ -0,0 +1,42 @@
+'use strict';
+
+const { mod, Range, Core } = require('./core.js');
+
+test('ranges overlap correctly', () => {
+ const a = new Range(7, 1, 8);
+ const b = new Range(0, 2, 8);
+ const c = new Range(3, 5, 8);
+
+ expect(a.overlaps(a)).toBe(true);
+ expect(b.overlaps(b)).toBe(true);
+ expect(c.overlaps(c)).toBe(true);
+
+ expect(a.overlaps(b)).toBe(true);
+ expect(b.overlaps(a)).toBe(true);
+ expect(a.overlaps(c)).toBe(false);
+ expect(b.overlaps(c)).toBe(false);
+ expect(c.overlaps(a)).toBe(false);
+ expect(c.overlaps(b)).toBe(false);
+});
+
+test('get non-overlapping ranges in a core', () => {
+ const CORESIZE = 8000;
+ const core = new Core(CORESIZE);
+
+ for (let loop=0; loop<500; loop++) {
+ const ranges = core.getRanges([20, 10, 5, 5]);
+
+ expect(ranges.length).toBe(4);
+ expect(mod(ranges[0].end - ranges[0].start + 1, CORESIZE)).toBe(20);
+ expect(mod(ranges[1].end - ranges[1].start + 1, CORESIZE)).toBe(10);
+ expect(mod(ranges[2].end - ranges[2].start + 1, CORESIZE)).toBe(5);
+ expect(mod(ranges[3].end - ranges[3].start + 1, CORESIZE)).toBe(5);
+
+ for (let i=0; i<ranges.length; i++) {
+ for (let j=0; j<ranges.length; j++) {
+ if (i === j) continue;
+ expect(ranges[i].overlaps(ranges[j])).toBe(false);
+ }
+ }
+ }
+});