refining SymptomVsSymptomChartDataProviderTest
This commit is contained in:
@@ -1,13 +1,31 @@
|
|||||||
class SymptomVsSymptomChartDataProvider {
|
class SymptomVsSymptomChartDataProvider {
|
||||||
|
|
||||||
static retainCommonLots({ prrByLotX, prrByLotY }) {
|
// FK-TODO: extract utility class and test
|
||||||
const commonLots = SymptomVsSymptomChartDataProvider.#getCommonKeys(prrByLotX, prrByLotY);
|
static retainCommonKeys({ dict1, dict2 }) {
|
||||||
|
const commonKeys = SymptomVsSymptomChartDataProvider.#getCommonKeys(dict1, dict2);
|
||||||
return {
|
return {
|
||||||
prrByLotX: SymptomVsSymptomChartDataProvider.#retainKeysOfDict(prrByLotX, commonLots),
|
dict1: SymptomVsSymptomChartDataProvider.#retainKeysOfDict(dict1, commonKeys),
|
||||||
prrByLotY: SymptomVsSymptomChartDataProvider.#retainKeysOfDict(prrByLotY, commonLots)
|
dict2: SymptomVsSymptomChartDataProvider.#retainKeysOfDict(dict2, commonKeys)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getChartData({ prrByLotX, prrByLotY }) {
|
||||||
|
const { dict1: prrByLotXCommon, dict2: prrByLotYCommon } =
|
||||||
|
SymptomVsSymptomChartDataProvider.retainCommonKeys(
|
||||||
|
{
|
||||||
|
dict1: prrByLotX,
|
||||||
|
dict2: prrByLotY
|
||||||
|
});
|
||||||
|
return Object
|
||||||
|
.keys(prrByLotXCommon)
|
||||||
|
.map(
|
||||||
|
lot =>
|
||||||
|
({
|
||||||
|
x: prrByLotXCommon[lot],
|
||||||
|
y: prrByLotYCommon[lot]
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
static #getCommonKeys(dict1, dict2) {
|
static #getCommonKeys(dict1, dict2) {
|
||||||
return Sets.intersection(
|
return Sets.intersection(
|
||||||
SymptomVsSymptomChartDataProvider.#getKeySet(dict1),
|
SymptomVsSymptomChartDataProvider.#getKeySet(dict1),
|
||||||
|
|||||||
@@ -5,48 +5,73 @@ QUnit.module('SymptomVsSymptomChartDataProviderTest', function () {
|
|||||||
[
|
[
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
prrByLotX: {
|
dict1: {
|
||||||
"lotX": 1.0
|
"lotX": 1.0
|
||||||
},
|
},
|
||||||
prrByLotY: {
|
dict2: {
|
||||||
"lotY": 2.0
|
"lotY": 2.0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
prrByLotX: {
|
dict1: {
|
||||||
},
|
},
|
||||||
prrByLotY: {
|
dict2: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
prrByLotX: {
|
dict1: {
|
||||||
"lotX": 1.0,
|
"lotX": 1.0,
|
||||||
"lotCommon": 2.0
|
"lotCommon": 2.0
|
||||||
},
|
},
|
||||||
prrByLotY: {
|
dict2: {
|
||||||
"lotCommon": 3.0,
|
"lotCommon": 3.0,
|
||||||
"lotY": 4.0
|
"lotY": 4.0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
prrByLotX: {
|
dict1: {
|
||||||
"lotCommon": 2.0
|
"lotCommon": 2.0
|
||||||
},
|
},
|
||||||
prrByLotY: {
|
dict2: {
|
||||||
"lotCommon": 3.0
|
"lotCommon": 3.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
(assert, [dataSets, mergedDataSets]) => {
|
(assert, [dicts, dictsHavingCommonKeys]) => {
|
||||||
// Given
|
// Given
|
||||||
|
|
||||||
// When
|
// When
|
||||||
const mergedDataSetsActual = SymptomVsSymptomChartDataProvider.retainCommonLots(dataSets);
|
const dictsHavingCommonKeysActual = SymptomVsSymptomChartDataProvider.retainCommonKeys(dicts);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
assert.deepEqual(mergedDataSetsActual, mergedDataSets);
|
assert.deepEqual(dictsHavingCommonKeysActual, dictsHavingCommonKeys);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('shouldProvideChartData', function (assert) {
|
||||||
|
// Given
|
||||||
|
const prrByLotX = {
|
||||||
|
"lotX": 1.0,
|
||||||
|
"lotCommon": 2.0
|
||||||
|
};
|
||||||
|
const prrByLotY = {
|
||||||
|
"lotCommon": 3.0,
|
||||||
|
"lotY": 4.0
|
||||||
|
};
|
||||||
|
|
||||||
|
// When
|
||||||
|
const chartData = SymptomVsSymptomChartDataProvider.getChartData({ prrByLotX, prrByLotY });
|
||||||
|
|
||||||
|
// Then
|
||||||
|
assert.deepEqual(
|
||||||
|
chartData,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
x: 2.0,
|
||||||
|
y: 3.0
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user