diff --git a/src/co2.test.js b/src/co2.test.js index 9a7af24..cd616b6 100644 --- a/src/co2.test.js +++ b/src/co2.test.js @@ -9,9 +9,10 @@ import pagexray from "pagexray"; import CO2 from "./co2.js"; import { averageIntensity, marginalIntensity } from "./index.js"; +const TwnGridIntensityValue = averageIntensity.data["TWN"]; + describe("co2", () => { let har, co2; - describe("1 byte model", () => { const { TGWF_GREY_VALUE, TGWF_GREEN_VALUE, TGWF_MIXED_VALUE } = ONEBYTE; @@ -484,7 +485,7 @@ describe("co2", () => { expect( co2.perVisitTrace(MILLION, false, { gridIntensity: { - device: 565.629, + device: 678.87, dataCenter: { country: "TWN" }, }, }).co2 @@ -493,7 +494,7 @@ describe("co2", () => { expect( co2.perByteTrace(MILLION, false, { gridIntensity: { - device: 565.629, + device: 678.87, dataCenter: { country: "TWN" }, network: { country: "TWN" }, }, @@ -542,7 +543,7 @@ describe("co2", () => { co2 .perVisitTrace(MILLION, false, { gridIntensity: { - device: 561, + device: TwnGridIntensityValue, }, }) .co2.toPrecision(5) @@ -559,7 +560,7 @@ describe("co2", () => { co2 .perByteTrace(MILLION, false, { gridIntensity: { - device: 561, + device: TwnGridIntensityValue, }, }) .co2.toPrecision(4) @@ -641,7 +642,7 @@ describe("co2", () => { co2 .perVisitTrace(MILLION, false, { gridIntensity: { - dataCenter: 561, + dataCenter: TwnGridIntensityValue, }, }) .co2.toPrecision(5) @@ -657,7 +658,7 @@ describe("co2", () => { co2 .perByteTrace(MILLION, false, { gridIntensity: { - dataCenter: 561, + dataCenter: TwnGridIntensityValue, }, }) .co2.toPrecision(5) @@ -740,14 +741,14 @@ describe("co2", () => { co2 .perVisitTrace(MILLION, false, { gridIntensity: { - network: 561, + network: TwnGridIntensityValue, }, }) .co2.toPrecision(5) ) ).toBeCloseTo( parseFloat( - MILLION_PERVISIT_GREY_NETWORK_GRID_INTENSITY_CHANGE.toPrecision(5) + MILLION_PERVISIT_GREY_NETWORK_GRID_INTENSITY_CHANGE.toFixed(5) ), 3 ); @@ -756,7 +757,7 @@ describe("co2", () => { co2 .perByteTrace(MILLION, false, { gridIntensity: { - network: 561, + network: TwnGridIntensityValue, }, }) .co2.toPrecision(5) diff --git a/src/constants/test-constants.js b/src/constants/test-constants.js index c645520..da86f83 100644 --- a/src/constants/test-constants.js +++ b/src/constants/test-constants.js @@ -10,37 +10,37 @@ export const ONEBYTE = { }; export const SWD = { - MILLION_GREY: 0.35418, - MILLION_GREEN: 0.30713, - MILLION_PERVISIT_GREY: 0.26765, - MILLION_PERVISIT_GREEN: 0.23188, + MILLION_GREY: 0.40008, + MILLION_GREEN: 0.34613, + MILLION_PERVISIT_GREY: 0.30206, + MILLION_PERVISIT_GREEN: 0.26133, - TGWF_GREY_VALUE: 0.24963, + TGWF_GREY_VALUE: 0.28198, TGWF_GREEN_VALUE: 0.54704, - TGWF_MIXED_VALUE: 0.21942, + TGWF_MIXED_VALUE: 0.24734, - MILLION_GREY_DEVICES: 0.18417, - MILLION_GREY_NETWORKS: 0.04959, - MILLION_GREY_DATACENTERS: 0.05313, + MILLION_GREY_DEVICES: 0.20803, + MILLION_GREY_NETWORKS: 0.05601, + MILLION_GREY_DATACENTERS: 0.06001, MILLION_GREEN_DATACENTERS: 0.00607, - MILLION_GREY_PRODUCTION: 0.06729, + MILLION_GREY_PRODUCTION: 0.07601, - MILLION_PERVISIT_GREY_DEVICE_GRID_INTENSITY_CHANGE: 0.30676, - MILLION_PERVISIT_GREY_DATACENTER_GRID_INTENSITY_CHANGE: 0.27876, - MILLION_PERVISIT_GREY_NETWORK_GRID_INTENSITY_CHANGE: 0.27800, + MILLION_PERVISIT_GREY_DEVICE_GRID_INTENSITY_CHANGE: 0.36087, + MILLION_PERVISIT_GREY_DATACENTER_GRID_INTENSITY_CHANGE: 0.31902, + MILLION_PERVISIT_GREY_NETWORK_GRID_INTENSITY_CHANGE: 0.31789, - MILLION_PERBYTE_GREY_DEVICE_GRID_INTENSITY_CHANGE: 0.40631, - MILLION_PERBYTE_GREY_DATACENTER_GRID_INTENSITY_CHANGE: 0.36922, - MILLION_PERBYTE_GREY_NETWORK_GRID_INTENSITY_CHANGE: 0.36821, + MILLION_PERBYTE_GREY_DEVICE_GRID_INTENSITY_CHANGE: 0.47800, + MILLION_PERBYTE_GREY_DATACENTER_GRID_INTENSITY_CHANGE: 0.42255, + MILLION_PERBYTE_GREY_NETWORK_GRID_INTENSITY_CHANGE: 0.42105, - MILLION_PERVISIT_GREY_DEVICES_FIRST: 0.13813, + MILLION_PERVISIT_GREY_DEVICES_FIRST: 0.15603, MILLION_PERVISIT_GREY_DEVICES_SECOND: 0.00092, MILLION_PERVISIT_GREY_NETWORKS_FIRST: 0.03719, MILLION_PERVISIT_GREY_NETWORKS_SECOND: 0.00025, - MILLION_PERVISIT_GREY_DATACENTERS_FIRST: 0.03985, + MILLION_PERVISIT_GREY_DATACENTERS_FIRST: 0.04501, MILLION_PERVISIT_GREY_DATACENTERS_SECOND: 0.00027, MILLION_PERVISIT_GREEN_DATACENTERS_FIRST: 0.00456, MILLION_PERVISIT_GREEN_DATACENTERS_SECOND: 0.00003, - MILLION_PERVISIT_GREY_PRODUCTION_FIRST: 0.05047, + MILLION_PERVISIT_GREY_PRODUCTION_FIRST: 0.05701, MILLION_PERVISIT_GREY_PRODUCTION_SECOND: 0.00034, }; diff --git a/src/sustainable-web-design.test.js b/src/sustainable-web-design.test.js index af19ad8..1aaad79 100644 --- a/src/sustainable-web-design.test.js +++ b/src/sustainable-web-design.test.js @@ -80,7 +80,7 @@ describe("sustainable web design model", () => { describe("emissionsPerVisitInGrams", () => { it("should calculate the correct co2 per visit", () => { const energy = swd.energyPerVisit(averageWebsiteInBytes); - expect(swd.emissionsPerVisitInGrams(energy)).toEqual(0.6); + expect(swd.emissionsPerVisitInGrams(energy)).toEqual(0.68); }); it("should accept a dynamic KwH value", () => {