|
| 1 | +import { homogenity, HomogenityTestResult } from '../src/homogenity'; |
| 2 | + |
| 3 | +describe('homogenity', () => { |
| 4 | + it('should correctly calculate homogenity for given dataset', () => { |
| 5 | + // Arrange |
| 6 | + const testData: HomogenityTestResult[] = [ |
| 7 | + { label: 'X', values: [0.452, 0.438] }, |
| 8 | + { label: 'X', values: [0.436, 0.432] }, |
| 9 | + { label: 'X', values: [0.435, 0.434] }, |
| 10 | + { label: 'X', values: [0.456, 0.441] }, |
| 11 | + { label: 'X', values: [0.434, 0.433] }, |
| 12 | + { label: 'X', values: [0.439, 0.430] }, |
| 13 | + { label: 'X', values: [0.433, 0.430] }, |
| 14 | + { label: 'X', values: [0.434, 0.429] }, |
| 15 | + { label: 'X', values: [0.434, 0.436] } |
| 16 | + ]; |
| 17 | + const r = 0.07; |
| 18 | + |
| 19 | + // Act |
| 20 | + const result = homogenity(testData, r); |
| 21 | + |
| 22 | + // Assert |
| 23 | + expect(result.homogenity).toBe(true); |
| 24 | + expect(result.xAvg).toBeCloseTo(0.436, 3); |
| 25 | + expect(result.sw).toBeCloseTo(0.006, 3); |
| 26 | + expect(result.ss).toBeCloseTo(0.005, 3); |
| 27 | + expect(result.ss2).toBeCloseTo(0.00002, 5); |
| 28 | + expect(result.c).toBeCloseTo(0.0001, 4); |
| 29 | + expect(result.cSqrt).toBeCloseTo(0.012, 3); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should correctly calculate homogenity for second dataset with 10 measurements', () => { |
| 33 | + // Arrange |
| 34 | + const testData: HomogenityTestResult[] = [ |
| 35 | + { label: 'X', values: [0.452, 0.438] }, |
| 36 | + { label: 'X', values: [0.436, 0.432] }, |
| 37 | + { label: 'X', values: [0.435, 0.434] }, |
| 38 | + { label: 'X', values: [0.456, 0.441] }, |
| 39 | + { label: 'X', values: [0.434, 0.433] }, |
| 40 | + { label: 'X', values: [0.439, 0.43] }, |
| 41 | + { label: 'X', values: [0.433, 0.430] }, |
| 42 | + { label: 'X', values: [0.434, 0.429] }, |
| 43 | + { label: 'X', values: [0.434, 0.436] }, |
| 44 | + { label: 'X', values: [0.47, 0.43] } |
| 45 | + ]; |
| 46 | + |
| 47 | + const r = 0.07; |
| 48 | + |
| 49 | + // Act |
| 50 | + const result = homogenity(testData, r); |
| 51 | + |
| 52 | + // Assert |
| 53 | + expect(result.homogenity).toBe(true); |
| 54 | + expect(result.xAvg).toBeCloseTo(0.438, 3); |
| 55 | + expect(result.sw).toBeCloseTo(0.011, 2); |
| 56 | + expect(result.ss).toBeCloseTo(0.000, 3); |
| 57 | + expect(result.ss2).toBeCloseTo(-0.00001, 4); |
| 58 | + expect(result.c).toBeCloseTo(0.0002, 4); |
| 59 | + expect(result.cSqrt).toBeCloseTo(0.015, 3); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should throw error when input array is empty', () => { |
| 63 | + expect(() => homogenity([], 0.07)).toThrow('At least one test result is required'); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should throw error when values array does not contain exactly 2 values', () => { |
| 67 | + const invalidData: HomogenityTestResult[] = [ |
| 68 | + { label: 'X', values: [0.452, 0.438, 0.434] } |
| 69 | + ]; |
| 70 | + |
| 71 | + expect(() => homogenity(invalidData, 0.07)).toThrow('We currently only support two values per test'); |
| 72 | + }); |
| 73 | +}); |
0 commit comments