test multoply and divide
This commit is contained in:
parent
62b7182133
commit
9babbf846c
@ -1,17 +1,26 @@
|
||||
import {divide} from "./index";
|
||||
import { divide } from "./index";
|
||||
|
||||
describe("Test multiply", () => {
|
||||
describe("Test divide", () => {
|
||||
it.each([
|
||||
{ a: 2, b : 1, expected: 2 },
|
||||
{ a: 2, b: 1, expected: 2 },
|
||||
{ a: 10, b: 2, expected: 5 },
|
||||
{ a: 50, b: 5, expected: 10 },
|
||||
])(
|
||||
"should return multiplication of A by B",
|
||||
"should return division of $b by $a",
|
||||
({ a, b, expected }) => {
|
||||
// arrange
|
||||
// act
|
||||
const result = divide(a,b);
|
||||
const result = divide(a, b);
|
||||
// assert
|
||||
expect(result).toEqual(expected);
|
||||
console.log(`Test with a = ${a}, b = ${b}, expected = ${expected}, result = ${result}`);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw an exception when dividing by zero", () => {
|
||||
// arrange
|
||||
const a = 7;
|
||||
const b = 0;
|
||||
// act & assert
|
||||
expect(() => divide(a, b)).toThrow("Division by zero");
|
||||
});
|
||||
});
|
@ -3,14 +3,18 @@ import {multiply} from "./index";
|
||||
describe("Test multiply", () => {
|
||||
it.each([
|
||||
{ a: 1, b : 2, expected: 2 },
|
||||
{ a: 6, b : 7, expected: 42 },
|
||||
{ a: 10, b : 5, expected: 50 },
|
||||
{ a: 0, b : 5, expected: 0},
|
||||
])(
|
||||
"should return multiplication of A by B",
|
||||
`should return multiplication of $a by $b`,
|
||||
({ a, b, expected }) => {
|
||||
// arrange
|
||||
// act
|
||||
const result = multiply(a,b);
|
||||
// assert
|
||||
expect(result).toEqual(expected);
|
||||
console.log(`Test with a = ${a}, b = ${b}, expected = ${expected}, result = ${result}`);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user