forked from m426-2026/math
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgcd_tests.ts
More file actions
31 lines (27 loc) · 781 Bytes
/
gcd_tests.ts
File metadata and controls
31 lines (27 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { assertEquals, assertThrows } from "@std/assert";
import { GCD } from "./gcd.ts";
const testVariables = [
{ a: 7, b: 5, gcd: 1 },
{ a: 6, b: 1, gcd: 1 },
{ a: 0, b: 6, gcd: 1 },
{ a: 81, b: 36, gcd: 9 },
];
Deno.test("GCD(bruteForce) using testVariables", () => {
for (const { a, b, gcd } of testVariables) {
//Arrange & Act
const actual = GCD.bruteForce(a, b);
//Assert
assertEquals(actual, gcd);
}
});
Deno.test("GCD(euclid) using testVariables", () => {
for (const { a, b, gcd } of testVariables) {
//Arrange & Act
const actual = GCD.euclid(a, b);
//Assert
assertEquals(actual, gcd);
}
});
Deno.test("GCD null division check (error thrown)", () => {
assertThrows(() => GCD.euclid(3, 0), `can't divide by 0`);
})