Moar unit tests

pull/1496/head
Piero Toffanin 2024-05-09 09:27:10 -04:00
rodzic d46b582dcd
commit ece6bba200
2 zmienionych plików z 39 dodań i 17 usunięć

Wyświetl plik

@ -2,68 +2,57 @@ import { _ } from './gettext';
const units = { const units = {
acres: { acres: {
factor: 0.00024711, factor: 1 / 4046.85642,
label: _('Acres'),
abbr: 'ac', abbr: 'ac',
round: 5 round: 5
}, },
feet: { feet: {
factor: 3.2808, factor: 3.28084,
label: _('Feet'),
abbr: 'ft', abbr: 'ft',
round: 4 round: 4
}, },
hectares: { hectares: {
factor: 0.0001, factor: 0.0001,
label: _('Hectares'),
abbr: 'ha', abbr: 'ha',
round: 4 round: 4
}, },
meters: { meters: {
factor: 1, factor: 1,
label: _('Meters'),
abbr: 'm', abbr: 'm',
round: 3 round: 3
}, },
kilometers: { kilometers: {
factor: 0.001, factor: 0.001,
label: _('Kilometers'),
abbr: 'km', abbr: 'km',
round: 5 round: 5
}, },
centimeters: { centimeters: {
factor: 100, factor: 100,
label: _('Centimeters'),
abbr: 'cm', abbr: 'cm',
round: 1 round: 1
}, },
miles: { miles: {
factor: 3.2808 / 5280, factor: 3.28084 / 5280,
label: _('Miles'),
abbr: 'mi', abbr: 'mi',
round: 5 round: 5
}, },
sqfeet: { sqfeet: {
factor: 10.7639, factor: 1 / 0.09290304,
label: _('Square Feet'),
abbr: 'ft²', abbr: 'ft²',
round: 2 round: 2
}, },
sqmeters: { sqmeters: {
factor: 1, factor: 1,
label: _('Square Meters'),
abbr: 'm²', abbr: 'm²',
round: 2 round: 2
}, },
sqmeters: { sqkilometers: {
factor: 0.000001, factor: 0.000001,
label: _('Square Kilometers'),
abbr: 'km²', abbr: 'km²',
round: 5 round: 5
}, },
sqmiles: { sqmiles: {
factor: 0.000000386102, factor: 0.000000386102,
label: _('Square Miles'),
abbr: 'mi²', abbr: 'mi²',
round: 5 round: 5
} }

Wyświetl plik

@ -31,7 +31,8 @@ describe('Metric system', () => {
[11005, "1.1005 ha"], [11005, "1.1005 ha"],
[999999, "99.9999 ha"], [999999, "99.9999 ha"],
[1000000, "1 km²"], [1000000, "1 km²"],
[1000000000, "1,000 km²"] [1000000000, "1,000 km²"],
[1000255558, "1,000.25556 km²"]
]; ];
areas.forEach(a => { areas.forEach(a => {
@ -39,3 +40,35 @@ describe('Metric system', () => {
}); });
}) })
}); });
describe('Imperial system', () => {
it('it should display units properly', () => {
const { imperial } = systems;
const lengths = [
[1, "3.2808 ft"],
[0.01, "0.0328 ft"],
[0.0154, "0.0505 ft"],
[1609, "5,278.8716 ft"],
[1609.344, "1 mi"],
[3218.69, "2 mi"]
];
lengths.forEach(l => {
expect(imperial.length(l[0]).toString()).toBe(l[1]);
});
const areas = [
[1, "10.76 ft²"],
[9999, "2.47081 ac"],
[4046.86, "1 ac"],
[2587398.1, "639.35999 ac"],
[2.59e+6, "1 mi²"]
];
areas.forEach(a => {
expect(imperial.area(a[0]).toString()).toBe(a[1]);
});
})
});