UINT64-test.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. var assert = require('assert')
  2. var UINT64 = require('..').UINT64
  3. describe('UINT64 constructor', function () {
  4. describe('with no parameters', function () {
  5. it('should properly initialize', function (done) {
  6. var u = UINT64()
  7. assert.equal( u._a00, 0 )
  8. assert.equal( u._a16, 0 )
  9. assert.equal( u._a32, 0 )
  10. assert.equal( u._a48, 0 )
  11. done()
  12. })
  13. })
  14. describe('with low and high bits', function () {
  15. describe('0, 0', function () {
  16. it('should properly initialize', function (done) {
  17. var u = UINT64(0, 0)
  18. assert.equal( u._a00, 0 )
  19. assert.equal( u._a16, 0 )
  20. assert.equal( u._a32, 0 )
  21. assert.equal( u._a48, 0 )
  22. done()
  23. })
  24. })
  25. describe('1, 0', function () {
  26. it('should properly initialize', function (done) {
  27. var u = UINT64(1, 0)
  28. assert.equal( u._a00, 1 )
  29. assert.equal( u._a16, 0 )
  30. assert.equal( u._a32, 0 )
  31. assert.equal( u._a48, 0 )
  32. done()
  33. })
  34. })
  35. describe('0, 1', function () {
  36. it('should properly initialize', function (done) {
  37. var u = UINT64(0, 1)
  38. assert.equal( u._a00, 0 )
  39. assert.equal( u._a16, 0 )
  40. assert.equal( u._a32, 1 )
  41. assert.equal( u._a48, 0 )
  42. done()
  43. })
  44. })
  45. describe('3, 5', function () {
  46. it('should properly initialize', function (done) {
  47. var u = UINT64(3, 5)
  48. assert.equal( u._a00, 3 )
  49. assert.equal( u._a16, 0 )
  50. assert.equal( u._a32, 5 )
  51. assert.equal( u._a48, 0 )
  52. done()
  53. })
  54. })
  55. })
  56. describe('with number', function () {
  57. describe('0', function () {
  58. it('should properly initialize', function (done) {
  59. var u = UINT64(0)
  60. assert.equal( u._a00, 0 )
  61. assert.equal( u._a16, 0 )
  62. assert.equal( u._a32, 0 )
  63. assert.equal( u._a48, 0 )
  64. done()
  65. })
  66. })
  67. describe('1', function () {
  68. it('should properly initialize', function (done) {
  69. var u = UINT64(1)
  70. assert.equal( u._a00, 1 )
  71. assert.equal( u._a16, 0 )
  72. assert.equal( u._a32, 0 )
  73. assert.equal( u._a48, 0 )
  74. done()
  75. })
  76. })
  77. describe('3', function () {
  78. it('should properly initialize', function (done) {
  79. var u = UINT64(3)
  80. assert.equal( u._a00, 3 )
  81. assert.equal( u._a16, 0 )
  82. assert.equal( u._a32, 0 )
  83. assert.equal( u._a48, 0 )
  84. done()
  85. })
  86. })
  87. describe('with high bit', function () {
  88. it('should properly initialize', function (done) {
  89. var u = UINT64( Math.pow(2,17)+123 )
  90. assert.equal( u._a00, 123 )
  91. assert.equal( u._a16, 2 )
  92. assert.equal( u._a32, 0 )
  93. assert.equal( u._a48, 0 )
  94. done()
  95. })
  96. })
  97. })
  98. describe('with string', function () {
  99. describe('"0"', function () {
  100. it('should properly initialize', function (done) {
  101. var u = UINT64('0')
  102. assert.equal( u._a00, 0 )
  103. assert.equal( u._a16, 0 )
  104. assert.equal( u._a32, 0 )
  105. assert.equal( u._a48, 0 )
  106. done()
  107. })
  108. })
  109. describe('"1"', function () {
  110. it('should properly initialize', function (done) {
  111. var u = UINT64('1')
  112. assert.equal( u._a00, 1 )
  113. assert.equal( u._a16, 0 )
  114. assert.equal( u._a32, 0 )
  115. assert.equal( u._a48, 0 )
  116. done()
  117. })
  118. })
  119. describe('10', function () {
  120. it('should properly initialize', function (done) {
  121. var u = UINT64('10')
  122. assert.equal( u._a00, 10 )
  123. assert.equal( u._a16, 0 )
  124. assert.equal( u._a32, 0 )
  125. assert.equal( u._a48, 0 )
  126. done()
  127. })
  128. })
  129. describe('with high bit', function () {
  130. it('should properly initialize', function (done) {
  131. var u = UINT64( '' + (Math.pow(2,17)+123) )
  132. assert.equal( u._a00, 123 )
  133. assert.equal( u._a16, 2 )
  134. assert.equal( u._a32, 0 )
  135. assert.equal( u._a48, 0 )
  136. done()
  137. })
  138. })
  139. describe('with radix 10', function () {
  140. it('should properly initialize', function (done) {
  141. var u = UINT64( '123', 10 )
  142. assert.equal( u._a00, 123 )
  143. assert.equal( u._a16, 0 )
  144. assert.equal( u._a32, 0 )
  145. assert.equal( u._a48, 0 )
  146. done()
  147. })
  148. })
  149. describe('with radix 2', function () {
  150. it('should properly initialize', function (done) {
  151. var u = UINT64( '1111011', 2 )
  152. assert.equal( u._a00, 123 )
  153. assert.equal( u._a16, 0 )
  154. assert.equal( u._a32, 0 )
  155. assert.equal( u._a48, 0 )
  156. done()
  157. })
  158. })
  159. describe('with radix 16', function () {
  160. it('should properly initialize', function (done) {
  161. var u = UINT64( '7B', 16 )
  162. assert.equal( u._a00, 123 )
  163. assert.equal( u._a16, 0 )
  164. assert.equal( u._a32, 0 )
  165. assert.equal( u._a48, 0 )
  166. done()
  167. })
  168. })
  169. describe('8000 with radix 16', function () {
  170. it('should properly initialize', function (done) {
  171. var u = UINT64( '8000', 16 )
  172. assert.equal( u._a00, 32768 )
  173. assert.equal( u._a16, 0 )
  174. assert.equal( u._a32, 0 )
  175. assert.equal( u._a48, 0 )
  176. done()
  177. })
  178. })
  179. describe('80000000 with radix 16', function () {
  180. it('should properly initialize', function (done) {
  181. var u = UINT64( '80000000', 16 )
  182. assert.equal( u._a00, 0 )
  183. assert.equal( u._a16, 32768 )
  184. assert.equal( u._a32, 0 )
  185. assert.equal( u._a48, 0 )
  186. done()
  187. })
  188. })
  189. describe('800000000000 with radix 16', function () {
  190. it('should properly initialize', function (done) {
  191. var u = UINT64( '800000000000', 16 )
  192. assert.equal( u._a00, 0 )
  193. assert.equal( u._a16, 0 )
  194. assert.equal( u._a32, 32768 )
  195. assert.equal( u._a48, 0 )
  196. done()
  197. })
  198. })
  199. describe('8000000000000000 with radix 16', function () {
  200. it('should properly initialize', function (done) {
  201. var u = UINT64( '8000000000000000', 16 )
  202. assert.equal( u._a00, 0 )
  203. assert.equal( u._a16, 0 )
  204. assert.equal( u._a32, 0 )
  205. assert.equal( u._a48, 32768 )
  206. done()
  207. })
  208. })
  209. describe('maximum unsigned 64 bits value in base 2', function () {
  210. it('should properly initialize', function (done) {
  211. var u = UINT64( Array(65).join('1'), 2 )
  212. assert.equal( u._a00, 65535 )
  213. assert.equal( u._a16, 65535 )
  214. assert.equal( u._a32, 65535 )
  215. assert.equal( u._a48, 65535 )
  216. done()
  217. })
  218. })
  219. describe('maximum unsigned 64 bits value in base 16', function () {
  220. it('should properly initialize', function (done) {
  221. var u = UINT64( Array(17).join('F'), 16 )
  222. assert.equal( u._a00, 65535 )
  223. assert.equal( u._a16, 65535 )
  224. assert.equal( u._a32, 65535 )
  225. assert.equal( u._a48, 65535 )
  226. done()
  227. })
  228. })
  229. })
  230. })