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