UINT32-test.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. var assert = require('assert')
  2. var UINT32 = require('..').UINT32
  3. describe('UINT32 constructor', function () {
  4. describe('with no parameters', function () {
  5. it('should properly initialize', function (done) {
  6. var u = UINT32()
  7. assert.equal( u._low, 0 )
  8. assert.equal( u._high, 0 )
  9. done()
  10. })
  11. })
  12. describe('with low and high bits', function () {
  13. describe('0, 0', function () {
  14. it('should properly initialize', function (done) {
  15. var u = UINT32(0, 0)
  16. assert.equal( u._low, 0 )
  17. assert.equal( u._high, 0 )
  18. done()
  19. })
  20. })
  21. describe('1, 0', function () {
  22. it('should properly initialize', function (done) {
  23. var u = UINT32(1, 0)
  24. assert.equal( u._low, 1 )
  25. assert.equal( u._high, 0 )
  26. done()
  27. })
  28. })
  29. describe('0, 1', function () {
  30. it('should properly initialize', function (done) {
  31. var u = UINT32(0, 1)
  32. assert.equal( u._low, 0 )
  33. assert.equal( u._high, 1 )
  34. done()
  35. })
  36. })
  37. describe('3, 5', function () {
  38. it('should properly initialize', function (done) {
  39. var u = UINT32(3, 5)
  40. assert.equal( u._low, 3 )
  41. assert.equal( u._high, 5 )
  42. done()
  43. })
  44. })
  45. })
  46. describe('with number', function () {
  47. describe('0', function () {
  48. it('should properly initialize', function (done) {
  49. var u = UINT32(0)
  50. assert.equal( u._low, 0 )
  51. assert.equal( u._high, 0 )
  52. done()
  53. })
  54. })
  55. describe('1', function () {
  56. it('should properly initialize', function (done) {
  57. var u = UINT32(1)
  58. assert.equal( u._low, 1 )
  59. assert.equal( u._high, 0 )
  60. done()
  61. })
  62. })
  63. describe('3', function () {
  64. it('should properly initialize', function (done) {
  65. var u = UINT32(3)
  66. assert.equal( u._low, 3 )
  67. assert.equal( u._high, 0 )
  68. done()
  69. })
  70. })
  71. describe('with high bit', function () {
  72. it('should properly initialize', function (done) {
  73. var u = UINT32( Math.pow(2,17)+123 )
  74. assert.equal( u._low, 123 )
  75. assert.equal( u._high, 2 )
  76. done()
  77. })
  78. })
  79. })
  80. describe('with string', function () {
  81. describe('"0"', function () {
  82. it('should properly initialize', function (done) {
  83. var u = UINT32('0')
  84. assert.equal( u._low, 0 )
  85. assert.equal( u._high, 0 )
  86. done()
  87. })
  88. })
  89. describe('"1"', function () {
  90. it('should properly initialize', function (done) {
  91. var u = UINT32('1')
  92. assert.equal( u._low, 1 )
  93. assert.equal( u._high, 0 )
  94. done()
  95. })
  96. })
  97. describe('10', function () {
  98. it('should properly initialize', function (done) {
  99. var u = UINT32('10')
  100. assert.equal( u._low, 10 )
  101. assert.equal( u._high, 0 )
  102. done()
  103. })
  104. })
  105. describe('with high bit', function () {
  106. it('should properly initialize', function (done) {
  107. var u = UINT32( '' + (Math.pow(2,17)+123) )
  108. assert.equal( u._low, 123 )
  109. assert.equal( u._high, 2 )
  110. done()
  111. })
  112. })
  113. describe('with radix 10', function () {
  114. it('should properly initialize', function (done) {
  115. var u = UINT32( '123', 10 )
  116. assert.equal( u._low, 123 )
  117. assert.equal( u._high, 0 )
  118. done()
  119. })
  120. })
  121. describe('with radix 2', function () {
  122. it('should properly initialize', function (done) {
  123. var u = UINT32( '1111011', 2 )
  124. assert.equal( u._low, 123 )
  125. assert.equal( u._high, 0 )
  126. done()
  127. })
  128. })
  129. describe('with radix 16', function () {
  130. it('should properly initialize', function (done) {
  131. var u = UINT32( '7B', 16 )
  132. assert.equal( u._low, 123 )
  133. assert.equal( u._high, 0 )
  134. done()
  135. })
  136. })
  137. describe('8000 with radix 16', function () {
  138. it('should properly initialize', function (done) {
  139. var u = UINT32( '8000', 16 )
  140. assert.equal( u._low, 32768 )
  141. assert.equal( u._high, 0 )
  142. done()
  143. })
  144. })
  145. describe('80000000 with radix 16', function () {
  146. it('should properly initialize', function (done) {
  147. var u = UINT32( '80000000', 16 )
  148. assert.equal( u._low, 0 )
  149. assert.equal( u._high, 32768 )
  150. done()
  151. })
  152. })
  153. describe('maximum unsigned 32 bits value in base 2', function () {
  154. it('should properly initialize', function (done) {
  155. var u = UINT32( Array(33).join('1'), 2 )
  156. assert.equal( u._low, 65535 )
  157. assert.equal( u._high, 65535 )
  158. done()
  159. })
  160. })
  161. describe('maximum unsigned 32 bits value in base 16', function () {
  162. it('should properly initialize', function (done) {
  163. var u = UINT32( Array(9).join('F'), 16 )
  164. assert.equal( u._low, 65535 )
  165. assert.equal( u._high, 65535 )
  166. done()
  167. })
  168. })
  169. })
  170. })