Skip to content

Commit 49b2300

Browse files
committed
minor bug fix in reference value. bump version
1 parent 8f4f542 commit 49b2300

File tree

4 files changed

+131
-112
lines changed

4 files changed

+131
-112
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "labkar-algorithms",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"description": "Labkar Algorithms",
55
"main": "dist/lib.js",
66
"scripts": {
@@ -45,4 +45,4 @@
4545
"url": "https://github.com/swiftmade/labkar-algorithms/issues"
4646
},
4747
"homepage": "https://github.com/swiftmade/labkar-algorithms#readme"
48-
}
48+
}

src/algorithms/reference-value.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function ReferenceValue(
1414
/* Second, if reference value is not found, try to calculate using non-reference Formula */
1515
if (formulaInRange.length === 0) {
1616
const notReferenceArray = formulae.filter(
17-
(formula) => formula.is_reference === false
17+
(formula) => !formula.is_reference
1818
);
1919

2020
formulaInRange = notReferenceArray.filter((r) => {
@@ -37,5 +37,4 @@ export function ReferenceValue(
3737
});
3838

3939
return _.maxBy(chainArray, 'value');
40-
4140
}

tests/algorithms.test.ts

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,6 @@
1-
import {
2-
MADe,
3-
M_Estimator,
4-
Q,
5-
Hampel,
6-
A_Algorithm,
7-
ReferenceValue,
8-
} from '../src/lib';
1+
import { MADe, M_Estimator, Q, Hampel, A_Algorithm } from '../src/lib';
92

103
describe('Algorithms', () => {
11-
it('Reference Value (CASE1: x value is not range)', () => {
12-
let x = 0.4;
13-
const formulae = [
14-
{
15-
formula: '0.075*X+4.6',
16-
method: 'TS EN 13132',
17-
min: 60.1,
18-
max: 500.0,
19-
is_reference: true,
20-
},
21-
{
22-
formula: '0.016*X+3.70 ',
23-
method: 'TS EN ISO 13032',
24-
min: 8.0,
25-
max: 50.0,
26-
is_reference: true,
27-
},
28-
{
29-
formula: '0.6*X',
30-
method: 'ASTM D381',
31-
min: 1.0,
32-
max: 30.0,
33-
is_reference: false,
34-
},
35-
];
36-
const output = ReferenceValue(x, formulae);
37-
38-
expect(output).toBe(null);
39-
});
40-
41-
it('Reference Value (CASE2: is not reference array)', () => {
42-
let x = 0.4;
43-
const formulae = [
44-
{
45-
formula: '0.075*X+4.6',
46-
method: 'TS EN 13132',
47-
min: 60.1,
48-
max: 500.0,
49-
is_reference: false,
50-
},
51-
{
52-
formula: '0.016*X+3.70 ',
53-
method: 'TS EN ISO 13032',
54-
min: 8.0,
55-
max: 50.0,
56-
is_reference: false,
57-
},
58-
{
59-
formula: '0.6*X',
60-
method: 'ASTM D381',
61-
min: 1.0,
62-
max: 30.0,
63-
is_reference: false,
64-
},
65-
];
66-
let output = ReferenceValue(x, formulae);
67-
expect(output).toBe(null);
68-
69-
x = 10;
70-
output = ReferenceValue(x, formulae);
71-
72-
expect(output?.value).toBeCloseTo(6, 3);
73-
expect(output?.method).toBe('ASTM D381');
74-
});
75-
76-
it('Reference Value (CASE3: is reference array)', () => {
77-
let x = 0.4;
78-
const formulae = [
79-
{
80-
formula: '0.075*X+4.6',
81-
method: 'TS EN 13132',
82-
min: 60.1,
83-
max: 500.0,
84-
is_reference: true,
85-
},
86-
{
87-
formula: '0.016*X+3.70 ',
88-
method: 'TS EN ISO 13032',
89-
min: 8.0,
90-
max: 50.0,
91-
is_reference: true,
92-
},
93-
{
94-
formula: '0.6*X',
95-
method: 'ASTM D381',
96-
min: 1.0,
97-
max: 30.0,
98-
is_reference: false,
99-
},
100-
];
101-
let output = ReferenceValue(x, formulae);
102-
expect(output).toBe(null);
103-
104-
x = 10;
105-
output = ReferenceValue(x, formulae);
106-
107-
expect(output?.value).toBeCloseTo(3.86, 3);
108-
expect(output?.method).toBe('TS EN ISO 13032');
109-
});
110-
1114
it('A algorithm', () => {
1125
const samples = [
1136
0.04, 0.055, 0.178, 0.202, 0.206, 0.227, 0.228, 0.23, 0.23, 0.235, 0.236,

tests/reference-value.test.ts

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import {
2+
MADe,
3+
M_Estimator,
4+
Q,
5+
Hampel,
6+
A_Algorithm,
7+
ReferenceValue,
8+
} from '../src/lib';
9+
10+
describe('Reference Value', () => {
11+
it('x value is not range', () => {
12+
let x = 0.4;
13+
const formulae = [
14+
{
15+
formula: '0.075*X+4.6',
16+
method: 'TS EN 13132',
17+
min: 60.1,
18+
max: 500.0,
19+
is_reference: true,
20+
},
21+
{
22+
formula: '0.016*X+3.70 ',
23+
method: 'TS EN ISO 13032',
24+
min: 8.0,
25+
max: 50.0,
26+
is_reference: true,
27+
},
28+
{
29+
formula: '0.6*X',
30+
method: 'ASTM D381',
31+
min: 1.0,
32+
max: 30.0,
33+
is_reference: false,
34+
},
35+
];
36+
const output = ReferenceValue(x, formulae);
37+
38+
expect(output).toBe(null);
39+
});
40+
41+
it('No reference values', () => {
42+
let x = 0.4;
43+
const formulae = [
44+
{
45+
formula: '0.075*X+4.6',
46+
method: 'TS EN 13132',
47+
min: 60.1,
48+
max: 500.0,
49+
is_reference: false,
50+
},
51+
{
52+
formula: '0.016*X+3.70 ',
53+
method: 'TS EN ISO 13032',
54+
min: 8.0,
55+
max: 50.0,
56+
is_reference: false,
57+
},
58+
{
59+
formula: '0.6*X',
60+
method: 'ASTM D381',
61+
min: 1.0,
62+
max: 30.0,
63+
is_reference: false,
64+
},
65+
];
66+
let output = ReferenceValue(x, formulae);
67+
expect(output).toBe(null);
68+
69+
x = 10;
70+
output = ReferenceValue(x, formulae);
71+
72+
expect(output?.value).toBeCloseTo(6, 3);
73+
expect(output?.method).toBe('ASTM D381');
74+
});
75+
76+
it('Prioritizes reference value', () => {
77+
let x = 0.4;
78+
const formulae = [
79+
{
80+
formula: '0.075*X+4.6',
81+
method: 'TS EN 13132',
82+
min: 60.1,
83+
max: 500.0,
84+
is_reference: true,
85+
},
86+
{
87+
formula: '0.016*X+3.70 ',
88+
method: 'TS EN ISO 13032',
89+
min: 8.0,
90+
max: 50.0,
91+
is_reference: true,
92+
},
93+
{
94+
formula: '0.6*X',
95+
method: 'ASTM D381',
96+
min: 1.0,
97+
max: 30.0,
98+
is_reference: false,
99+
},
100+
];
101+
let output = ReferenceValue(x, formulae);
102+
expect(output).toBe(null);
103+
104+
x = 10;
105+
output = ReferenceValue(x, formulae);
106+
107+
expect(output?.value).toBeCloseTo(3.86, 3);
108+
expect(output?.method).toBe('TS EN ISO 13032');
109+
});
110+
111+
it('Alternative: prioritizes reference array', () => {
112+
const formulae = [
113+
{
114+
formula: '0.4',
115+
method: 'TEST',
116+
min: 0,
117+
max: 100,
118+
is_reference: false,
119+
},
120+
];
121+
122+
const output = ReferenceValue(79.3, formulae);
123+
124+
expect(output?.value).toBe(0.4);
125+
expect(output?.method).toBe('TEST');
126+
});
127+
});

0 commit comments

Comments
 (0)