adding ScatterChart2CsvConverterTest
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
<script src="./js/SymptomVsSymptomChartDataProvider.js"></script>
|
||||
<script src="./js/SymptomVsSymptomChartViewInitializer.js"></script>
|
||||
<script src="./js/DictUtils.js"></script>
|
||||
<script src="./js/ScatterChart2CsvConverter.js"></script>
|
||||
<script>
|
||||
document.addEventListener(
|
||||
"DOMContentLoaded",
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
class ScatterChart2CsvConverter {
|
||||
|
||||
static convertScatterChart2Csv({ symptomX, symptomY, batches, data }) {
|
||||
const header = `"Batch","PRR ratio of Batch for ${symptomX}","PRR ratio of Batch for ${symptomY}"`;
|
||||
return `${header}\n${ScatterChart2CsvConverter.#asCsv(batches, data)}`;
|
||||
}
|
||||
|
||||
static #asCsv(batches, data) {
|
||||
return Utils
|
||||
.zip([batches, data])
|
||||
.map(([batch, { x, y }]) => `${ScatterChart2CsvConverter.#quote(batch)},${x},${y}`)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
static #quote(str) {
|
||||
return '"' + str + '"';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
QUnit.module('ScatterChart2CsvConverterTest', function () {
|
||||
|
||||
QUnit.test('convertScatterChart2Csv', function (assert) {
|
||||
// Given
|
||||
const scatterChartDescr = {
|
||||
symptomX: 'Adult failure to thrive',
|
||||
symptomY: 'Acariasis',
|
||||
batches: ['002A21A', '002A21B'],
|
||||
data: [
|
||||
{
|
||||
x: 2.1,
|
||||
y: 3.1
|
||||
},
|
||||
{
|
||||
x: 4.1,
|
||||
y: 5.1
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
// When
|
||||
const csv = ScatterChart2CsvConverter.convertScatterChart2Csv(scatterChartDescr);
|
||||
|
||||
// Then
|
||||
const csvExpected =
|
||||
`"Batch","PRR ratio of Batch for Adult failure to thrive","PRR ratio of Batch for Acariasis"
|
||||
"002A21A",2.1,3.1
|
||||
"002A21B",4.1,5.1`;
|
||||
assert.equal(csv, csvExpected);
|
||||
});
|
||||
});
|
||||
@@ -3,12 +3,12 @@ QUnit.module('SymptomVsSymptomChartDataProviderTest', function () {
|
||||
QUnit.test('shouldProvideChartData', function (assert) {
|
||||
// Given
|
||||
const prrByLotX = {
|
||||
"lotX": 1.0,
|
||||
"lotCommon": 2.0
|
||||
'lotX': 1.0,
|
||||
'lotCommon': 2.0
|
||||
};
|
||||
const prrByLotY = {
|
||||
"lotCommon": 3.0,
|
||||
"lotY": 4.0
|
||||
'lotCommon': 3.0,
|
||||
'lotY': 4.0
|
||||
};
|
||||
|
||||
// When
|
||||
@@ -18,7 +18,7 @@ QUnit.module('SymptomVsSymptomChartDataProviderTest', function () {
|
||||
assert.deepEqual(
|
||||
chartData,
|
||||
{
|
||||
labels: ["lotCommon"],
|
||||
labels: ['lotCommon'],
|
||||
data: [
|
||||
{
|
||||
x: 2.0,
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<script src="../js/SymptomVsSymptomChartDataProvider.js"></script>
|
||||
<script src="../js/SymptomVsSymptomChartViewInitializer.js"></script>
|
||||
<script src="../js/DictUtils.js"></script>
|
||||
<script src="../js/ScatterChart2CsvConverter.js"></script>
|
||||
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.17.2.css">
|
||||
<script src="https://code.jquery.com/qunit/qunit-2.17.2.js"></script>
|
||||
<script type="text/javascript" src="./jshamcrest.js"></script>
|
||||
@@ -30,6 +31,7 @@
|
||||
</script>
|
||||
<script src="./SymptomVsSymptomChartDataProviderTest.js"></script>
|
||||
<script src="./DictUtilsTest.js"></script>
|
||||
<script src="./ScatterChart2CsvConverterTest.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@@ -24,4 +24,6 @@ class Utils {
|
||||
static sliceDict(dict, start, end) {
|
||||
return Object.fromEntries(Object.entries(dict).slice(start, end));
|
||||
}
|
||||
|
||||
static zip = rows => rows[0].map((_, c) => rows.map(row => row[c]))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user