|
| 1 | +import { calculateMean } from "../calculateMean"; |
| 2 | + |
| 3 | +describe("Tests for AverageMean", () => { |
| 4 | + it("should be a function", () => { |
| 5 | + expect(typeof calculateMean).toEqual("function"); |
| 6 | + }); |
| 7 | + |
| 8 | + it("should throw error for invalid input", () => { |
| 9 | + expect(() => calculateMean([])).toThrow(); |
| 10 | + }); |
| 11 | + |
| 12 | + it("should return the mean of an array of consecutive numbers", () => { |
| 13 | + const meanFunction = calculateMean([1, 2, 3, 4]); |
| 14 | + expect(meanFunction).toBe(2.5); |
| 15 | + }); |
| 16 | + |
| 17 | + it("should return the mean of an array of numbers", () => { |
| 18 | + const meanFunction = calculateMean([10, 40, 100, 20]); |
| 19 | + expect(meanFunction).toBe(42.5); |
| 20 | + }); |
| 21 | + |
| 22 | + it("should return the mean of an array of decimal numbers", () => { |
| 23 | + const meanFunction = calculateMean([1.3, 12.67, 99.14, 20]); |
| 24 | + expect(meanFunction).toBe(33.2775); |
| 25 | + }); |
| 26 | + |
| 27 | + it("should return the mean of an array of numbers, including negatives", () => { |
| 28 | + const meanFunction = calculateMean([10, -40, 100, -20]); |
| 29 | + expect(meanFunction).toBe(12.5); |
| 30 | + }); |
| 31 | +}); |
0 commit comments