Add test, update libs

pull/15/head
Michał Górny 2023-08-18 22:42:33 +02:00
rodzic 2628b152d8
commit 2b1c478f0e
8 zmienionych plików z 1664 dodań i 881 usunięć

2
README.md 100644
Wyświetl plik

@ -0,0 +1,2 @@
# sejm-calculator
Simulator for the Polish Sejm election

2517
package-lock.json wygenerowano

Plik diff jest za duży Load Diff

Wyświetl plik

@ -36,8 +36,8 @@
"@types/webpack": "^4.41.29",
"@types/webpack-dev-server": "^3.11.4",
"@types/webpack-livereload-plugin": "^2.3.2",
"@typescript-eslint/eslint-plugin": "^4.6.1",
"@typescript-eslint/parser": "^4.6.1",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"babel-loader": "^8.1.0",
"css-loader": "^3.2.0",
"cssnano": "^5.1.6",
@ -62,6 +62,7 @@
"stylelint-config-standard": "^20.0.0",
"stylelint-webpack-plugin": "^2.1.1",
"ts-jest": "^28.0.8",
"ts-node": "^10.9.1",
"typescript": "^4.0.5",
"webpack": "^4.44.2",
"webpack-cli": "^4.9.2",

Wyświetl plik

@ -18,7 +18,7 @@ export const clearInputs = (): void => {
};
export const clearResults = (): void => {
document.querySelectorAll<HTMLTableDataCellElement>('tr td:last-child').forEach((td) => {
document.querySelectorAll<HTMLTableCellElement>('tr td:last-child').forEach((td) => {
td.innerHTML = '';
});
barChart.detach();
@ -36,7 +36,7 @@ export const clearResults = (): void => {
const displayResults = (mandates: number[]) => {
mandates.forEach((value, index) => {
const committeeId = committees[index].id;
const td = document.querySelector<HTMLTableDataCellElement>(`tr.${committeeId} td:last-child`);
const td = document.querySelector<HTMLTableCellElement>(`tr.${committeeId} td:last-child`);
if (td) td.textContent = value.toString();
});
};

Wyświetl plik

@ -7,8 +7,8 @@ const calculateLocalSupport = (
constituency: Constituency,
): number[] => {
const localPastSupport = constituency.pastSupport;
const localPastSupportProjection = support.map((committeeSupport, index) => (
committees[index].pastSupportEquivalence
const localPastSupportProjection = committees.map((committee) => (
committee.pastSupportEquivalence
.map((pastCommittee) => localPastSupport[pastCommittee[0]] * pastCommittee[1])
.reduce((a, b) => a + b, 0)
));
@ -26,8 +26,8 @@ const calculateLocalSupport = (
};
export default (support: number[]): number[] => {
const pastSupportProjection = support.map((committeeSupport, index) => (
committees[index].pastSupportEquivalence
const pastSupportProjection = committees.map((committee) => (
committee.pastSupportEquivalence
.map((pastCommittee) => pastSupport[pastCommittee[0]] * pastCommittee[1])
.reduce((a, b) => a + b, 0)
));

Wyświetl plik

@ -1,4 +1,4 @@
h1.main-heading Kalkulator mandatów w wyborach do Sejmu
h1 Kalkulator mandatów w wyborach do Sejmu
p.
Kalkulator zwraca szacowany rozkład mandatów w Sejmie na podstawie wyników sondażowych.

Wyświetl plik

@ -13,3 +13,10 @@ test('calculates correct results (2)', () => {
expect(mandates).toEqual([182, 133, 40, 34, 12, 58, 1]);
});
test('calculates correct results (3)', () => {
const support = [39.7, 42.4, 0, 0, 7.2, 0];
const mandates = calculateMandates(support);
expect(mandates).toEqual([225, 216, 0, 0, 18, 0, 1]);
});