Skip to content

Commit

Permalink
refactoring of plots tests
Browse files Browse the repository at this point in the history
  • Loading branch information
istefanis committed Jan 28, 2024
1 parent 4270b0d commit 2260d6d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 35 deletions.
23 changes: 6 additions & 17 deletions test/custom/plots.customTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,19 @@
* Test / Custom / Plots.customTest
*/

import { findComplexRootsOfPolynomial } from "../../math/numericalAnalysis/numericalAnalysisService.js";
import { sleep } from "../../util/commons.js";
import { logMessages } from "../../util/loggingService.js";
import BodePlot from "../../view/plots/bodePlot.js";
import { plotsTests } from "../definitions/plotsTests.js";

const runPlotsCustomTest = (t) => {
//computation of Bode curve points & characteristic numbers
const { magnitudeCurvePoints, phaseCurvePoints, characteristicNumbers } =
new BodePlot(
null,
t.numeratorTermsArray,
t.denominatorTermsArray,
findComplexRootsOfPolynomial(t.numeratorTermsArray),
findComplexRootsOfPolynomial(t.denominatorTermsArray)
);
// console.log(phaseCurvePoints);
//computation of Plot points & other values (ex. characteristic numbers)
const returnedValuesArray = t.steps(
t.numeratorTermsArray,
t.denominatorTermsArray
);

//evaluation of assertions using the computed data
const assertionsEvaluated = t.assertions(
magnitudeCurvePoints,
phaseCurvePoints,
characteristicNumbers
);
const assertionsEvaluated = t.assertions.call(null, ...returnedValuesArray);

if (assertionsEvaluated.length > 0) {
const testCondition = assertionsEvaluated.every((a) => {
Expand Down
35 changes: 34 additions & 1 deletion test/definitions/plotsTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,34 @@
* Test / Definitions / PlotsTests
*/

import { tolerance } from "../../math/numericalAnalysis/numericalAnalysisService.js";
import {
tolerance,
findComplexRootsOfPolynomial,
} from "../../math/numericalAnalysis/numericalAnalysisService.js";
import BodePlot from "../../view/plots/bodePlot.js";

const toleranceSmall = tolerance; //0.0001
const toleranceMedium = 0.2;
const toleranceLarge = 3;

const bodeSteps = (numeratorTermsArray, denominatorTermsArray) => {
const { magnitudeCurvePoints, phaseCurvePoints, characteristicNumbers } =
new BodePlot(
null,
numeratorTermsArray,
denominatorTermsArray,
findComplexRootsOfPolynomial(numeratorTermsArray),
findComplexRootsOfPolynomial(denominatorTermsArray)
);
return [magnitudeCurvePoints, phaseCurvePoints, characteristicNumbers];
};

export const plotsTests = {
test1: {
description: "test1: tf([1, 0, 0, 0], [1])",
numeratorTermsArray: [1, 0, 0, 0],
denominatorTermsArray: [1],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand All @@ -41,6 +58,7 @@ export const plotsTests = {
description: "test2: tf([1], [1, 0, 0, 0])",
numeratorTermsArray: [1],
denominatorTermsArray: [1, 0, 0, 0],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand All @@ -65,6 +83,7 @@ export const plotsTests = {
description: "test3: tf([1, 0, 1], [1])",
numeratorTermsArray: [1, 0, 1],
denominatorTermsArray: [1],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand All @@ -89,6 +108,7 @@ export const plotsTests = {
description: "test4: tf([1], [1, 0, 1])",
numeratorTermsArray: [1],
denominatorTermsArray: [1, 0, 1],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand All @@ -113,6 +133,7 @@ export const plotsTests = {
description: "test5: tf([1], [0.3, 0.1, 1])",
numeratorTermsArray: [1],
denominatorTermsArray: [0.3, 0.1, 1],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand All @@ -137,6 +158,7 @@ export const plotsTests = {
description: "test6: tf([1], [1, 0])",
numeratorTermsArray: [1],
denominatorTermsArray: [1, 0],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand All @@ -161,6 +183,7 @@ export const plotsTests = {
description: "test7: tf([1, 200, 33.333], [0.333, 0])",
numeratorTermsArray: [1, 200, 33.333],
denominatorTermsArray: [0.333, 0],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand All @@ -180,6 +203,7 @@ export const plotsTests = {
description: "test8: tf([1, 0.625], [0.125])",
numeratorTermsArray: [1, 0.625],
denominatorTermsArray: [0.125],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand All @@ -199,6 +223,7 @@ export const plotsTests = {
description: "test9: tf([1, 1.6], [0.2, 0])",
numeratorTermsArray: [1, 1.6],
denominatorTermsArray: [0.2, 0],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand All @@ -218,6 +243,7 @@ export const plotsTests = {
description: "test10: tf([1, 0.2], [1.6, 0.2])",
numeratorTermsArray: [1, 0.2],
denominatorTermsArray: [1.6, 0.2],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand All @@ -237,6 +263,7 @@ export const plotsTests = {
description: "test11: tf([1, 2, 5], [4, 4])",
numeratorTermsArray: [1, 2, 5],
denominatorTermsArray: [4, 4],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand All @@ -261,6 +288,7 @@ export const plotsTests = {
description: "test12: tf([1, 0, -0.1], [-0.1, -0.2, -0.1])",
numeratorTermsArray: [1, 0, -0.1],
denominatorTermsArray: [-0.1, -0.2, -0.1],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand All @@ -285,6 +313,7 @@ export const plotsTests = {
description: "test13: tf([1, 2, 1], [-10, 0, 1])",
numeratorTermsArray: [1, 2, 1],
denominatorTermsArray: [-10, 0, 1],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand All @@ -309,6 +338,7 @@ export const plotsTests = {
description: "test14: tf([1], [64, 5.214, 64.212, 3.375, 8.062])",
numeratorTermsArray: [1],
denominatorTermsArray: [64, 5.214, 64.212, 3.375, 8.062],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand All @@ -328,6 +358,7 @@ export const plotsTests = {
description: "test15: tf([3.8], [64, 5.214, 64.212, 3.375, 8.062, 0])",
numeratorTermsArray: [3.8],
denominatorTermsArray: [64, 5.214, 64.212, 3.375, 8.062, 0],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand Down Expand Up @@ -359,6 +390,7 @@ export const plotsTests = {
-1, 0.667, 0.667, 2.333, 1.333, -0.333, -0.5, -0.833, -1.167, -0.833,
-0.333,
],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand All @@ -380,6 +412,7 @@ export const plotsTests = {
"[1, 21, 211, 1281, 4935, 11655, 15120, 10395, 10395])",
numeratorTermsArray: [1, -21, 210, -1260, 4725, -10395, 10395],
denominatorTermsArray: [1, 21, 211, 1281, 4935, 11655, 15120, 10395, 10395],
steps: bodeSteps,
assertions: (
magnitudeCurvePoints,
phaseCurvePoints,
Expand Down
23 changes: 6 additions & 17 deletions test/jest/plots.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,17 @@
// Any '*.test.js' files like this are automatically discovered and executed by Jest.
// This file is not imported anywhere so as not to be executed regularly

import { findComplexRootsOfPolynomial } from "../../math/numericalAnalysis/numericalAnalysisService.js";
import BodePlot from "../../view/plots/bodePlot.js";
import { plotsTests } from "../definitions/plotsTests.js";

const runPlotsJestTest = (t) => {
//computation of Bode curve points & characteristic numbers
const { magnitudeCurvePoints, phaseCurvePoints, characteristicNumbers } =
new BodePlot(
null,
t.numeratorTermsArray,
t.denominatorTermsArray,
findComplexRootsOfPolynomial(t.numeratorTermsArray),
findComplexRootsOfPolynomial(t.denominatorTermsArray)
);
// console.log(phaseCurvePoints);
//computation of Plot points & other values (ex. characteristic numbers)
const returnedValuesArray = t.steps(
t.numeratorTermsArray,
t.denominatorTermsArray
);

//evaluation of assertions using the computed data
const assertionsEvaluated = t.assertions(
magnitudeCurvePoints,
phaseCurvePoints,
characteristicNumbers
);
const assertionsEvaluated = t.assertions.call(null, ...returnedValuesArray);

if (assertionsEvaluated.length > 0) {
test(`[TE-03] ${
Expand Down

0 comments on commit 2260d6d

Please # to comment.