From 4e51cf54cd9b750e8f69701920b8da75eedb9a38 Mon Sep 17 00:00:00 2001 From: Jordan Ocokoljic Date: Fri, 2 Feb 2024 14:08:39 +1100 Subject: [PATCH] Add tests for JOS3 setters --- tests/models/1_run_setters.json | 395 ++++++++++++++++++++++++++++++++ tests/models/JOS3.test.js | 45 ++-- 2 files changed, 427 insertions(+), 13 deletions(-) create mode 100644 tests/models/1_run_setters.json diff --git a/tests/models/1_run_setters.json b/tests/models/1_run_setters.json new file mode 100644 index 0000000..43e284c --- /dev/null +++ b/tests/models/1_run_setters.json @@ -0,0 +1,395 @@ +[ + { + "property": "tdb", + "operations": [ + { + "next": 30, + "expected": [ + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0 + ] + } + ] + }, + { + "property": "tr", + "operations": [ + { + "next": 30, + "expected": [ + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0 + ] + } + ] + }, + { + "property": "to", + "operations": [ + { + "next": 30, + "expected": [ + 30.0, + 30.0, + 30.0, + 30.0, + 29.999999999999996, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.0, + 30.000000000000004, + 29.999999999999996, + 30.000000000000004, + 30.000000000000004, + 29.999999999999996, + 30.000000000000004 + ] + } + ] + }, + { + "property": "rh", + "operations": [ + { + "next": 55, + "expected": [ + 55.0, + 55.0, + 55.0, + 55.0, + 55.0, + 55.0, + 55.0, + 55.0, + 55.0, + 55.0, + 55.0, + 55.0, + 55.0, + 55.0, + 55.0, + 55.0, + 55.0 + ] + } + ] + }, + { + "property": "v", + "operations": [ + { + "next": 0.2, + "expected": [ + 0.2, + 0.2, + 0.2, + 0.2, + 0.2, + 0.2, + 0.2, + 0.2, + 0.2, + 0.2, + 0.2, + 0.2, + 0.2, + 0.2, + 0.2, + 0.2, + 0.2 + ] + } + ] + }, + { + "property": "posture", + "operations": [ + { + "next": 0, + "expected": "standing" + }, + { + "next": 1, + "expected": "sitting" + }, + { + "next": 2, + "expected": "lying" + }, + { + "next": "standing", + "expected": "standing" + }, + { + "next": "sitting", + "expected": "sitting" + }, + { + "next": "sedentary", + "expected": "sitting" + }, + { + "next": "lying", + "expected": "lying" + }, + { + "next": "supine", + "expected": "lying" + }, + { + "next": "invalid", + "expected": "standing" + } + ] + }, + { + "property": "clo", + "operations": [ + { + "next": 1, + "expected": [ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0 + ] + } + ] + }, + { + "property": "par", + "operations": [ + { + "next": 2, + "expected": 2 + } + ] + }, + { + "property": "body_temp", + "operations": [ + { + "next":[ + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0 + ], + "expected": [ + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0, + 39.0 + ] + } + ] + } +] \ No newline at end of file diff --git a/tests/models/JOS3.test.js b/tests/models/JOS3.test.js index b5b050d..c576321 100644 --- a/tests/models/JOS3.test.js +++ b/tests/models/JOS3.test.js @@ -3,6 +3,7 @@ import { describe, it, expect } from "@jest/globals"; import single_iteration from "./1_run_dict.json"; import twenty_iterations from "./20_runs_dict.json"; import getters from "./1_run_getters.json"; +import setters from "./1_run_setters.json"; import * as math from "mathjs"; import { BODY_NAMES } from "../../src/jos3_functions/matrix.js"; @@ -41,6 +42,24 @@ describe("JOS3", () => { } }); + const checkProperty = (prop, expected) => { + if (math.isMatrix(prop)) { + prop = prop.toArray(); + } + + if (Array.isArray(expected)) { + for (let i = 0; i < expected.length; i++) { + expect(prop[i]).toBeCloseTo(expected[i], 10); + } + } else if (typeof expected === "string") { + expect(prop).toBe(expected); + } else if (typeof expected === "number") { + expect(prop).toBeCloseTo(expected, 10); + } else { + throw new Error(`whoops, not implemented for "${typeof expected}"`); + } + } + describe("getters return correct values", () => { const jos = new JOS3(); @@ -53,22 +72,22 @@ describe("JOS3", () => { }); it.each(getters)("$property", ({ property, expected }) => { - let prop = jos[property]; + checkProperty(jos[property], expected); + }); + }); - if (math.isMatrix(prop)) { - prop = prop.toArray(); - } + describe("setters operate appropriately", () => { + it.each(setters)("$property", ({ property, operations }) => { + for (const { next, expected } of operations) { + const jos = new JOS3(); + let set = next; - if (Array.isArray(expected)) { - for (let i = 0; i < expected.length; i++) { - expect(prop[i]).toBeCloseTo(expected[i], 10); + if (Array.isArray(set)) { + set = math.matrix(set); } - } else if (typeof expected === "string") { - expect(prop).toBe(expected); - } else if (typeof expected === "number") { - expect(prop).toBeCloseTo(expected, 10); - } else { - throw new Error(`whoops, not implemented for "${typeof expected}"`); + + jos[property] = set; + checkProperty(jos[property], expected); } }); });