Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

42 строки
1.1 KiB

  1. /**
  2. * Tests for numeric stability
  3. */
  4. var algorithm = require('./')
  5. , test = require('tape')
  6. , badVector
  7. badVector = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7]
  8. test('fastSum', function (t) {
  9. t.plan(1);
  10. t.deepEqual(algorithm.fastTwoSum(1/3, 1/6)
  11. , [0.5, -2.7755575615628914e-17, null]
  12. , 'Result and error should have been returned')
  13. });
  14. test('nextPowerTwo', function (t) {
  15. t.plan(1)
  16. t.equal(algorithm.nextPowerTwo(1534)
  17. , 2048
  18. , 'Should be Math.pow(2, Math.ceil(algorithm.logBase2(Math.abs(1534))))')
  19. })
  20. test('accumulate', function (t) {
  21. t.plan(5)
  22. t.equal(algorithm([1,2,3,4]), 10, 'Integer sum should work')
  23. t.equal(algorithm.dumbSum(badVector), 15.299999999999999, 'Inaccurate summation using naive method')
  24. t.equal(algorithm(badVector), 15.3, 'Rump-Ogita-Oishi summation of insidious sum')
  25. t.equal(algorithm([0, 0, 0]), 0, 'Rump-Ogita-Oishi summation of zero array')
  26. t.equal(algorithm([]), 0, 'Rump-Ogita-Oishi summation of empty array')
  27. })