initial commit

This commit is contained in:
2026-10-07 01:48:32 +03:00
commit 664421662c
70 changed files with 11333 additions and 0 deletions

38
test/stopGroups.test.mjs Normal file
View File

@@ -0,0 +1,38 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { countLabel, directionLabel, groupStops } from '../src/lib/stopGroups.ts';
test('names are grouped like the landing while direction IDs remain independent', () => {
const groups = groupStops([
{ id: 1, name: ' Площадь Свободы ', direction: 'В центр', routesCount: 2 },
{ id: 2, name: 'площадь свободы', direction: 'Из центра', routesCount: 3 },
{ id: 1, name: 'Площадь Свободы', direction: 'Duplicate ID', routesCount: 2 },
{ id: 3, name: 'Автовокзал', direction: '', routesCount: 1 },
]);
assert.equal(groups.length, 2);
assert.equal(groups[0].name, 'Автовокзал');
assert.equal(groups[1].name, 'Площадь Свободы');
assert.deepEqual(groups[1].stops.map(stop => stop.id), [1, 2]);
});
test('direction labels distinguish unlabeled and repeated directions', () => {
const stops = [
{ id: 1, name: 'Вокзал', direction: 'В центр', routesCount: 2 },
{ id: 2, name: 'Вокзал', direction: 'В центр', routesCount: 2 },
{ id: 3, name: 'Вокзал', direction: '', routesCount: 2 },
];
const group = groupStops(stops)[0];
assert.equal(directionLabel(group, stops[0], 0), 'В центр · 1');
assert.equal(directionLabel(group, stops[1], 1), 'В центр · 2');
assert.equal(directionLabel(group, stops[2], 2), 'Направление 3');
});
test('the list retains more than eighty stops and uses correct count labels', () => {
const stops = Array.from({ length: 120 }, (_, index) => ({ id: index + 1, name: `Остановка ${index + 1}`, direction: '', routesCount: 1 }));
assert.equal(groupStops(stops).length, 120);
const forms = ['остановка', 'остановки', 'остановок'];
assert.equal(countLabel(1, forms), '1 остановка');
assert.equal(countLabel(2, forms), '2 остановки');
assert.equal(countLabel(11, forms), '11 остановок');
assert.equal(countLabel(21, forms), '21 остановка');
});