diff options
Diffstat (limited to 'window-switcher/test_expose.js')
| -rw-r--r-- | window-switcher/test_expose.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/window-switcher/test_expose.js b/window-switcher/test_expose.js new file mode 100644 index 0000000..d394253 --- /dev/null +++ b/window-switcher/test_expose.js @@ -0,0 +1,59 @@ +// Copyright (C) 2026 Danilo M. <danix@danix.xyz> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Run: node window-switcher/test_expose.js +// Expose.js is a QML library, so its .pragma line is stripped before node +// evaluates it, as test_perf.js does for Perf.js. + +const fs = require("fs"); +const assert = require("assert"); + +const src = fs.readFileSync(__dirname + "/Expose.js", "utf8") + .replace(/^\.pragma library$/m, ""); +const { layout } = new Function(src + "\nreturn { layout };")(); + +const W = 2560, H = 1080; +const wide = { w: 2556, h: 1076 }, tall = { w: 1076, h: 1916 }; + +function apart(a, b) { + return a.x + a.w <= b.x || b.x + b.w <= a.x || a.y + a.h <= b.y || b.y + b.h <= a.y; +} +function check(out) { + for (const o of out) { + assert.ok(o.x >= 0 && o.y >= 0 && o.x + o.w <= W + 1e-6 && o.y + o.h <= H + 1e-6, "inside the screen"); + } + for (let i = 0; i < out.length; i++) + for (let j = i + 1; j < out.length; j++) + assert.ok(apart(out[i], out[j]), `windows ${i} and ${j} overlap`); +} + +assert.deepStrictEqual(layout([], W, H), []); + +// Seven identical full-screen windows, the normal case here: no overlap. +const seven = Array(7).fill(wide); +check(layout(seven, W, H)); + +// A busy mixed desk still separates within the pass limit. +check(layout(Array.from({ length: 14 }, (_, i) => i % 3 ? wide : tall), W, H)); + +// Deterministic: the same input gives the same scatter. +assert.deepStrictEqual(layout(seven, W, H), layout(seven, W, H)); + +// A lone window is capped at half size. +const one = layout([wide], W, H)[0]; +assert.ok(Math.abs(one.w - wide.w * 0.5) < 1e-6); + +// One scale for all: sizes stay relative. +const [a, b] = layout([wide, tall], W, H); +assert.ok(Math.abs(a.w / b.w - wide.w / tall.w) < 1e-9); +assert.ok(Math.abs(a.h / b.h - wide.h / tall.h) < 1e-9); + +console.log("test_expose: ok"); |
