Import initial : code en production sur Hetzner
This commit is contained in:
commit
cf6ee64e31
43 changed files with 14404 additions and 0 deletions
42
test/unit/estimate.spec.ts
Normal file
42
test/unit/estimate.spec.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
import { estimateTrainTrip } from '../../server/utils/estimate'
|
||||
|
||||
describe('estimateTrainTrip', () => {
|
||||
const grenoble = { lat: 45.1885, lon: 5.7245 }
|
||||
const marseille = { lat: 43.2965, lon: 5.3698 }
|
||||
const lille = { lat: 50.6292, lon: 3.0573 }
|
||||
const paris = { lat: 48.8566, lon: 2.3522 }
|
||||
|
||||
it('renvoie un objet marque comme estime', () => {
|
||||
const trip = estimateTrainTrip(grenoble, marseille)
|
||||
expect(trip.estimated).toBe(true)
|
||||
expect(trip.mode).toBe('train')
|
||||
})
|
||||
|
||||
it('estime Grenoble-Marseille (vol oiseau 216 km, ferroviaire ~260 km)', () => {
|
||||
const trip = estimateTrainTrip(grenoble, marseille)
|
||||
expect(trip.distanceKm).toBeGreaterThan(230)
|
||||
expect(trip.distanceKm).toBeLessThan(290)
|
||||
// A 90 km/h : entre 2h30 et 3h20 environ
|
||||
expect(trip.durationMin).toBeGreaterThan(150)
|
||||
expect(trip.durationMin).toBeLessThan(200)
|
||||
})
|
||||
|
||||
it('estime Lille-Paris (vol oiseau 203 km, ferroviaire ~245 km)', () => {
|
||||
const trip = estimateTrainTrip(lille, paris)
|
||||
expect(trip.distanceKm).toBeGreaterThan(220)
|
||||
expect(trip.distanceKm).toBeLessThan(280)
|
||||
})
|
||||
|
||||
it('renvoie une geometrie a deux points', () => {
|
||||
const trip = estimateTrainTrip(grenoble, marseille)
|
||||
expect(trip.geometry).toHaveLength(2)
|
||||
expect(trip.geometry[0]).toEqual([grenoble.lon, grenoble.lat])
|
||||
expect(trip.geometry[1]).toEqual([marseille.lon, marseille.lat])
|
||||
})
|
||||
|
||||
it('calcule le CO2 avec le facteur ADEME train (2.4 g/km)', () => {
|
||||
const trip = estimateTrainTrip(grenoble, marseille)
|
||||
expect(trip.co2Grams).toBeCloseTo(trip.distanceKm * 2.4, 0)
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue