Files
leistungsbilanz-ts/tests/circuit-power-calculation.test.ts
T

48 lines
1.8 KiB
TypeScript

import assert from "node:assert/strict";
import { describe, it } from "node:test";
import {
calculateCircuitTotalPower,
calculateRowTotalPower,
} from "../src/domain/calculations/circuit-power-calculation.js";
import {
resolveCircuitPhaseType,
resolveProjectVoltage,
} from "../src/domain/services/project-voltage.service.js";
describe("circuit power calculation", () => {
it("calculates row and circuit totals from device rows", () => {
assert.equal(calculateRowTotalPower(2, 1.5, 0.5), 1.5);
const total = calculateCircuitTotalPower([
{ quantity: 2, powerPerUnit: 1.5, simultaneityFactor: 0.5 },
{ quantity: 1, powerPerUnit: 3, simultaneityFactor: 1 },
]);
assert.equal(total, 4.5);
});
});
describe("project voltage derivation", () => {
const settings = {
singlePhaseVoltageV: 240,
threePhaseVoltageV: 415,
};
it("derives device voltage exclusively from phase and project settings", () => {
assert.equal(resolveProjectVoltage("single_phase", settings), 240);
assert.equal(resolveProjectVoltage("three_phase", settings), 415);
});
it("uses section phase and handles unassigned circuits conservatively", () => {
assert.equal(resolveCircuitPhaseType("lighting", ["three_phase"]), "single_phase");
assert.equal(resolveCircuitPhaseType("single_phase", ["three_phase"]), "single_phase");
assert.equal(resolveCircuitPhaseType("three_phase", ["single_phase"]), "three_phase");
assert.equal(resolveCircuitPhaseType("unassigned", ["three_phase"]), "three_phase");
assert.equal(
resolveCircuitPhaseType("unassigned", ["three_phase", "single_phase"]),
"single_phase"
);
assert.equal(resolveCircuitPhaseType("unassigned", []), "single_phase");
assert.equal(resolveCircuitPhaseType("unassigned", [null]), "single_phase");
});
});