Skip to content

Commit 72581b3

Browse files
committed
additions to tests definitions
1 parent 63c066a commit 72581b3

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ A User Guide is included in the web app, and can be launched from the main menu
9090

9191
4. Run `npm test` to execute the tests via [Jest](https://jestjs.io/)
9292

93-
> _Current test coverage according to Jest: 62% (statements)_
93+
> _Current test coverage according to Jest: 67% (statements)_
9494
9595
## Code Structure
9696

test/definitions/plotsTests.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from "../../util/commons.js";
1515
import BodePlot from "../../view/plots/bodePlot.js";
1616
import NyquistPlot from "../../view/plots/nyquistPlot.js";
17+
import TimeDomainPlot from "../../view/plots/timeDomainPlot.js";
1718

1819
const bodeSteps = (numeratorTermsArray, denominatorTermsArray) => {
1920
const { magnitudeCurvePoints, phaseCurvePoints, characteristicNumbers } =
@@ -38,13 +39,31 @@ const nyquistSteps = (numeratorTermsArray, denominatorTermsArray) => {
3839
return [curvePoints, stability];
3940
};
4041

42+
const timeDomainSteps = (numeratorTermsArray, denominatorTermsArray) => {
43+
const { timeResponseCurvePoints, trajectoryCurvePoints } = new TimeDomainPlot(
44+
null,
45+
numeratorTermsArray,
46+
denominatorTermsArray,
47+
findComplexRootsOfPolynomial(numeratorTermsArray),
48+
findComplexRootsOfPolynomial(denominatorTermsArray)
49+
);
50+
return [timeResponseCurvePoints, trajectoryCurvePoints];
51+
};
52+
4153
const bodeAndNyquistSteps = (numeratorTermsArray, denominatorTermsArray) => {
4254
return [
4355
...bodeSteps(numeratorTermsArray, denominatorTermsArray),
4456
...nyquistSteps(numeratorTermsArray, denominatorTermsArray),
4557
];
4658
};
4759

60+
const bodeAndTimeDomainSteps = (numeratorTermsArray, denominatorTermsArray) => {
61+
return [
62+
...bodeSteps(numeratorTermsArray, denominatorTermsArray),
63+
...timeDomainSteps(numeratorTermsArray, denominatorTermsArray),
64+
];
65+
};
66+
4867
export const plotsTests = {
4968
test1: {
5069
description: "test1: tf([1, 0, 0, 0], [1])",
@@ -158,11 +177,13 @@ export const plotsTests = {
158177
description: "test4: tf([1], [1, 0, 1])",
159178
numeratorTermsArray: [1],
160179
denominatorTermsArray: [1, 0, 1],
161-
steps: bodeSteps,
180+
steps: bodeAndTimeDomainSteps,
162181
assertions: (
163182
magnitudeCurvePoints,
164183
phaseCurvePoints,
165-
characteristicNumbers
184+
characteristicNumbers,
185+
timeResponseCurvePoints,
186+
trajectoryCurvePoints
166187
) => [
167188
[
168189
"Roll-off",
@@ -176,6 +197,18 @@ export const plotsTests = {
176197
"-180",
177198
toleranceTestsSmall,
178199
],
200+
[
201+
"Max f(t)",
202+
Math.max(...timeResponseCurvePoints.map((x) => x[1])),
203+
1,
204+
toleranceTestsSmall,
205+
],
206+
[
207+
"Min f(t)",
208+
Math.min(...timeResponseCurvePoints.map((x) => x[1])),
209+
-1,
210+
toleranceTestsSmall,
211+
],
179212
],
180213
},
181214

test/definitions/viewServicesTests.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import { Block } from "../../model/elements/block.js";
1010
import { getTopBlock, setTopBlock } from "../../model/topBlockService.js";
1111
import { roundDecimal, sleep } from "../../util/commons.js";
1212
import { setLogMode } from "../../util/loggingService.js";
13+
import { domElements } from "../../view/services/core/elementRenderingService.js";
1314
import { getTotalLengthOfAllLines } from "../../view/services/core/lineRenderingService.js";
1415
import { optimizeTopology } from "../../view/services/feature/optimizeTopologyService.js";
16+
import { openOrUpdateElementAnalysisWindow } from "../../view/elementAnalysisWindowView.js";
1517
import { circuit1 } from "./circuits.js";
1618

1719
export const viewServicesTests = {
@@ -131,4 +133,37 @@ export const viewServicesTests = {
131133
assertion: (x) => x,
132134
resultsDescription: () => "traversed successfully",
133135
},
136+
137+
test4: {
138+
description: "test4: elementAnalysisWindowView",
139+
steps: async function () {
140+
if (getTopBlock()) {
141+
getTopBlock().clearState();
142+
} else {
143+
setTopBlock(new Block());
144+
}
145+
setTopBlock(circuit1(getTopBlock()));
146+
147+
openOrUpdateElementAnalysisWindow(domElements[0]);
148+
149+
for (let i = 1; i <= 3; i++) {
150+
const elementAnalysisWindowTabButton = document.getElementById(
151+
`element-analysis-window-tab-button-${i}`
152+
);
153+
elementAnalysisWindowTabButton.click();
154+
await sleep(500);
155+
}
156+
157+
const elementAnalysisWindowCloseButton = document.getElementById(
158+
`element-analysis-window-close-button`
159+
);
160+
elementAnalysisWindowCloseButton.click();
161+
162+
getTopBlock().clearState();
163+
164+
return [true];
165+
},
166+
assertion: (x) => x,
167+
resultsDescription: () => "traversed successfully",
168+
},
134169
};

0 commit comments

Comments
 (0)