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([
|
it.each([
|
||||||
{ a: 2, b : 1, expected: 2 },
|
{ a: 2, b: 1, expected: 2 },
|
||||||
])(
|
{ a: 10, b: 2, expected: 5 },
|
||||||
"should return multiplication of A by B",
|
{ a: 50, b: 5, expected: 10 },
|
||||||
({ a, b, expected }) => {
|
])(
|
||||||
|
"should return division of $b by $a",
|
||||||
|
({ a, b, expected }) => {
|
||||||
|
// act
|
||||||
|
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
|
// arrange
|
||||||
// act
|
const a = 7;
|
||||||
const result = divide(a,b);
|
const b = 0;
|
||||||
// assert
|
// act & assert
|
||||||
expect(result).toEqual(expected);
|
expect(() => divide(a, b)).toThrow("Division by zero");
|
||||||
}
|
});
|
||||||
);
|
});
|
||||||
});
|
|
||||||
|
|
@ -2,15 +2,19 @@ import {multiply} from "./index";
|
|||||||
|
|
||||||
describe("Test multiply", () => {
|
describe("Test multiply", () => {
|
||||||
it.each([
|
it.each([
|
||||||
{ a: 1, b : 2, expected: 2 },
|
{ 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 }) => {
|
({ a, b, expected }) => {
|
||||||
// arrange
|
// arrange
|
||||||
// act
|
// act
|
||||||
const result = multiply(a,b);
|
const result = multiply(a,b);
|
||||||
// assert
|
// assert
|
||||||
expect(result).toEqual(expected);
|
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