Skip to content

Commit

Permalink
add some forgiveness to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fershad committed Oct 9, 2023
1 parent c2a805a commit 26972e4
Showing 1 changed file with 68 additions and 62 deletions.
130 changes: 68 additions & 62 deletions src/co2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ describe("co2", () => {
})
.co2.toPrecision(5)
)
).toBe(MILLION_PERVISIT_GREY);
).toBeCloseTo(MILLION_PERVISIT_GREY, 5);

expect(
parseFloat(
Expand All @@ -485,7 +485,7 @@ describe("co2", () => {
})
.co2.toPrecision(5)
)
).toBe(MILLION_GREY);
).toBeCloseTo(MILLION_GREY, 5);
});

it("uses a number correctly", () => {
Expand All @@ -512,27 +512,31 @@ describe("co2", () => {

it("uses an object correctly", () => {
expect(
co2
.perVisitTrace(MILLION, false, {
gridIntensity: {
device: {
country: "TWN",
parseFloat(
co2
.perVisitTrace(MILLION, false, {
gridIntensity: {
device: {
country: "TWN",
},
},
},
})
.co2.toPrecision(5)
).toBe(MILLION_PERVISIT_GREY_DEVICE_GRID_INTENSITY_CHANGE.toPrecision(5));
})
.co2.toFixed(5)
)
).toBeCloseTo(MILLION_PERVISIT_GREY_DEVICE_GRID_INTENSITY_CHANGE, 4);
expect(
co2
.perByteTrace(MILLION, false, {
gridIntensity: {
device: {
country: "TWN",
parseFloat(
co2
.perByteTrace(MILLION, false, {
gridIntensity: {
device: {
country: "TWN",
},
},
},
})
.co2.toPrecision(4)
).toBe(MILLION_PERBYTE_GREY_DEVICE_GRID_INTENSITY_CHANGE.toPrecision(4));
})
.co2.toPrecision(4)
)
).toBeCloseTo(MILLION_PERBYTE_GREY_DEVICE_GRID_INTENSITY_CHANGE, 4);
});
});

Expand Down Expand Up @@ -596,31 +600,31 @@ describe("co2", () => {

it("uses an object correctly", () => {
expect(
co2
.perVisitTrace(MILLION, false, {
gridIntensity: {
dataCenter: {
country: "TWN",
parseFloat(
co2
.perVisitTrace(MILLION, false, {
gridIntensity: {
dataCenter: {
country: "TWN",
},
},
},
})
.co2.toPrecision(5)
).toBe(
MILLION_PERVISIT_GREY_DATACENTER_GRID_INTENSITY_CHANGE.toPrecision(5)
);
})
.co2.toPrecision(5)
)
).toBeCloseTo(MILLION_PERVISIT_GREY_DATACENTER_GRID_INTENSITY_CHANGE, 4);
expect(
co2
.perByteTrace(MILLION, false, {
gridIntensity: {
dataCenter: {
country: "TWN",
parseFloat(
co2
.perByteTrace(MILLION, false, {
gridIntensity: {
dataCenter: {
country: "TWN",
},
},
},
})
.co2.toPrecision(5)
).toBe(
MILLION_PERBYTE_GREY_DATACENTER_GRID_INTENSITY_CHANGE.toPrecision(5)
);
})
.co2.toPrecision(5)
)
).toBeCloseTo(MILLION_PERBYTE_GREY_DATACENTER_GRID_INTENSITY_CHANGE, 4);
});
});

Expand Down Expand Up @@ -683,29 +687,31 @@ describe("co2", () => {

it("uses an object correctly", () => {
expect(
co2
.perVisitTrace(MILLION, false, {
gridIntensity: {
network: {
country: "TWN",
parseFloat(
co2
.perVisitTrace(MILLION, false, {
gridIntensity: {
network: {
country: "TWN",
},
},
},
})
.co2.toPrecision(5)
).toBe(
MILLION_PERVISIT_GREY_NETWORK_GRID_INTENSITY_CHANGE.toPrecision(5)
);
})
.co2.toPrecision(5)
)
).toBeCloseTo(MILLION_PERVISIT_GREY_NETWORK_GRID_INTENSITY_CHANGE, 4);
expect(
co2
.perByteTrace(MILLION, false, {
gridIntensity: {
network: {
country: "TWN",
parseFloat(
co2
.perByteTrace(MILLION, false, {
gridIntensity: {
network: {
country: "TWN",
},
},
},
})
.co2.toPrecision(5)
).toBe(MILLION_PERBYTE_GREY_NETWORK_GRID_INTENSITY_CHANGE.toPrecision(5));
})
.co2.toPrecision(5)
)
).toBeCloseTo(MILLION_PERBYTE_GREY_NETWORK_GRID_INTENSITY_CHANGE, 4);
});
});

Expand Down

0 comments on commit 26972e4

Please sign in to comment.