Skip to content

Commit

Permalink
comments with calculations in the tests
Browse files Browse the repository at this point in the history
from review, adding the calculations in comments with the tests helps to make the arithmetic more credible

#1098 (review)
  • Loading branch information
Abby Wheelis committed Dec 4, 2023
1 parent c1f6dc3 commit 0b471e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
14 changes: 14 additions & 0 deletions www/__tests__/footprintHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,38 @@ const custom_metrics = [
{ key: 'unicycle', values: 5000 },
];

/*
3*0 + 6.5*0 + 10*0.22031 + 25*0.00894 + 5*0
0 + 0 + 2.2031 + 0.2235 + 0
2.4266
*/
it('gets footprint for metrics (custom, fallback 0)', async () => {
const appConfig = await getConfig();
await initCustomDatasetHelper(appConfig);
expect(getFootprintForMetrics(custom_metrics, 0)).toBe(2.4266);
});

/*
3*0 + 6.5*0 + 10*0.22031 + 25*0.00894 + 5*0.1
0 + 0 + 2.2031 + 0.2235 + 0.5
2.4266 + 0.5
*/
it('gets footprint for metrics (custom, fallback 0.1)', async () => {
const appConfig = await getConfig();
await initCustomDatasetHelper(appConfig);
expect(getFootprintForMetrics(custom_metrics, 0.1)).toBe(2.4266 + 0.5);
});

//expects TAXI from the fake labels
it('gets the highest footprint from the dataset, custom', async () => {
const appConfig = await getConfig();
await initCustomDatasetHelper(appConfig);
expect(getHighestFootprint()).toBe(0.30741);
});

/*
TAXI co2/km * meters/1000
*/
it('gets the highest footprint for distance, custom', async () => {
const appConfig = await getConfig();
await initCustomDatasetHelper(appConfig);
Expand Down
20 changes: 10 additions & 10 deletions www/__tests__/metHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ global.fetch = (url: string) =>
}) as any;

it('gets met for mode and speed', () => {
expect(getMet('WALKING', 1.47523, 0)).toBe(4.3);
expect(getMet('BICYCLING', 4.5, 0)).toBe(6.8);
expect(getMet('UNICYCLE', 100, 0)).toBe(0);
expect(getMet('CAR', 25, 1)).toBe(0);
expect(getMet('WALKING', 1.47523, 0)).toBe(4.3); //1.47523 mps = 3.299 mph -> 4.3 METs
expect(getMet('BICYCLING', 4.5, 0)).toBe(6.8); //4.5 mps = 10.07 mph = 6.8 METs
expect(getMet('UNICYCLE', 100, 0)).toBe(0); //unkown mode, 0 METs
expect(getMet('CAR', 25, 1)).toBe(0); //0 METs in CAR
});

it('gets custom met for mode and speed', async () => {
const appConfig = await getConfig();
await initCustomDatasetHelper(appConfig);
expect(getMet('walk', 1.47523, 0)).toBe(4.3);
expect(getMet('bike', 4.5, 0)).toBe(6.8);
expect(getMet('unicycle', 100, 0)).toBe(0);
expect(getMet('drove_alone', 25, 1)).toBe(0);
expect(getMet('e-bike', 6, 1)).toBe(4.9);
expect(getMet('e-bike', 12, 1)).toBe(4.9);
expect(getMet('walk', 1.47523, 0)).toBe(4.3); //1.47523 mps = 3.299 mph -> 4.3 METs
expect(getMet('bike', 4.5, 0)).toBe(6.8); //4.5 mps = 10.07 mph = 6.8 METs
expect(getMet('unicycle', 100, 0)).toBe(0); //unkown mode, 0 METs
expect(getMet('drove_alone', 25, 1)).toBe(0); //0 METs IN_VEHICLE
expect(getMet('e-bike', 6, 1)).toBe(4.9); //e-bike is 4.9 for all speeds
expect(getMet('e-bike', 12, 1)).toBe(4.9); //e-bike is 4.9 for all speeds
});

0 comments on commit 0b471e5

Please sign in to comment.