Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated Validation Tool for Jsthermalcomfort Package Functions #127

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions data
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"information": {
"summary": "This file contains a series of validation tables for a_pmv() in pythermalcomfort, jsthermalcomfort, calcaPMV() in R",
"version": "1.0.0",
"license": "MIT"
},
"tolerance": {
"pmv": 0.01
},
"data": [
{
"inputs": {
"tdb": 24,
"tr": 30,
"vr": 0.22,
"rh": 50,
"met": 1.4,
"clo": 0.5,
"a_coefficient": 0.293
},
"outputs": {
"a_pmv": 0.48
}
},
{
"inputs": {
"tdb": 30,
"tr": 30,
"vr": 0.22,
"rh": 50,
"met": 1.4,
"clo": 0.5,
"a_coefficient": 0.293
},
"outputs": {
"a_pmv": 1.09
}
},
{
"inputs": {
"tdb": [24, 30],
"tr": 30,
"vr": 0.22,
"rh": 50,
"met": 1.4,
"clo": 0.5,
"a_coefficient": 0.293
},
"outputs": {
"a_pmv": [0.48, 1.09]
}
}
]
}
69 changes: 26 additions & 43 deletions tests/models/a_pmv.test.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,32 @@
import { expect, describe, it } from "@jest/globals";
import { deep_close_to_array } from "../test_utilities.js";
import { a_pmv, a_pmv_array } from "../../src/models/a_pmv.js";
import { expect, describe, it, beforeAll } from "@jest/globals";
import { loadTestData, shouldSkipTest } from './testUtils'; // Use the utils
import { a_pmv } from "../../src/models/a_pmv.js";
import { testDataUrls } from './comftest';

describe("a_pmv", () => {
it.each([
{
tdb: 24,
tr: 30,
vr: 0.22,
rh: 50,
met: 1.4,
clo: 0.5,
a_coefficient: 0.293,
wme: undefined,
expected: 0.48,
},
])(
"returns $expected when tdb is $tdb, tr is $tr, vr is $vr, rh is $rh, met is $met, clo is $clo, a_coefficient is $a_coefficient",
({ tdb, tr, vr, rh, met, clo, wme, a_coefficient, expected }) => {
const result = a_pmv(tdb, tr, vr, rh, met, clo, a_coefficient, wme);
let testData;
let tolerance;

expect(result).toBeCloseTo(expected, 2);
},
);
beforeAll(async () => {
const result = await loadTestData(testDataUrls.aPmv, 'pmv');
testData = result.testData;
tolerance = result.tolerance;
});

describe("a_pmv_array", () => {
it.each([
{
tdb: [24, 30],
tr: [30, 30],
vr: [0.22, 0.22],
rh: [50, 50],
met: [1.4, 1.4],
clo: [0.5, 0.5],
a_coefficient: [0.293, 0.293],
wme: undefined,
expected: [0.48, 1.09],
},
])(
"returns $expected when tdb is $tdb, tr is $tr, vr is $vr, rh is $rh, met is $met, clo is $clo, a_coefficient is $a_coefficient",
({ tdb, tr, vr, rh, met, clo, wme, a_coefficient, expected }) => {
const result = a_pmv_array(tdb, tr, vr, rh, met, clo, a_coefficient, wme);
describe("a_pmv", () => {
it("Runs the test after data is loaded and skips data containing arrays", () => {
testData.data.forEach(({ inputs, expected }) => {
if (shouldSkipTest(inputs) || expected === undefined) {
return; // skip the test
}

const { tdb, tr, vr, rh, met, clo, a_coefficient, wme } = inputs;
const result = a_pmv(tdb, tr, vr, rh, met, clo, a_coefficient, wme);

deep_close_to_array(result, expected, 2);
},
);
if (isNaN(result) || expected === null) {
expect(result).toBeNaN();
} else {
expect(result).toBeCloseTo(expected, tolerance);
}
});
});
});
Loading
Loading