66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
import { describe, it } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
calculateCurrentA,
|
|
calculateDemandPowerKw,
|
|
calculateInstalledPowerKw,
|
|
} from "../src/domain/calculations/power-calculation.js";
|
|
|
|
describe("power calculation", () => {
|
|
it("calculates installed power", () => {
|
|
const result = calculateInstalledPowerKw({
|
|
quantity: 4,
|
|
installedPowerPerUnitKw: 1.2,
|
|
demandFactor: 0.8,
|
|
});
|
|
assert.ok(Math.abs(result - 4.8) < 0.00001);
|
|
});
|
|
|
|
it("calculates demand power", () => {
|
|
const result = calculateDemandPowerKw({
|
|
quantity: 4,
|
|
installedPowerPerUnitKw: 1.2,
|
|
demandFactor: 0.8,
|
|
});
|
|
assert.ok(Math.abs(result - 3.84) < 0.00001);
|
|
});
|
|
|
|
it("handles zero quantity", () => {
|
|
const result = calculateInstalledPowerKw({
|
|
quantity: 0,
|
|
installedPowerPerUnitKw: 3,
|
|
demandFactor: 0.9,
|
|
});
|
|
assert.equal(result, 0);
|
|
});
|
|
|
|
it("handles zero demand factor", () => {
|
|
const result = calculateDemandPowerKw({
|
|
quantity: 5,
|
|
installedPowerPerUnitKw: 2,
|
|
demandFactor: 0,
|
|
});
|
|
assert.equal(result, 0);
|
|
});
|
|
|
|
it("calculates single-phase current", () => {
|
|
const current = calculateCurrentA({
|
|
demandPowerKw: 2.3,
|
|
voltageV: 230,
|
|
phaseCount: 1,
|
|
powerFactor: 0.95,
|
|
});
|
|
assert.ok(Math.abs(current - 10.53) < 0.02);
|
|
});
|
|
|
|
it("calculates three-phase current", () => {
|
|
const current = calculateCurrentA({
|
|
demandPowerKw: 9.5,
|
|
voltageV: 400,
|
|
phaseCount: 3,
|
|
powerFactor: 0.9,
|
|
});
|
|
assert.ok(Math.abs(current - 15.23) < 0.02);
|
|
});
|
|
});
|