UINT64_toNumber-test.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. var assert = require('assert')
  2. var UINT64 = require('..').UINT64
  3. describe('toNumber method', function () {
  4. describe('from 0', function () {
  5. it('should return 0', function (done) {
  6. var u = UINT64(0).toNumber()
  7. assert.equal( u, 0 )
  8. done()
  9. })
  10. })
  11. describe('from low bit number', function () {
  12. it('should return the number', function (done) {
  13. var u = UINT64(123).toNumber()
  14. assert.equal( u, 123 )
  15. done()
  16. })
  17. })
  18. describe('from high bit number', function () {
  19. it('should return the number', function (done) {
  20. var n = Math.pow(2,17)
  21. var u = UINT64(n).toNumber()
  22. assert.equal( u, n )
  23. done()
  24. })
  25. })
  26. describe('from high and low bit number', function () {
  27. it('should return the number', function (done) {
  28. var n = Math.pow(2,17) + 123
  29. var u = UINT64(n).toNumber()
  30. assert.equal( u, n )
  31. done()
  32. })
  33. })
  34. describe('toNumber and toString', function () {
  35. it('should return the same result for 100 random numbers', function () {
  36. for (var i=0; i<100; i++) {
  37. var u = UINT64(Math.floor(Math.random() * 0xffffffff), 0);
  38. assert.equal(u.toNumber(), parseInt(u.toString()));
  39. }
  40. })
  41. })
  42. })