|
| 1 | +import { binaryLCM, lowestCommonMultiple, naiveLCM } from "../LowestCommonMultiple"; |
| 2 | + |
| 3 | +describe("naiveLCM", () => { |
| 4 | + test.each([[[3, 4], 12], [[8, 6], 24], [[5, 8, 3], 120], [[0.8, 0.4], 0.8]])( |
| 5 | + "of given two numbers is correct", |
| 6 | + (nums, expected) => { |
| 7 | + expect(naiveLCM(nums)).toBe(expected); |
| 8 | + }, |
| 9 | + ); |
| 10 | + |
| 11 | + test("only positive numbers should be accepted", () => { |
| 12 | + expect(() => naiveLCM([-2, -3])).toThrowError( |
| 13 | + "numbers must be positive to determine lowest common multiple", |
| 14 | + ); |
| 15 | + }); |
| 16 | + |
| 17 | + test("at least one number must be passed in", () => { |
| 18 | + expect(() => naiveLCM([])).toThrowError( |
| 19 | + "at least one number must be passed in", |
| 20 | + ); |
| 21 | + }); |
| 22 | +}); |
| 23 | + |
| 24 | +describe("binaryLCM", () => { |
| 25 | + test.each([[3, 4, 12], [8, 6, 24], [8, 16, 16]])( |
| 26 | + "of given two numbers is correct", |
| 27 | + (numa, numb, expected) => { |
| 28 | + expect(binaryLCM(numa, numb)).toBe(expected); |
| 29 | + }, |
| 30 | + ); |
| 31 | + |
| 32 | + test("only whole numbers should be accepted", () => { |
| 33 | + expect(() => binaryLCM(-2, -3)).toThrowError( |
| 34 | + "numbers must be positive to determine lowest common multiple", |
| 35 | + ); |
| 36 | + }); |
| 37 | +}); |
| 38 | + |
| 39 | +describe("lowestCommonMultiple", () => { |
| 40 | + test.each([[[3, 4], 12], [[8, 6], 24], [[5, 8, 3], 120], [[8, 16], 16]])( |
| 41 | + "of given two numbers is correct", |
| 42 | + (nums, expected) => { |
| 43 | + expect(lowestCommonMultiple(nums)).toBe(expected); |
| 44 | + }, |
| 45 | + ); |
| 46 | + |
| 47 | + test("only positive numbers should be accepted", () => { |
| 48 | + expect(() => lowestCommonMultiple([-2, -3])).toThrowError( |
| 49 | + "numbers must be positive to determine lowest common multiple", |
| 50 | + ); |
| 51 | + }); |
| 52 | + |
| 53 | + test("at least one number must be passed in", () => { |
| 54 | + expect(() => lowestCommonMultiple([])).toThrowError( |
| 55 | + "at least one number must be passed in", |
| 56 | + ); |
| 57 | + }); |
| 58 | +}); |
0 commit comments