adding UtilsTest.convertDict2CSV
This commit is contained in:
@@ -24,4 +24,17 @@ class Utils {
|
|||||||
static sliceDict(dict, start, end) {
|
static sliceDict(dict, start, end) {
|
||||||
return Object.fromEntries(Object.entries(dict).slice(start, end));
|
return Object.fromEntries(Object.entries(dict).slice(start, end));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static convertDict2CSV(dict) {
|
||||||
|
const {'keys': columns, 'values': firstRow} = Utils.getKeysAlignedWithValues(dict);
|
||||||
|
return `${Utils.#quoteValues(columns)}\n${firstRow}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static #quoteValues(values) {
|
||||||
|
return values.map(Utils.#quoteValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
static #quoteValue(value) {
|
||||||
|
return '"' + value + '"';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17
test/SymptomsCausedByVaccines/UtilsTest.js
Normal file
17
test/SymptomsCausedByVaccines/UtilsTest.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
QUnit.module('UtilsTest', function () {
|
||||||
|
|
||||||
|
QUnit.test('convertDict2CSV', function (assert) {
|
||||||
|
// Given
|
||||||
|
const dict = {
|
||||||
|
"MM,R": 26.17432376240791,
|
||||||
|
"VARCEL": 10.549534724816644
|
||||||
|
};
|
||||||
|
|
||||||
|
// When
|
||||||
|
const csv = Utils.convertDict2CSV(dict);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
const csvExpected = '"MM,R","VARCEL"\n26.17432376240791,10.549534724816644';
|
||||||
|
assert.equal(csv, csvExpected);
|
||||||
|
});
|
||||||
|
});
|
||||||
36
test/SymptomsCausedByVaccines/index.test.html
Normal file
36
test/SymptomsCausedByVaccines/index.test.html
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
||||||
|
<!-- Meta, title, CSS, favicons, etc. -->
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta content="IE=edge" http-equiv="X-UA-Compatible" />
|
||||||
|
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
|
||||||
|
<title>Symptoms caused by Vaccines</title>
|
||||||
|
<script src="../../docs/Utils.js"></script>
|
||||||
|
<script src="../../docs/UIUtils.js"></script>
|
||||||
|
<script src="../../docs/NumberWithBarElementFactory.js"></script>
|
||||||
|
<script src="../../docs/SymptomsCausedByVaccines/js/PageInitializer.js"></script>
|
||||||
|
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByVaccineProvider.js"></script>
|
||||||
|
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByVaccineTable.js"></script>
|
||||||
|
<script src="../../docs/SymptomsCausedByVaccines/js/PrrBySymptomTable.js"></script>
|
||||||
|
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByVaccineTableView.js"></script>
|
||||||
|
<script src="../../docs/SymptomsCausedByVaccines/js/PrrBySymptomTableView.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>
|
||||||
|
<script type="text/javascript" src="./jsmockito-1.0.4.js"></script>
|
||||||
|
<script>
|
||||||
|
JsHamcrest.Integration.QUnit();
|
||||||
|
JsMockito.Integration.QUnit();
|
||||||
|
</script>
|
||||||
|
<script src="./UtilsTest.js"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="nav-md">
|
||||||
|
<div id="qunit"></div>
|
||||||
|
<div id="qunit-fixture"></div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
1500
test/SymptomsCausedByVaccines/jshamcrest.js
Normal file
1500
test/SymptomsCausedByVaccines/jshamcrest.js
Normal file
File diff suppressed because it is too large
Load Diff
1019
test/SymptomsCausedByVaccines/jsmockito-1.0.4.js
Normal file
1019
test/SymptomsCausedByVaccines/jsmockito-1.0.4.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user