Geen omschrijving

StatisticUtils.test.ts 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { expect } from '@std/expect'
  2. import { describe, it } from 'node:test'
  3. import { max, min, nthPercentile, stdDeviation } from '../../src/utils/StatisticUtils.js'
  4. await describe('StatisticUtils test suite', async () => {
  5. await it('Verify min()', () => {
  6. expect(min()).toBe(Number.POSITIVE_INFINITY)
  7. expect(min(0, 1)).toBe(0)
  8. expect(min(1, 0)).toBe(0)
  9. expect(min(0, -1)).toBe(-1)
  10. expect(min(-1, 0)).toBe(-1)
  11. })
  12. await it('Verify max()', () => {
  13. expect(max()).toBe(Number.NEGATIVE_INFINITY)
  14. expect(max(0, 1)).toBe(1)
  15. expect(max(1, 0)).toBe(1)
  16. expect(max(0, -1)).toBe(0)
  17. expect(max(-1, 0)).toBe(0)
  18. })
  19. await it('Verify nthPercentile()', () => {
  20. expect(nthPercentile([], 25)).toBe(0)
  21. expect(nthPercentile([0.08], 50)).toBe(0.08)
  22. const array0 = [0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03]
  23. expect(nthPercentile(array0, 0)).toBe(0.25)
  24. expect(nthPercentile(array0, 50)).toBe(3.05)
  25. expect(nthPercentile(array0, 80)).toBe(4.974)
  26. expect(nthPercentile(array0, 85)).toBe(5.131)
  27. expect(nthPercentile(array0, 90)).toBe(5.434)
  28. expect(nthPercentile(array0, 95)).toBe(5.736999999999999)
  29. expect(nthPercentile(array0, 100)).toBe(6.04)
  30. })
  31. await it('Verify stdDeviation()', () => {
  32. expect(stdDeviation([0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03])).toBe(2.1879050645374383)
  33. })
  34. })