/
spider0
/
Spider0
Обзор
Документация
Войти
/
spider0
/
Spider0
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
tests/zoneEngine.test.js
33 строки
1 KB
AlexSpider0686
Add files via upload
24 мар 2026, 00:30
Не верифицирован
24 мар 2026, 00:30
3545f96
Код
Авторство
О чём код?
import test from "node:test"; import assert from "node:assert/strict"; import { rebalanceZoneAreasWithLocks, getZonePercentSum } from "../src/lib/zoneEngine.js"; const TOTAL_AREA = 1000; test("rebalanceZoneAreasWithLocks keeps total share at 100%", () => { const zones = [ { id: 1, area: 500, floors: 1, type: "office" }, { id: 2, area: 300, floors: 1, type: "parking" }, { id: 3, area: 200, floors: 1, type: "technical" }, ]; const next = rebalanceZoneAreasWithLocks(zones, 1, 60, TOTAL_AREA, []); const totalPercent = getZonePercentSum(next, TOTAL_AREA); assert.ok(Math.abs(totalPercent - 100) < 0.2); }); test("rebalanceZoneAreasWithLocks preserves locked zones and rejects changing locked target", () => { const zones = [ { id: 1, area: 500, floors: 1, type: "office" }, { id: 2, area: 300, floors: 1, type: "parking" }, { id: 3, area: 200, floors: 1, type: "technical" }, ]; const changedLocked = rebalanceZoneAreasWithLocks(zones, 2, 50, TOTAL_AREA, [2]); assert.deepEqual(changedLocked, zones); const next = rebalanceZoneAreasWithLocks(zones, 1, 55, TOTAL_AREA, [2]); const zone2 = next.find((z) => z.id === 2); assert.equal(zone2.area, 300); });