Skip to content

Commit

Permalink
refactor(constants): changing gibibyte to gigabyte calculation (#66)
Browse files Browse the repository at this point in the history
* refactor(constants): changing gibibyte to gigabyte calculation

* refactor(tests): update test assertions

Co-authored-by: Chris Adams <chris@productscience.co.uk>
  • Loading branch information
drydenwilliams and mrchrisadams authored Apr 19, 2022
1 parent 2738547 commit 3e17b29
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/constants/file-size.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const GIGABYTE = 1024 * 1024 * 1024;
const GIGABYTE = 1000 * 1000 * 1000;

module.exports = {
GIGABYTE,
Expand Down
8 changes: 3 additions & 5 deletions src/sustainable-web-design.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,21 @@ describe("sustainable web design model", () => {
});

it("should calculate the correct energy", () => {
expect(swd.energyPerVisit(averageWebsiteInBytes)).toBe(
0.0004513362121582032
);
expect(swd.energyPerVisit(2257715.2)).toBe(0.00048461856768000004);
});
});

describe("emissionsPerVisitInGrams", function () {
it("should calculate the correct co2 per visit", () => {
const averageWebsiteInBytes = 2257715.2;
const energy = swd.energyPerVisit(averageWebsiteInBytes);
expect(swd.emissionsPerVisitInGrams(energy)).toEqual(0.2);
expect(swd.emissionsPerVisitInGrams(energy)).toEqual(0.21);
});

it("should accept a dynamic KwH value", () => {
const averageWebsiteInBytes = 2257715.2;
const energy = swd.energyPerVisit(averageWebsiteInBytes);
expect(swd.emissionsPerVisitInGrams(energy, 245)).toEqual(0.11);
expect(swd.emissionsPerVisitInGrams(energy, 245)).toEqual(0.12);
});
});

Expand Down

0 comments on commit 3e17b29

Please sign in to comment.