helpers.math.tests.js 953 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. describe('Chart.helpers.math', function() {
  3. var math = Chart.helpers.math;
  4. var factorize = math._factorize;
  5. it('should factorize', function() {
  6. expect(factorize(1000)).toEqual([1, 2, 4, 5, 8, 10, 20, 25, 40, 50, 100, 125, 200, 250, 500]);
  7. expect(factorize(60)).toEqual([1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30]);
  8. expect(factorize(30)).toEqual([1, 2, 3, 5, 6, 10, 15]);
  9. expect(factorize(24)).toEqual([1, 2, 3, 4, 6, 8, 12]);
  10. expect(factorize(12)).toEqual([1, 2, 3, 4, 6]);
  11. expect(factorize(4)).toEqual([1, 2]);
  12. expect(factorize(-1)).toEqual([]);
  13. expect(factorize(2.76)).toEqual([]);
  14. });
  15. it('should do a log10 operation', function() {
  16. expect(math.log10(0)).toBe(-Infinity);
  17. // Check all allowed powers of 10, which should return integer values
  18. var maxPowerOf10 = Math.floor(math.log10(Number.MAX_VALUE));
  19. for (var i = 0; i < maxPowerOf10; i += 1) {
  20. expect(math.log10(Math.pow(10, i))).toBe(i);
  21. }
  22. });
  23. });