forked from edgarmsilva/QAEngineeringChallenge2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculate.test.ts
208 lines (181 loc) · 9.03 KB
/
calculate.test.ts
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import { calculatePartHealth, calculateMachineHealth } from "../calculations";
import {
MachineType,
QualityControlStationPart,
WeldingRobotPart,
partInfo,
} from "../../native-app/data/types";
import machineData from "../../native-app/data/machineData.json";
describe("calculatePartHealth", () => {
it("should return 72.22...3 when part quality 0.5 and normal range 0.1~1", () => {
const machineName: MachineType = MachineType.WeldingRobot;
const part: partInfo = { name: WeldingRobotPart.ErrorRate, value: 0.5 };
const expectedHealth = 72.22222222222223;
const result = calculatePartHealth(machineName, part);
expect(result).toBe(expectedHealth);
});
it("should return 100 when part quality 1 and normal range 0.1~1", () => {
const machineName: MachineType = MachineType.WeldingRobot;
const part: partInfo = { name: WeldingRobotPart.ErrorRate, value: 1 };
const expectedHealth = 100;
const result = calculatePartHealth(machineName, part);
expect(result).toBe(expectedHealth);
});
it("should return 0 when part quality 1.1 compared to normal range 0.1~1", () => {
const machineName: MachineType = MachineType.WeldingRobot;
const part: partInfo = { name: WeldingRobotPart.ErrorRate, value: 1.1 };
const expectedHealth = 50;
const result = calculatePartHealth(machineName, part);
expect(result).toBe(expectedHealth);
});
it("should return 0 when part quality 1.1 compared to normal range 0.1~1", () => {
const machineName: MachineType = MachineType.WeldingRobot;
const part: partInfo = { name: WeldingRobotPart.ErrorRate, value: 1.1 };
const expectedHealth = 50;
const result = calculatePartHealth(machineName, part);
expect(result).toBe(expectedHealth);
});
it("should return 100 when part value is at minimum of optimal range [0.0~0.1]", () => {
const machineName: MachineType = MachineType.WeldingRobot;
const part: partInfo = { name: WeldingRobotPart.ErrorRate, value: 0.0 };
const expectedHealth = 100;
const result = calculatePartHealth(machineName, part);
expect(result).toBe(expectedHealth);
});
it("should return 100 when part value is at maximum of optimal range and equals minimum of normal range", () => {
//Could also dynamically try to find this machine and part in machineData.json
const machineName: MachineType = MachineType.WeldingRobot;
const part: partInfo = { name: WeldingRobotPart.ErrorRate, value: 0.1 };
const expectedHealth = 100;
const minNormalRange =
machineData[machineName][WeldingRobotPart.ErrorRate].normalRange[0];
const maxOptimalRange =
machineData[machineName][WeldingRobotPart.ErrorRate].optimalRange[1];
const isMinNormalRangeSameAsMaxOptimalRange =
minNormalRange === maxOptimalRange;
if (isMinNormalRangeSameAsMaxOptimalRange) {
const result = calculatePartHealth(machineName, part);
expect(result).toBe(expectedHealth);
} else {
console.log(
"Test skipped because minNormalRange is not equal to maxOptimalRange in machineData.json"
);
}
});
it("should return health 100 when part optimal range is [0, 0] and normal range is [0, >0] and part quality is 0", () => {
// More context on this test given below
const machineName: MachineType = MachineType.QualityControlStation;
const part: partInfo = {
name: QualityControlStationPart.CriteriaSettings,
value: 0,
};
const expectedHealth = 100;
const result = calculatePartHealth(machineName, part);
expect(result).toBe(expectedHealth);
});
it("should return health 100 within optimal and normal range of a part with string value", () => {
const machineName: MachineType = MachineType.QualityControlStation;
const part: partInfo = {
name: QualityControlStationPart.SoftwareVersion,
//In this case, the value here should be "v1.0" based on machineData.json
//But typescript won't allow it as the definition of the partInfo value is a number and not number | string
//Another particularity that I would be looking into with the team to determine whether we should fix in code, data, or
//In the way that the value is used
value: 1.0,
};
const expectedHealth = 100;
const result = calculatePartHealth(machineName, part);
expect(result).toBe(expectedHealth);
});
it("should return health 100 within optimal and normal range of a part with string value", () => {
const machineName: MachineType = MachineType.QualityControlStation;
const part: partInfo = {
name: QualityControlStationPart.SoftwareVersion,
//Same as above, the value here should be "v2.0" based on machineData.json
value: 2.0,
};
const expectedHealth = 100;
const result = calculatePartHealth(machineName, part);
expect(result).toBe(expectedHealth);
});
it("should not return health 0 when above normal range or below lowest of normal or optimal", () => {
const machineName: MachineType = MachineType.QualityControlStation;
const part: partInfo = {
name: QualityControlStationPart.SoftwareVersion,
//Same as above, the value here should be "v2.1" based on machineData.json
value: 2.1,
};
const expectedHealth = 100;
const result = calculatePartHealth(machineName, part);
expect(result).toBe(expectedHealth);
});
it("should not return health 0 when above normal range or below lowest of normal or optimal", () => {
const machineName: MachineType = MachineType.QualityControlStation;
const part: partInfo = {
name: QualityControlStationPart.SoftwareVersion,
//Same as above, the value here should be "v0.9" based on machineData.json
value: 0.9,
};
const expectedHealth = 100;
const result = calculatePartHealth(machineName, part);
expect(result).toBe(expectedHealth);
});
});
describe("calculateMachineHealth", () => {
it("should return 76.70138...9 based on a combination of parts and respective particular qualities", () => {
const machineName: MachineType = MachineType.WeldingRobot;
const parts = [
{ name: WeldingRobotPart.ErrorRate, value: 0.5 },
{ name: WeldingRobotPart.VibrationLevel, value: 4.0 },
{ name: WeldingRobotPart.ElectrodeWear, value: 0.8 },
{ name: WeldingRobotPart.ShieldingPressure, value: 12.0 },
{ name: WeldingRobotPart.WireFeedRate, value: 7.5 },
{ name: WeldingRobotPart.ArcStability, value: 92.0 },
{ name: WeldingRobotPart.SeamWidth, value: 1.5 },
{ name: WeldingRobotPart.CoolingEfficiency, value: 85.0 },
];
const expectedHealth = 76.70138888888889;
const result = calculateMachineHealth(machineName, parts);
expect(result).toBe(expectedHealth);
});
it("should return health 100 when machine with part optimal range is [0, 0] and normal range is [0, >0] but part quality is at 0", () => {
// Generating a dynamic test suite using data from ../../native-app/data/machineData.json
// Where we have test cases to check for the min, middle, and max value in each range (normal, abnormal, optimal)
// I came up to the realization that we have issues that initially could only be data issues from the machineData.json file
// When the optimal range is [0, 0] and normal range is [0, >0], it would be expected that a
// machine with a part with value of 0 would have a health score of 100, but we get a health score of 50 instead of 100
// Likely because the maximum and minimum are the same
const machineName: MachineType = MachineType.QualityControlStation;
const parts = [
{ name: QualityControlStationPart.CriteriaSettings, value: 0 },
];
// Conditional check to see if both values in
// machineData[MachineType.QualityControlStation][QualityControlStationPart.CriteriaSettings].optimalRange are 0
// To either skip the test or run the test
const { optimalRange } =
machineData[MachineType.QualityControlStation][
QualityControlStationPart.CriteriaSettings
];
const isMin0Max0OptimalRange =
optimalRange[0] === 0 && optimalRange[1] === 0;
if (isMin0Max0OptimalRange) {
const expectedHealth = 100;
const result = calculateMachineHealth(machineName, parts);
expect(result).toBe(expectedHealth);
} else {
console.log(
"Test skipped because optimal range is not [0, 0] in machine-data.json"
);
}
// Additionally, I could programatically try to find the machine and part with the optimal range of [0, 0]
// Instead of fixing it to QualityControlStation and CriteriaSettings
});
// TODO: More tests validating overall machine health score
// with different combinations of parts and respective qualities
// TODO: More tests validating overall factory health score
// with different combinations of machines, parts, and respective qualities
// TODO: More tests validating machine/parts that do not exist in machineData.json
// TODO: More tests validating extreme minimum and maximum values of qualities
// TODO: More tests around different types of values for parts (string, number, etc.)
// and how the API requests are handled on those cases
});