-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecision-table.js
75 lines (70 loc) · 1.5 KB
/
decision-table.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import assert from 'node:assert';
const testIfThenElse = (a, b) => {
assert(a >= 1 && a <= 4);
assert(b >= 1 && b <= 4);
let returnValue;
if (a === 1) {
if (b === 1) {
returnValue = 10;
} else if (b === 2) {
returnValue = 20;
} else if (b === 3) {
returnValue = 30;
} else if (b === 4) {
returnValue = 40;
}
} else if (a === 2) {
if (b === 1) {
returnValue = 50;
} else if (b === 2) {
returnValue = 60;
} else if (b === 3) {
returnValue = 70;
} else if (b === 4) {
returnValue = 80;
}
} else if (a === 3) {
if (b === 1) {
returnValue = 90;
} else if (b === 2) {
returnValue = 100;
} else if (b === 3) {
returnValue = 110;
} else if (b === 4) {
returnValue = 120;
}
} else if (a === 4) {
if (b === 1) {
returnValue = 130;
} else if (b === 2) {
returnValue = 140;
} else if (b === 3) {
returnValue = 150;
} else if (b === 4) {
returnValue = 160;
}
}
return returnValue;
};
const testDecisionTable = (a, b) => {
assert(a >= 1 && a <= 4);
assert(b >= 1 && b <= 4);
const decisionTable = [
[10, 20, 30, 40],
[50, 60, 70, 80],
[90, 100, 110, 120],
[130, 140, 150, 160],
];
return decisionTable[a - 1][b - 1];
};
const main = () => {
for (let a = 1; a <= 4; ++a) {
for (let b = 1; b <= 4; ++b) {
const resultIfThenElse = testIfThenElse(a, b);
const resultDecisionTable = testDecisionTable(a, b);
console.log({resultIfThenElse, resultDecisionTable});
assert(resultIfThenElse === resultDecisionTable);
}
}
};
main();