2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-11-21 14:52:38 +00:00
|
|
|
|
|
|
|
import { expect } from "./expect.ts";
|
2024-04-29 02:57:30 +00:00
|
|
|
import { AssertionError, assertThrows } from "@std/assert";
|
2023-11-21 14:52:38 +00:00
|
|
|
|
|
|
|
Deno.test("expect().toBeCloseTo()", () => {
|
|
|
|
expect(0.2 + 0.1).toBeCloseTo(0.3);
|
|
|
|
expect(0.2 + 0.1).toBeCloseTo(0.3, 5);
|
|
|
|
expect(0.2 + 0.1).toBeCloseTo(0.3, 15);
|
|
|
|
|
|
|
|
expect(0.2 + 0.11).not.toBeCloseTo(0.3);
|
|
|
|
expect(0.2 + 0.1).not.toBeCloseTo(0.3, 16);
|
|
|
|
|
|
|
|
assertThrows(() => {
|
|
|
|
expect(0.2 + 0.11).toBeCloseTo(0.3);
|
|
|
|
}, AssertionError);
|
|
|
|
|
|
|
|
assertThrows(() => {
|
|
|
|
expect(0.2 + 0.1).not.toBeCloseTo(0.3);
|
|
|
|
});
|
|
|
|
});
|
2024-07-01 09:13:47 +00:00
|
|
|
|
|
|
|
Deno.test("expect().toBeCloseTo() throws error when the numDigits is smaller than 0", () => {
|
|
|
|
assertThrows(
|
|
|
|
() => expect(0.2 + 0.1).toBeCloseTo(0.3, -1),
|
|
|
|
Error,
|
|
|
|
"toBeCloseTo second argument must be a non-negative integer. Got -1",
|
|
|
|
);
|
|
|
|
});
|