first commit

This commit is contained in:
2026-04-30 18:22:10 +02:00
commit c3e98af5b6
36 changed files with 4779 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const power_calculation_js_1 = require("../src/domain/calculations/power-calculation.js");
(0, vitest_1.describe)("power calculation", () => {
(0, vitest_1.it)("calculates installed power", () => {
const result = (0, power_calculation_js_1.calculateInstalledPowerKw)({
quantity: 4,
installedPowerPerUnitKw: 1.2,
demandFactor: 0.8,
});
(0, vitest_1.expect)(result).toBeCloseTo(4.8);
});
(0, vitest_1.it)("calculates demand power", () => {
const result = (0, power_calculation_js_1.calculateDemandPowerKw)({
quantity: 4,
installedPowerPerUnitKw: 1.2,
demandFactor: 0.8,
});
(0, vitest_1.expect)(result).toBeCloseTo(3.84);
});
(0, vitest_1.it)("handles zero quantity", () => {
const result = (0, power_calculation_js_1.calculateInstalledPowerKw)({
quantity: 0,
installedPowerPerUnitKw: 3,
demandFactor: 0.9,
});
(0, vitest_1.expect)(result).toBe(0);
});
(0, vitest_1.it)("handles zero demand factor", () => {
const result = (0, power_calculation_js_1.calculateDemandPowerKw)({
quantity: 5,
installedPowerPerUnitKw: 2,
demandFactor: 0,
});
(0, vitest_1.expect)(result).toBe(0);
});
(0, vitest_1.it)("calculates single-phase current", () => {
const current = (0, power_calculation_js_1.calculateCurrentA)({
demandPowerKw: 2.3,
voltageV: 230,
phaseCount: 1,
powerFactor: 0.95,
});
(0, vitest_1.expect)(current).toBeCloseTo(10.53, 2);
});
(0, vitest_1.it)("calculates three-phase current", () => {
const current = (0, power_calculation_js_1.calculateCurrentA)({
demandPowerKw: 9.5,
voltageV: 400,
phaseCount: 3,
powerFactor: 0.9,
});
(0, vitest_1.expect)(current).toBeCloseTo(15.23, 2);
});
});
+65
View File
@@ -0,0 +1,65 @@
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);
});
});