ipaddress 0.2.3 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/{crunchy.d.ts → dist/src/crunchy.d.ts} +1 -0
  2. package/dist/src/crunchy.d.ts.map +1 -0
  3. package/dist/src/crunchy.js +484 -0
  4. package/dist/src/index.d.ts +13 -0
  5. package/dist/src/index.d.ts.map +1 -0
  6. package/dist/src/index.js +21 -0
  7. package/{ip_bits.d.ts → dist/src/ip_bits.d.ts} +6 -5
  8. package/dist/src/ip_bits.d.ts.map +1 -0
  9. package/dist/src/ip_bits.js +133 -0
  10. package/{ip_version.d.ts → dist/src/ip_version.d.ts} +2 -1
  11. package/dist/src/ip_version.d.ts.map +1 -0
  12. package/dist/src/ip_version.js +6 -0
  13. package/{ipaddress.d.ts → dist/src/ipaddress.d.ts} +18 -16
  14. package/dist/src/ipaddress.d.ts.map +1 -0
  15. package/dist/src/ipaddress.js +1228 -0
  16. package/dist/src/ipv4.d.ts +15 -0
  17. package/dist/src/ipv4.d.ts.map +1 -0
  18. package/dist/src/ipv4.js +176 -0
  19. package/dist/src/ipv6.d.ts +13 -0
  20. package/dist/src/ipv6.d.ts.map +1 -0
  21. package/dist/src/ipv6.js +190 -0
  22. package/dist/src/ipv6_loopback.d.ts +6 -0
  23. package/dist/src/ipv6_loopback.d.ts.map +1 -0
  24. package/dist/src/ipv6_loopback.js +51 -0
  25. package/dist/src/ipv6_mapped.d.ts +6 -0
  26. package/dist/src/ipv6_mapped.d.ts.map +1 -0
  27. package/dist/src/ipv6_mapped.js +159 -0
  28. package/dist/src/ipv6_unspec.d.ts +6 -0
  29. package/dist/src/ipv6_unspec.d.ts.map +1 -0
  30. package/dist/src/ipv6_unspec.js +57 -0
  31. package/{prefix.d.ts → dist/src/prefix.d.ts} +10 -7
  32. package/dist/src/prefix.d.ts.map +1 -0
  33. package/dist/src/prefix.js +142 -0
  34. package/dist/src/prefix128.d.ts +7 -0
  35. package/dist/src/prefix128.d.ts.map +1 -0
  36. package/dist/src/prefix128.js +35 -0
  37. package/dist/src/prefix32.d.ts +7 -0
  38. package/dist/src/prefix32.d.ts.map +1 -0
  39. package/dist/src/prefix32.js +25 -0
  40. package/dist/src/rle.d.ts +19 -0
  41. package/dist/src/rle.d.ts.map +1 -0
  42. package/dist/src/rle.js +73 -0
  43. package/dist/test/test_crunchy.d.ts +2 -0
  44. package/dist/test/test_crunchy.d.ts.map +1 -0
  45. package/dist/test/test_crunchy.js +451 -0
  46. package/dist/test/test_ipaddress.d.ts +2 -0
  47. package/dist/test/test_ipaddress.d.ts.map +1 -0
  48. package/dist/test/test_ipaddress.js +182 -0
  49. package/dist/test/test_ipv4.d.ts +2 -0
  50. package/dist/test/test_ipv4.d.ts.map +1 -0
  51. package/dist/test/test_ipv4.js +561 -0
  52. package/dist/test/test_ipv6.d.ts +2 -0
  53. package/dist/test/test_ipv6.d.ts.map +1 -0
  54. package/dist/test/test_ipv6.js +313 -0
  55. package/dist/test/test_ipv6_loopback.d.ts +2 -0
  56. package/dist/test/test_ipv6_loopback.d.ts.map +1 -0
  57. package/dist/test/test_ipv6_loopback.js +40 -0
  58. package/dist/test/test_ipv6_mapped.d.ts +2 -0
  59. package/dist/test/test_ipv6_mapped.d.ts.map +1 -0
  60. package/dist/test/test_ipv6_mapped.js +89 -0
  61. package/dist/test/test_ipv6_unspec.d.ts +2 -0
  62. package/dist/test/test_ipv6_unspec.d.ts.map +1 -0
  63. package/dist/test/test_ipv6_unspec.js +39 -0
  64. package/dist/test/test_prefix128.d.ts +2 -0
  65. package/dist/test/test_prefix128.d.ts.map +1 -0
  66. package/dist/test/test_prefix128.js +35 -0
  67. package/dist/test/test_prefix32.d.ts +2 -0
  68. package/dist/test/test_prefix32.d.ts.map +1 -0
  69. package/dist/test/test_prefix32.js +126 -0
  70. package/dist/test/test_rle.d.ts +2 -0
  71. package/dist/test/test_rle.d.ts.map +1 -0
  72. package/dist/test/test_rle.js +141 -0
  73. package/dist/vitest.config.d.ts +3 -0
  74. package/dist/vitest.config.d.ts.map +1 -0
  75. package/dist/vitest.config.js +11 -0
  76. package/package.json +40 -37
  77. package/src/crunchy.ts +546 -0
  78. package/src/index.ts +23 -0
  79. package/src/ip_bits.ts +148 -0
  80. package/src/ip_version.ts +6 -0
  81. package/src/ipaddress.ts +1331 -0
  82. package/src/ipv4.ts +190 -0
  83. package/src/ipv6.ts +202 -0
  84. package/src/ipv6_loopback.ts +55 -0
  85. package/src/ipv6_mapped.ts +163 -0
  86. package/src/ipv6_unspec.ts +59 -0
  87. package/src/prefix.ts +170 -0
  88. package/src/prefix128.ts +38 -0
  89. package/src/prefix32.ts +28 -0
  90. package/src/rle.ts +85 -0
  91. package/test/test_crunchy.ts +614 -0
  92. package/test/test_ipaddress.ts +208 -0
  93. package/test/test_ipv4.ts +596 -0
  94. package/test/test_ipv6.ts +325 -0
  95. package/test/test_ipv6_loopback.ts +52 -0
  96. package/test/test_ipv6_mapped.ts +101 -0
  97. package/test/test_ipv6_unspec.ts +51 -0
  98. package/test/test_prefix128.ts +39 -0
  99. package/test/test_prefix32.ts +130 -0
  100. package/test/test_rle.ts +144 -0
  101. package/LICENSE +0 -20
  102. package/README.md +0 -956
  103. package/index.d.ts +0 -12
  104. package/ipaddress.js +0 -2854
  105. package/ipaddress.js.map +0 -1
  106. package/ipv4.d.ts +0 -14
  107. package/ipv6.d.ts +0 -12
  108. package/ipv6_loopback.d.ts +0 -5
  109. package/ipv6_mapped.d.ts +0 -5
  110. package/ipv6_unspec.d.ts +0 -5
  111. package/prefix128.d.ts +0 -6
  112. package/prefix32.d.ts +0 -6
  113. package/rle.d.ts +0 -14
@@ -0,0 +1,614 @@
1
+ import Crunchy from "../src/crunchy.js";
2
+
3
+ describe("#compare", function () {
4
+ it("Should confirm equality", function () {
5
+ const x = Crunchy.from_string("12345678901234567890");
6
+ const y = Crunchy.from_string("12345678901234567890");
7
+ assert.isTrue(x.eq(y));
8
+ // this.done();
9
+ });
10
+
11
+ it("Should find first is greater than second", function () {
12
+ const x = Crunchy.from_string("12345678901234567890");
13
+ const y = Crunchy.from_string("1234567890");
14
+ assert.isTrue(x.gt(y));
15
+ // this.done();
16
+ });
17
+
18
+ it("Should find first is less than second", function () {
19
+ const x = Crunchy.from_string("1234567890");
20
+ const y = Crunchy.from_string("12345678901234567890");
21
+ assert.isTrue(x.lt(y));
22
+ // this.done();
23
+ });
24
+ });
25
+
26
+ describe("#add", function () {
27
+ it("Should add numbers", function () {
28
+ const x = Crunchy.from_8bit([242, 62]);
29
+ const y = Crunchy.from_8bit([42, 2]);
30
+
31
+ assert.deepEqual(x.add(y).to_8bit(), [1, 28, 64]);
32
+ // x.should.eql([242, 62]);
33
+ // y.should.eql([42, 2]);
34
+ });
35
+
36
+ it("Should add numbers, first longer than second", function () {
37
+ const x = Crunchy.from_8bit([26, 255, 230, 17]);
38
+ const y = Crunchy.from_8bit([42, 34]);
39
+
40
+ assert.deepEqual(x.add(y).to_8bit(), [27, 0, 16, 51]);
41
+
42
+ // x, [26, 255, 230, 17]);
43
+ // y.should.eql([42, 34]);
44
+ });
45
+
46
+ it("Should add numbers, second longer than first", function () {
47
+ const x = Crunchy.from_8bit([234, 34]);
48
+ const y = Crunchy.from_8bit([255, 255, 230, 17]);
49
+
50
+ assert.deepEqual(x.add(y).to_8bit(), [1, 0, 0, 208, 51]);
51
+
52
+ // x.should.eql([234, 34]);
53
+ // y.should.eql([255, 255, 230, 17]);
54
+ });
55
+
56
+ it("Should add two identical numbers", function () {
57
+ const x = Crunchy.from_8bit([255, 255, 255, 255, 255, 255]);
58
+ const y = Crunchy.from_8bit([255, 255, 255, 255, 255, 255]);
59
+
60
+ assert.deepEqual(x.add(y).to_8bit(), [1, 255, 255, 255, 255, 255, 254]);
61
+
62
+ // x.should.eql([255, 255, 255, 255, 255, 255]);
63
+ // y.should.eql([255, 255, 255, 255, 255, 255]);
64
+ });
65
+
66
+ it("Should add positive to negative number expecting positive result", function () {
67
+ const x = Crunchy.from_8bit([51, 254, 144, 207]);
68
+ const y = Crunchy.from_8bit([-20, 89, 145, 32]);
69
+
70
+ assert.deepEqual(x.add(y).to_8bit(), [31, 164, 255, 175]);
71
+
72
+ // x.should.eql([51, 254, 144, 207]);
73
+ // y.should.eql([-20, 89, 145, 32]);
74
+ });
75
+
76
+ it("Should add positive to negative number expecting negative result", function () {
77
+ const x = Crunchy.from_8bit([242, 62]);
78
+ const y = Crunchy.from_8bit([-242, 64]);
79
+
80
+ assert.deepEqual(x.add(y).to_8bit(), [-2]);
81
+
82
+ // x.should.eql([242, 62]);
83
+ // y.should.eql([-242, 64]);
84
+ });
85
+
86
+ it("Should add negative to positive number expecting positive result", function () {
87
+ const x = Crunchy.from_8bit([-42, 2]);
88
+ const y = Crunchy.from_8bit([242, 62]);
89
+
90
+ assert.deepEqual(x.add(y).to_8bit(), [200, 60]);
91
+
92
+ // x, [-42, 2]);
93
+ // y, [242, 62]);
94
+ });
95
+
96
+ it("Should add negative to positive number expecting negative result", function () {
97
+ const x = Crunchy.from_8bit([-42, 2]);
98
+ const y = Crunchy.from_8bit([42, 0]);
99
+
100
+ assert.deepEqual(x.add(y).to_8bit(), [-2]);
101
+ // x, [-42, 2]);
102
+ // y, [42, 0]);
103
+ });
104
+
105
+ it("Should add two negative numbers expecting negative result", function () {
106
+ const x = Crunchy.from_8bit([-242, 62]);
107
+ const y = Crunchy.from_8bit([-42, 2]);
108
+
109
+ assert.deepEqual(x.add(y).to_8bit(), [-1, 28, 64]);
110
+
111
+ // x, [-242, 62]);
112
+ // y, [-42, 2]);
113
+ });
114
+
115
+ it("Should add zero to number", function () {
116
+ const x = Crunchy.from_8bit([26, 255, 230, 17]);
117
+ const y = Crunchy.from_8bit([0]);
118
+
119
+ assert.deepEqual(x.add(y).to_8bit(), [26, 255, 230, 17]);
120
+
121
+ // x, [26, 255, 230, 17]);
122
+ // y, [0]);
123
+ });
124
+
125
+ it("Should add number to zero", function () {
126
+ const x = Crunchy.from_8bit([0]);
127
+ const y = Crunchy.from_8bit([43, 123, 200, 1]);
128
+
129
+ assert.deepEqual(x.add(y).to_8bit(), [43, 123, 200, 1]);
130
+
131
+ // x, [0]);
132
+ // y, [43, 123, 200, 1]);
133
+ });
134
+
135
+ it("Should add two zeros", function () {
136
+ const x = Crunchy.from_8bit([0]);
137
+ const y = Crunchy.from_8bit([0]);
138
+
139
+ assert.deepEqual(x.add(y).to_8bit(), [0]);
140
+
141
+ // x.should.eql([0]);
142
+ // y.should.eql([0]);
143
+ });
144
+ });
145
+
146
+ describe("#add-from_string", function () {
147
+ it("Should add numbers", function () {
148
+ // console.log(new Date());
149
+ const x = Crunchy.from_string("12345678911234567891");
150
+ // console.log(new Date());
151
+ const y = Crunchy.from_string("12345678901234567890");
152
+ // console.log(new Date(), x, y);
153
+ // console.log("addddddd:", new Date(), x, x.toString(), y, y.toString(), x.add(y).toString());
154
+ assert.equal(x.add(y).toString(), "24691357812469135781");
155
+ // console.log(new Date());
156
+ // this.done();
157
+ });
158
+
159
+ it("Should add numbers, first longer than second", function () {
160
+ const x = Crunchy.from_string("12345678901234567890");
161
+ const y = Crunchy.from_string("1234567890");
162
+ assert.equal(x.add(y).toString(), "12345678902469135780");
163
+ // this.done();
164
+ });
165
+
166
+ it("Should add numbers, second longer than first", function () {
167
+ const x = Crunchy.from_string("1234567890");
168
+ const y = Crunchy.from_string("12345678901234567890");
169
+ assert.equal(x.add(y).toString(), "12345678902469135780");
170
+ // this.done();
171
+ });
172
+
173
+ it("Should add two identical numbers", function () {
174
+ const x = Crunchy.from_string("12345678901234567890");
175
+ const y = Crunchy.from_string("12345678901234567890");
176
+ assert.equal(x.add(y).toString(), "24691357802469135780");
177
+ // this.done();
178
+ });
179
+
180
+ it("Should add zero to number", function () {
181
+ const x = Crunchy.from_string("12345678901234567890");
182
+ const y = Crunchy.from_string("0");
183
+ assert.equal(x.add(y).toString(), "12345678901234567890");
184
+ // this.done();
185
+ });
186
+
187
+ it("Should add number to zero", function () {
188
+ const x = Crunchy.from_string("0");
189
+ const y = Crunchy.from_string("12345678901234567890");
190
+ assert.equal(x.add(y).toString(), "12345678901234567890");
191
+ // this.done();
192
+ });
193
+
194
+ it("Should add two zeros", function () {
195
+ const x = Crunchy.from_string("0");
196
+ const y = Crunchy.from_string("0");
197
+ assert.equal(x.add(y).toString(), "0");
198
+ // this.done();
199
+ });
200
+ });
201
+
202
+ describe("#sub", function () {
203
+ it("Should subtract numbers", function () {
204
+ const x = Crunchy.from_8bit([170, 1, 79, 119, 242, 62]);
205
+ const y = Crunchy.from_8bit([17, 241, 123, 250, 42, 2]);
206
+
207
+ // console.log("Should subtract numbers:", x, y, x.sub(y));
208
+ assert.deepEqual(x.sub(y).to_8bit(), [152, 15, 211, 125, 200, 60]);
209
+ // x.to_8bit().should.eql([170, 1, 79, 119, 242, 62]);
210
+ // y.should.eql([17, 241, 123, 250, 42, 2]);
211
+ });
212
+
213
+ it("Should subtract one", function () {
214
+ const x = Crunchy.from_8bit([240, 0, 0, 0, 0, 0]);
215
+ const y = Crunchy.from_8bit([1]);
216
+
217
+ assert.deepEqual(x.sub(y).to_8bit(), [239, 255, 255, 255, 255, 255]);
218
+
219
+ // x.should.eql([240, 0, 0, 0, 0, 0]);
220
+ // y.should.eql([1]);
221
+ });
222
+
223
+ it("Should subtract numbers expecting negative result", function () {
224
+ const x = Crunchy.from_8bit([26]);
225
+ const y = Crunchy.from_8bit([255]);
226
+
227
+ assert.deepEqual(x.sub(y).to_8bit(), [-229]);
228
+
229
+ // x.should.eql([26]);
230
+ // y.should.eql([255]);
231
+ });
232
+
233
+ it("Should subtract numbers expecting negative result", function () {
234
+ const x = Crunchy.from_8bit([188, 196]);
235
+ const y = Crunchy.from_8bit([188, 197]);
236
+
237
+ assert.deepEqual(x.sub(y).to_8bit(), [-1]);
238
+
239
+ // x.should.eql([188, 196]);
240
+ // y.should.eql([188, 197]);
241
+ });
242
+
243
+ it("Should subtract negative number from positive", function () {
244
+ const x = Crunchy.from_8bit([240, 0, 0, 0, 0, 0]);
245
+ const y = Crunchy.from_8bit([-1]);
246
+ // console.log("negative:", x, y, x.sub(y));
247
+ assert.deepEqual(x.sub(y).to_8bit(), [240, 0, 0, 0, 0, 1]);
248
+
249
+ // x.should.eql([240, 0, 0, 0, 0, 0]);
250
+ // y.should.eql([-1]);
251
+ });
252
+
253
+ it("Should subtract positive number from negative", function () {
254
+ const x = Crunchy.from_8bit([-240, 0, 0, 0, 0, 0]);
255
+ const y = Crunchy.from_8bit([1]);
256
+
257
+ assert.deepEqual(x.sub(y).to_8bit(), [-240, 0, 0, 0, 0, 1]);
258
+
259
+ // x.should.eql([-240, 0, 0, 0, 0, 0]);
260
+ // y.should.eql([1]);
261
+ });
262
+
263
+ it("Should subtract two negative numbers", function () {
264
+ const x = Crunchy.from_8bit([-240, 0, 0, 0, 0, 0]);
265
+ const y = Crunchy.from_8bit([-1]);
266
+
267
+ assert.deepEqual(x.sub(y).to_8bit(), [-239, 255, 255, 255, 255, 255]);
268
+
269
+ // x.should.eql([-240, 0, 0, 0, 0, 0]);
270
+ // y.should.eql([-1]);
271
+ });
272
+
273
+ it("Should subtract two equal numbers expecting zero", function () {
274
+ const x = Crunchy.from_8bit([20]);
275
+ const y = Crunchy.from_8bit([20]);
276
+
277
+ assert.deepEqual(x.sub(y).to_8bit(), [0]);
278
+
279
+ // x.should.eql([20]);
280
+ // y.should.eql([20]);
281
+ });
282
+
283
+ it("Should subtract zero", function () {
284
+ const x = Crunchy.from_8bit([244, 137, 7, 161]);
285
+ const y = Crunchy.from_8bit([0]);
286
+
287
+ assert.deepEqual(x.sub(y).to_8bit(), [244, 137, 7, 161]);
288
+
289
+ // x.should.eql([244, 137, 7, 161]);
290
+ // y.should.eql([0]);
291
+ });
292
+
293
+ it("Should subtract zero from zero", function () {
294
+ const x = Crunchy.from_8bit([0]);
295
+ const y = Crunchy.from_8bit([0]);
296
+
297
+ assert.deepEqual(x.sub(y).to_8bit(), [0]);
298
+
299
+ // x.should.eql([0]);
300
+ // y.should.eql([0]);
301
+ });
302
+
303
+ it("Should subtract from zero", function () {
304
+ const x = Crunchy.from_8bit([0]);
305
+ const y = Crunchy.from_8bit([15]);
306
+
307
+ assert.deepEqual(x.sub(y).to_8bit(), [-15]);
308
+
309
+ // x.should.eql([0]);
310
+ // y.should.eql([15]);
311
+ });
312
+ });
313
+
314
+ describe("#mul", function () {
315
+ it("Should multiply numbers", function () {
316
+ const x = Crunchy.from_8bit([162, 51, 95]);
317
+ const y = Crunchy.from_8bit([42, 18, 204]);
318
+
319
+ assert.deepEqual(x.mul(y).to_8bit(), [26, 168, 86, 115, 157, 180]);
320
+ });
321
+
322
+ it("Should multiply numbers", function () {
323
+ const x = Crunchy.from_8bit([255, 65, 34, 51, 95]);
324
+ const y = Crunchy.from_8bit([42, 18, 204]);
325
+
326
+ assert.deepEqual(x.mul(y).to_8bit(), [41, 243, 109, 152, 188, 115, 157, 180]);
327
+ });
328
+
329
+ it("Should multiply numbers", function () {
330
+ const x = Crunchy.from_8bit([255, 255, 255, 255]);
331
+ const y = Crunchy.from_8bit([255, 255, 255, 255]);
332
+
333
+ assert.deepEqual(x.mul(y).to_8bit(), [255, 255, 255, 254, 0, 0, 0, 1]);
334
+ });
335
+
336
+ it("Should multiply positive with negative number", function () {
337
+ const x = Crunchy.from_8bit([77, 242, 62]);
338
+ const y = Crunchy.from_8bit([-42, 2, 113, 43, 57, 65]);
339
+
340
+ assert.deepEqual(x.mul(y).to_8bit(), [-12, 202, 124, 133, 146, 125, 36, 79, 190]);
341
+ });
342
+
343
+ it("Should multiply negative with positive number", function () {
344
+ const x = Crunchy.from_8bit([-255, 17, 162, 62]);
345
+ const y = Crunchy.from_8bit([255, 17, 162, 62]);
346
+
347
+ assert.deepEqual(x.mul(y).to_8bit(), [-254, 36, 34, 110, 119, 14, 135, 4]);
348
+ });
349
+
350
+ it("Should multiply two negative numbers", function () {
351
+ const x = Crunchy.from_8bit([-162, 51, 95]);
352
+ const y = Crunchy.from_8bit([-42, 18, 204]);
353
+
354
+ assert.deepEqual(x.mul(y).to_8bit(), [26, 168, 86, 115, 157, 180]);
355
+ });
356
+
357
+ it("Should multiply by zero", function () {
358
+ const x = Crunchy.from_8bit([77, 242, 62]);
359
+ const y = Crunchy.from_8bit([0]);
360
+
361
+ assert.deepEqual(x.mul(y).to_8bit(), [0]);
362
+ });
363
+
364
+ it("Should multiply zero by number", function () {
365
+ const x = Crunchy.from_8bit([0]);
366
+ const y = Crunchy.from_8bit([77, 242, 62]);
367
+
368
+ assert.deepEqual(x.mul(y).to_8bit(), [0]);
369
+ });
370
+
371
+ it("Should multiply zeros", function () {
372
+ const x = Crunchy.from_8bit([0]);
373
+ const y = Crunchy.from_8bit([0]);
374
+
375
+ assert.deepEqual(x.mul(y).to_8bit(), [0]);
376
+ });
377
+ });
378
+
379
+ describe("#div", function () {
380
+ it("Should divide numbers", function () {
381
+ const x = Crunchy.from_8bit([52, 155, 168, 23, 6, 85]);
382
+ const y = Crunchy.from_8bit([19, 26, 247]);
383
+
384
+ assert.deepEqual(x.div(y).to_8bit(), [2, 192, 234, 136]);
385
+ });
386
+
387
+ it("Should divide by one", function () {
388
+ const x = Crunchy.from_8bit([15, 127, 73, 1]);
389
+ const y = Crunchy.from_8bit([1]);
390
+
391
+ assert.deepEqual(x.div(y).to_8bit(), [15, 127, 73, 1]);
392
+ });
393
+
394
+ it("Should divide by self", function () {
395
+ const x = Crunchy.from_8bit([15, 127, 73, 1]);
396
+ const y = Crunchy.from_8bit([15, 127, 73, 1]);
397
+
398
+ assert.deepEqual(x.div(y).to_8bit(), [1]);
399
+ });
400
+
401
+ it("Should divide negative number", function () {
402
+ const x = Crunchy.from_8bit([-170, 153, 136]);
403
+ const y = Crunchy.from_8bit([17, 68]);
404
+
405
+ assert.deepEqual(x.div(y).to_8bit(), [-9, 225]);
406
+ });
407
+
408
+ it("Should divide by negative number", function () {
409
+ const x = Crunchy.from_8bit([170, 153, 136, 119, 102, 85]);
410
+ const y = Crunchy.from_8bit([-17, 68]);
411
+
412
+ assert.deepEqual(x.div(y).to_8bit(), [-9, 225, 129, 255, 9]);
413
+ });
414
+
415
+ it("Should divide two negative numbers", function () {
416
+ const x = Crunchy.from_8bit([-52, 155, 168, 23, 6, 85]);
417
+ const y = Crunchy.from_8bit([-19, 26, 247]);
418
+
419
+ assert.deepEqual(x.div(y).to_8bit(), [2, 192, 234, 136]);
420
+ });
421
+
422
+ it("Should divide zero", function () {
423
+ const x = Crunchy.from_8bit([0]);
424
+ const y = Crunchy.from_8bit([17, 68]);
425
+
426
+ assert.deepEqual(x.div(y).to_8bit(), [0]);
427
+ });
428
+
429
+ it("Shouldn't divide by zero", function () {
430
+ const x = Crunchy.from_8bit([170, 153]);
431
+ const y = Crunchy.from_8bit([0]);
432
+
433
+ assert.isNotOk(x.div(y));
434
+ });
435
+
436
+ it("Shouldn't divide zero by zero", function () {
437
+ const x = Crunchy.from_8bit([0]);
438
+ const y = Crunchy.from_8bit([0]);
439
+
440
+ assert.isNotOk(x.div(y));
441
+ });
442
+ });
443
+
444
+ // describe("#mod", function() {
445
+
446
+ // it("Should calculate modulo", function() {
447
+ // let x = [52, 155, 168, 23, 6, 85],
448
+ // y = [19, 26, 247];
449
+
450
+ // Crunch.mod(x, y).should.eql([10, 237, 29]);
451
+
452
+ // x.should.eql([52, 155, 168, 23, 6, 85]);
453
+ // y.should.eql([19, 26, 247]);
454
+ // });
455
+
456
+ // it("Should calculate modulo of number smaller than modulus", function() {
457
+ // let x = [1, 0],
458
+ // y = [1, 241];
459
+
460
+ // Crunch.mod(x, y).should.eql([1, 0]);
461
+
462
+ // x.should.eql([1, 0]);
463
+ // y.should.eql([1, 241]);
464
+ // });
465
+
466
+ // it("Should calculate modulo of modulus", function() {
467
+ // let x = [1, 241],
468
+ // y = [1, 241];
469
+
470
+ // Crunch.mod(x, y).should.eql([0]);
471
+
472
+ // x.should.eql([1, 241]);
473
+ // y.should.eql([1, 241]);
474
+ // });
475
+
476
+ // it("Should calculate modulo of zero", function() {
477
+ // let x = [0],
478
+ // y = [1, 241];
479
+
480
+ // Crunch.mod(x, y).should.eql([0]);
481
+
482
+ // x.should.eql([0]);
483
+ // y.should.eql([1, 241]);
484
+ // });
485
+
486
+ // // it("Should calculate modulo of negative", function() {
487
+ // // let x = [-4],
488
+ // // y = [3];
489
+
490
+ // // Crunch.mod(x, y).should.eql([2]);
491
+
492
+ // // x.should.eql([-4]);
493
+ // // y.should.eql([3]);
494
+ // // });
495
+
496
+ // // it("Should calculate modulo of negative", function() {
497
+ // // let x = [ -10, 18 ],
498
+ // // y = [ 123 ];
499
+
500
+ // // Crunch.mod(x, y).should.eql([ 5 ]);
501
+
502
+ // // x.should.eql([ -10, 18 ]);
503
+ // // y.should.eql([ 123 ]);
504
+ // // });
505
+
506
+ // // it("Should calculate modulo of negative", function() {
507
+ // // let x = [ -15, 62, 62, 18, 176 ],
508
+ // // y = [ 139, 207, 194, 82 ];
509
+
510
+ // // Crunch.mod(x, y).should.eql([ 12, 123, 46, 72 ]);
511
+
512
+ // // x.should.eql([ -15, 62, 62, 18, 176 ]);
513
+ // // y.should.eql([ 139, 207, 194, 82 ]);
514
+ // // });
515
+
516
+ // });
517
+
518
+ describe("#leftShift", function () {
519
+ it("Should left shift a number", function () {
520
+ const x = Crunchy.from_8bit([22, 11]);
521
+ const s = 5;
522
+
523
+ assert.deepEqual(x.shl(s).to_8bit(), [2, 193, 96]);
524
+ });
525
+
526
+ it("Should left shift a number more", function () {
527
+ const x = Crunchy.from_8bit([1]);
528
+ const s = 64;
529
+
530
+ assert.deepEqual(x.shl(s).to_8bit(), [1, 0, 0, 0, 0, 0, 0, 0, 0]);
531
+ });
532
+
533
+ it("Should left shift zero", function () {
534
+ const x = Crunchy.from_8bit([0]);
535
+ const s = 80;
536
+
537
+ assert.deepEqual(x.shl(s).to_8bit(), [0]);
538
+ });
539
+
540
+ it("Should left shift negative", function () {
541
+ const x = Crunchy.from_8bit([-3]);
542
+ const s = 8;
543
+
544
+ assert.deepEqual(x.shl(s).to_8bit(), [-3, 0]);
545
+ });
546
+
547
+ it("Should left shift one", function () {
548
+ const x = Crunchy.from_8bit([1, 0, 0, 0, 0]);
549
+ const s = 1;
550
+
551
+ assert.deepEqual(x.shl(s).to_8bit(), [2, 0, 0, 0, 0]);
552
+ });
553
+ });
554
+
555
+ describe("#rightShift", function () {
556
+ it("Should right shift a number to zero", function () {
557
+ const x = Crunchy.from_14bit([167837953]);
558
+ // assert.deepEqual(x.rsh(32).num, [0]);
559
+ assert.deepEqual(x.shr(32).num, [0]);
560
+ assert.deepEqual(x.shr(33).num, [0]);
561
+ });
562
+
563
+ it("Should right shift a number", function () {
564
+ const x = Crunchy.from_8bit([22, 11]);
565
+ const s = 5;
566
+
567
+ assert.deepEqual(x.shr(s).to_8bit(), [176]);
568
+ });
569
+
570
+ it("Should right shift a number out of existance", function () {
571
+ const x = Crunchy.from_8bit([22, 11]);
572
+ const s = 20;
573
+
574
+ assert.deepEqual(x.shr(s).to_8bit(), [0]);
575
+ });
576
+
577
+ it("Should right shift a negative number", function () {
578
+ const x = Crunchy.from_8bit([-3]);
579
+ const s = 8;
580
+ assert.deepEqual(x.shr(s).to_8bit(), [-0]);
581
+ });
582
+ });
583
+
584
+ // describe("#parse", function() {
585
+
586
+ // it("Should convert string to integer", function() {
587
+ // let s = "6315359056060240643798024";
588
+
589
+ // Crunchy.parse(s).to_8bit().should.eql([5, 57, 84, 76, 233, 0, 120, 91, 180, 180, 8]);
590
+
591
+ // s.should.equal("6315359056060240643798024");
592
+ // });
593
+
594
+ // it("Should convert string negative number to integer", function() {
595
+ // let s = "-256";
596
+
597
+ // Crunchy.parse(s).to_8bit().should.eql([-1, 0]);
598
+
599
+ // s.should.equal("-256");
600
+ // });
601
+
602
+ // });
603
+
604
+ // describe("#stringify", function() {
605
+
606
+ // it("Should convert integer to string", function() {
607
+ // let x = [5, 57, 84, 76, 233, 0, 120, 91, 180, 180, 8];
608
+
609
+ // Crunchy.from_8bit(x).to_8bit().should.equal("6315359056060240643798024");
610
+
611
+ // x.should.eql([5, 57, 84, 76, 233, 0, 120, 91, 180, 180, 8]);
612
+ // });
613
+
614
+ // });