Skip to content

Commit

Permalink
test: append gridAppropriateSize metric test #46
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiomrebelo committed Jul 24, 2023
1 parent c16cef0 commit 2ce2c6e
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/@evoposter/evaluator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "set of metric for evaluation of poster designs",
"main": "src/index.mjs",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules npx jest"
},
"type": "module",
"repository": {
Expand Down
7 changes: 5 additions & 2 deletions src/@evoposter/evaluator/src/metrics/GridAppropriateSize.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@ export const compute = (
let msg = "";

// height calculation
let height = margins.top+margins.bottom;
let height = Math.abs(margins.top)+Math.abs(margins.bottom);
for (let r of rows) {
height = height + parseFloat(r);
}
// width calculation
let width = margins.left+margins.right;
let width = Math.abs(margins.left)+Math.abs(margins.right);
for (let r of columns) {
width = width + parseFloat(r);
}

width = Math.round(width);
height = Math.round(height);

if (height > containerHeight) {
invalid = true;
msg += `Grid height is bigger than container (grid:${height}, container:${containerHeight}). `;
Expand Down
74 changes: 74 additions & 0 deletions src/@evoposter/evaluator/test/unit/GridAppropriateSize.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {gridAppropriateSize} from '../../src/index.mjs'

const TESTING_PARAMS = [
{
width: 300,
height: 423,
rows: [379.95],
columns: [135, 135],
margins: {left: 15, top: 21.900000000000002, right: 15, bottom: 21.150000000000002},
invalid: false,
},
{
width: 300,
height: 423,
rows: [377.84999999999997],
columns: [135, 135],
margins: {left: 15, top: 21.150000000000002, right: 15, bottom: 24.000000000000025},
invalid: false
},
{
width: 300,
height: 423,
rows: [72.85000000000001, 69.85, 71.95, 70.89999999999999, 70.89999999999999],
columns: [135, 135],
margins: {left: 15, top: 33.27500000000001, right: 15, bottom: 33.27500000000001},
invalid: false
},
{
width: 300,
height: 423,
rows: [76, 74.95, 74.95, 73.9, 72.85000000000001],
columns: [135, 135],
margins: {left: 15, top: 21.150000000000002, right: 15, bottom: 29.199999999999985},
invalid: false
},
{
width: 300,
height: 423,
rows: [22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05, 22.05],
columns: [135, 135],
margins: {left: 15, top: -171.45000000000002, right: 15, bottom: 21.150000000000002},
invalid: true
},
{
width: 300,
height: 423,
rows: [76, 74.95, 74.95, 73.9, 72.85000000000001],
columns: [135, 160],
margins: {left: 15, top: 21.150000000000002, right: 20, bottom: 29.199999999999985},
invalid: true
},
{
width: 300,
height: 423,
rows: [76, 150, 74.95, 200, 72.85000000000001],
columns: [135, 160],
margins: {left: 1000, top: 21.150000000000002, right: 20, bottom: 29.199999999999985},
invalid: true
}
];

describe(`Test the Grid Size Appropriateness metric`, () => {
for (let i in TESTING_PARAMS) {
let params = TESTING_PARAMS[i];
test(`Test ${i}`, async () => {
const invalid = gridAppropriateSize(
params.width, params.height,
params.rows, params.columns, params.margins
);
const expectResult = params.invalid ? 1 : 0;
expect(invalid).toBe(expectResult);
});
}
});
25 changes: 0 additions & 25 deletions src/@evoposter/evaluator/test/unit/gridSize.test.js

This file was deleted.

Empty file.
2 changes: 1 addition & 1 deletion src/public/app.js

Large diffs are not rendered by default.

0 comments on commit 2ce2c6e

Please sign in to comment.