forked from TheAlgorithms/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculateMean.test.ts
31 lines (25 loc) · 1007 Bytes
/
calculateMean.test.ts
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 { calculateMean } from "../calculateMean";
describe("Tests for AverageMean", () => {
it("should be a function", () => {
expect(typeof calculateMean).toEqual("function");
});
it("should throw error for invalid input", () => {
expect(() => calculateMean([])).toThrow();
});
it("should return the mean of an array of consecutive numbers", () => {
const meanFunction = calculateMean([1, 2, 3, 4]);
expect(meanFunction).toBe(2.5);
});
it("should return the mean of an array of numbers", () => {
const meanFunction = calculateMean([10, 40, 100, 20]);
expect(meanFunction).toBe(42.5);
});
it("should return the mean of an array of decimal numbers", () => {
const meanFunction = calculateMean([1.3, 12.67, 99.14, 20]);
expect(meanFunction).toBe(33.2775);
});
it("should return the mean of an array of numbers, including negatives", () => {
const meanFunction = calculateMean([10, -40, 100, -20]);
expect(meanFunction).toBe(12.5);
});
});