ipaddress 0.2.5 → 0.2.7
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.
- package/dist/src/crunchy.d.ts +130 -0
- package/dist/src/crunchy.d.ts.map +1 -0
- package/dist/src/crunchy.js +616 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +21 -0
- package/{ip_bits.d.ts → dist/src/ip_bits.d.ts} +6 -7
- package/dist/src/ip_bits.d.ts.map +1 -0
- package/dist/src/ip_bits.js +133 -0
- package/{ip_version.d.ts → dist/src/ip_version.d.ts} +2 -1
- package/dist/src/ip_version.d.ts.map +1 -0
- package/dist/src/ip_version.js +6 -0
- package/{ipaddress.d.ts → dist/src/ipaddress.d.ts} +38 -35
- package/dist/src/ipaddress.d.ts.map +1 -0
- package/dist/src/ipaddress.js +1243 -0
- package/dist/src/ipv4.d.ts +15 -0
- package/dist/src/ipv4.d.ts.map +1 -0
- package/dist/src/ipv4.js +187 -0
- package/dist/src/ipv6.d.ts +13 -0
- package/dist/src/ipv6.d.ts.map +1 -0
- package/dist/src/ipv6.js +190 -0
- package/dist/src/ipv6_loopback.d.ts +6 -0
- package/dist/src/ipv6_loopback.d.ts.map +1 -0
- package/dist/src/ipv6_loopback.js +51 -0
- package/dist/src/ipv6_mapped.d.ts +6 -0
- package/dist/src/ipv6_mapped.d.ts.map +1 -0
- package/dist/src/ipv6_mapped.js +159 -0
- package/dist/src/ipv6_unspec.d.ts +6 -0
- package/dist/src/ipv6_unspec.d.ts.map +1 -0
- package/dist/src/ipv6_unspec.js +57 -0
- package/{prefix.d.ts → dist/src/prefix.d.ts} +10 -7
- package/dist/src/prefix.d.ts.map +1 -0
- package/dist/src/prefix.js +142 -0
- package/dist/src/prefix128.d.ts +7 -0
- package/dist/src/prefix128.d.ts.map +1 -0
- package/dist/src/prefix128.js +39 -0
- package/dist/src/prefix32.d.ts +7 -0
- package/dist/src/prefix32.d.ts.map +1 -0
- package/dist/src/prefix32.js +29 -0
- package/dist/src/rle.d.ts +19 -0
- package/dist/src/rle.d.ts.map +1 -0
- package/dist/src/rle.js +73 -0
- package/dist/test/test_crunchy_impls.d.ts +2 -0
- package/dist/test/test_crunchy_impls.d.ts.map +1 -0
- package/dist/test/test_crunchy_impls.js +150 -0
- package/dist/test/test_crunchy_with32bit.d.ts +2 -0
- package/dist/test/test_crunchy_with32bit.d.ts.map +1 -0
- package/dist/test/test_crunchy_with32bit.js +382 -0
- package/dist/test/test_ipaddress.d.ts +2 -0
- package/dist/test/test_ipaddress.d.ts.map +1 -0
- package/dist/test/test_ipaddress.js +182 -0
- package/dist/test/test_ipv4.d.ts +2 -0
- package/dist/test/test_ipv4.d.ts.map +1 -0
- package/dist/test/test_ipv4.js +561 -0
- package/dist/test/test_ipv6.d.ts +2 -0
- package/dist/test/test_ipv6.d.ts.map +1 -0
- package/dist/test/test_ipv6.js +313 -0
- package/dist/test/test_ipv6_loopback.d.ts +2 -0
- package/dist/test/test_ipv6_loopback.d.ts.map +1 -0
- package/dist/test/test_ipv6_loopback.js +40 -0
- package/dist/test/test_ipv6_mapped.d.ts +2 -0
- package/dist/test/test_ipv6_mapped.d.ts.map +1 -0
- package/dist/test/test_ipv6_mapped.js +89 -0
- package/dist/test/test_ipv6_unspec.d.ts +2 -0
- package/dist/test/test_ipv6_unspec.d.ts.map +1 -0
- package/dist/test/test_ipv6_unspec.js +39 -0
- package/dist/test/test_prefix128.d.ts +2 -0
- package/dist/test/test_prefix128.d.ts.map +1 -0
- package/dist/test/test_prefix128.js +35 -0
- package/dist/test/test_prefix32.d.ts +2 -0
- package/dist/test/test_prefix32.d.ts.map +1 -0
- package/dist/test/test_prefix32.js +126 -0
- package/dist/test/test_rle.d.ts +2 -0
- package/dist/test/test_rle.d.ts.map +1 -0
- package/dist/test/test_rle.js +141 -0
- package/dist/vitest.config.d.ts +3 -0
- package/dist/vitest.config.d.ts.map +1 -0
- package/dist/vitest.config.js +11 -0
- package/package.json +41 -37
- package/src/crunchy.ts +731 -0
- package/src/index.ts +23 -0
- package/src/ip_bits.ts +148 -0
- package/src/ip_version.ts +6 -0
- package/src/ipaddress.ts +1347 -0
- package/src/ipv4.ts +203 -0
- package/src/ipv6.ts +202 -0
- package/src/ipv6_loopback.ts +55 -0
- package/src/ipv6_mapped.ts +163 -0
- package/src/ipv6_unspec.ts +59 -0
- package/src/prefix.ts +170 -0
- package/src/prefix128.ts +42 -0
- package/src/prefix32.ts +32 -0
- package/src/rle.ts +85 -0
- package/test/test_crunchy_impls.ts +179 -0
- package/test/test_crunchy_with32bit.ts +510 -0
- package/test/test_ipaddress.ts +208 -0
- package/test/test_ipv4.ts +596 -0
- package/test/test_ipv6.ts +325 -0
- package/test/test_ipv6_loopback.ts +52 -0
- package/test/test_ipv6_mapped.ts +101 -0
- package/test/test_ipv6_unspec.ts +51 -0
- package/test/test_prefix128.ts +39 -0
- package/test/test_prefix32.ts +130 -0
- package/test/test_rle.ts +144 -0
- package/LICENSE +0 -20
- package/README.md +0 -960
- package/crunchy.d.ts +0 -55
- package/index.d.ts +0 -12
- package/ipaddress.js +0 -2869
- package/ipaddress.js.map +0 -1
- package/ipv4.d.ts +0 -14
- package/ipv6.d.ts +0 -12
- package/ipv6_loopback.d.ts +0 -5
- package/ipv6_mapped.d.ts +0 -5
- package/ipv6_unspec.d.ts +0 -5
- package/prefix128.d.ts +0 -6
- package/prefix32.d.ts +0 -6
- package/rle.d.ts +0 -14
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
import { CrunchyWith32Bit } from "../src/crunchy.js";
|
|
2
|
+
|
|
3
|
+
const c32 = new CrunchyWith32Bit();
|
|
4
|
+
|
|
5
|
+
describe("#compare", function () {
|
|
6
|
+
it("Should confirm equality", function () {
|
|
7
|
+
const x = c32.from_string("12345678901234567890");
|
|
8
|
+
const y = c32.from_string("12345678901234567890");
|
|
9
|
+
assert.isTrue(x!.eq(y!));
|
|
10
|
+
// this.done();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("Should find first is greater than second", function () {
|
|
14
|
+
const x = c32.from_string("12345678901234567890");
|
|
15
|
+
const y = c32.from_string("1234567890");
|
|
16
|
+
assert.isTrue(x!.gt(y!));
|
|
17
|
+
// this.done();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("Should find first is less than second", function () {
|
|
21
|
+
const x = c32.from_string("1234567890");
|
|
22
|
+
const y = c32.from_string("12345678901234567890");
|
|
23
|
+
assert.isTrue(x!.lt(y!));
|
|
24
|
+
// this.done();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("#add", function () {
|
|
29
|
+
it("Should add numbers", function () {
|
|
30
|
+
const x = CrunchyWith32Bit.from_8bit([242, 62]);
|
|
31
|
+
const y = CrunchyWith32Bit.from_8bit([42, 2]);
|
|
32
|
+
|
|
33
|
+
assert.deepEqual(x.add(y).to_8bit(), [1, 28, 64]);
|
|
34
|
+
// x.should.eql([242, 62]);
|
|
35
|
+
// y.should.eql([42, 2]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("Should add numbers, first longer than second", function () {
|
|
39
|
+
const x = CrunchyWith32Bit.from_8bit([26, 255, 230, 17]);
|
|
40
|
+
const y = CrunchyWith32Bit.from_8bit([42, 34]);
|
|
41
|
+
|
|
42
|
+
assert.deepEqual(x.add(y).to_8bit(), [27, 0, 16, 51]);
|
|
43
|
+
|
|
44
|
+
// x, [26, 255, 230, 17]);
|
|
45
|
+
// y.should.eql([42, 34]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("Should add numbers, second longer than first", function () {
|
|
49
|
+
const x = CrunchyWith32Bit.from_8bit([234, 34]);
|
|
50
|
+
const y = CrunchyWith32Bit.from_8bit([255, 255, 230, 17]);
|
|
51
|
+
|
|
52
|
+
assert.deepEqual(x.add(y).to_8bit(), [1, 0, 0, 208, 51]);
|
|
53
|
+
|
|
54
|
+
// x.should.eql([234, 34]);
|
|
55
|
+
// y.should.eql([255, 255, 230, 17]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("Should add two identical numbers", function () {
|
|
59
|
+
const x = CrunchyWith32Bit.from_8bit([255, 255, 255, 255, 255, 255]);
|
|
60
|
+
const y = CrunchyWith32Bit.from_8bit([255, 255, 255, 255, 255, 255]);
|
|
61
|
+
|
|
62
|
+
assert.deepEqual(x.add(y).to_8bit(), [1, 255, 255, 255, 255, 255, 254]);
|
|
63
|
+
|
|
64
|
+
// x.should.eql([255, 255, 255, 255, 255, 255]);
|
|
65
|
+
// y.should.eql([255, 255, 255, 255, 255, 255]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("Should add positive to negative number expecting positive result", function () {
|
|
69
|
+
const x = CrunchyWith32Bit.from_8bit([51, 254, 144, 207]);
|
|
70
|
+
const y = CrunchyWith32Bit.from_8bit([-20, 89, 145, 32]);
|
|
71
|
+
|
|
72
|
+
assert.deepEqual(x.add(y).to_8bit(), [31, 164, 255, 175]);
|
|
73
|
+
|
|
74
|
+
// x.should.eql([51, 254, 144, 207]);
|
|
75
|
+
// y.should.eql([-20, 89, 145, 32]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("Should add positive to negative number expecting negative result", function () {
|
|
79
|
+
const x = CrunchyWith32Bit.from_8bit([242, 62]);
|
|
80
|
+
const y = CrunchyWith32Bit.from_8bit([-242, 64]);
|
|
81
|
+
|
|
82
|
+
assert.deepEqual(x.add(y).to_8bit(), [-2]);
|
|
83
|
+
|
|
84
|
+
// x.should.eql([242, 62]);
|
|
85
|
+
// y.should.eql([-242, 64]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("Should add negative to positive number expecting positive result", function () {
|
|
89
|
+
const x = CrunchyWith32Bit.from_8bit([-42, 2]);
|
|
90
|
+
const y = CrunchyWith32Bit.from_8bit([242, 62]);
|
|
91
|
+
|
|
92
|
+
assert.deepEqual(x.add(y).to_8bit(), [200, 60]);
|
|
93
|
+
|
|
94
|
+
// x, [-42, 2]);
|
|
95
|
+
// y, [242, 62]);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("Should add negative to positive number expecting negative result", function () {
|
|
99
|
+
const x = CrunchyWith32Bit.from_8bit([-42, 2]);
|
|
100
|
+
const y = CrunchyWith32Bit.from_8bit([42, 0]);
|
|
101
|
+
|
|
102
|
+
assert.deepEqual(x.add(y).to_8bit(), [-2]);
|
|
103
|
+
// x, [-42, 2]);
|
|
104
|
+
// y, [42, 0]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("Should add two negative numbers expecting negative result", function () {
|
|
108
|
+
const x = CrunchyWith32Bit.from_8bit([-242, 62]);
|
|
109
|
+
const y = CrunchyWith32Bit.from_8bit([-42, 2]);
|
|
110
|
+
|
|
111
|
+
assert.deepEqual(x.add(y).to_8bit(), [-1, 28, 64]);
|
|
112
|
+
|
|
113
|
+
// x, [-242, 62]);
|
|
114
|
+
// y, [-42, 2]);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("Should add zero to number", function () {
|
|
118
|
+
const x = CrunchyWith32Bit.from_8bit([26, 255, 230, 17]);
|
|
119
|
+
const y = CrunchyWith32Bit.from_8bit([0]);
|
|
120
|
+
|
|
121
|
+
assert.deepEqual(x.add(y).to_8bit(), [26, 255, 230, 17]);
|
|
122
|
+
|
|
123
|
+
// x, [26, 255, 230, 17]);
|
|
124
|
+
// y, [0]);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("Should add number to zero", function () {
|
|
128
|
+
const x = CrunchyWith32Bit.from_8bit([0]);
|
|
129
|
+
const y = CrunchyWith32Bit.from_8bit([43, 123, 200, 1]);
|
|
130
|
+
|
|
131
|
+
assert.deepEqual(x.add(y).to_8bit(), [43, 123, 200, 1]);
|
|
132
|
+
|
|
133
|
+
// x, [0]);
|
|
134
|
+
// y, [43, 123, 200, 1]);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("Should add two zeros", function () {
|
|
138
|
+
const x = CrunchyWith32Bit.from_8bit([0]);
|
|
139
|
+
const y = CrunchyWith32Bit.from_8bit([0]);
|
|
140
|
+
|
|
141
|
+
assert.deepEqual(x.add(y).to_8bit(), [0]);
|
|
142
|
+
|
|
143
|
+
// x.should.eql([0]);
|
|
144
|
+
// y.should.eql([0]);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("#add-from_string", function () {
|
|
149
|
+
it("Should add numbers", function () {
|
|
150
|
+
// console.log(new Date());
|
|
151
|
+
const x = c32.from_string("12345678911234567891");
|
|
152
|
+
// console.log(new Date());
|
|
153
|
+
const y = c32.from_string("12345678901234567890");
|
|
154
|
+
// console.log(new Date(), x, y);
|
|
155
|
+
// console.log("addddddd:", new Date(), x, x.toString(), y, y.toString(), x.add(y).toString());
|
|
156
|
+
assert.equal(x!.add(y!).toString(), "24691357812469135781");
|
|
157
|
+
// console.log(new Date());
|
|
158
|
+
// this.done();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("Should add numbers, first longer than second", function () {
|
|
162
|
+
const x = c32.from_string("12345678901234567890");
|
|
163
|
+
const y = c32.from_string("1234567890");
|
|
164
|
+
assert.equal(x!.add(y!).toString(), "12345678902469135780");
|
|
165
|
+
// this.done();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("Should add numbers, second longer than first", function () {
|
|
169
|
+
const x = c32.from_string("1234567890");
|
|
170
|
+
const y = c32.from_string("12345678901234567890");
|
|
171
|
+
assert.equal(x!.add(y!).toString(), "12345678902469135780");
|
|
172
|
+
// this.done();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("Should add two identical numbers", function () {
|
|
176
|
+
const x = c32.from_string("12345678901234567890");
|
|
177
|
+
const y = c32.from_string("12345678901234567890");
|
|
178
|
+
assert.equal(x!.add(y!).toString(), "24691357802469135780");
|
|
179
|
+
// this.done();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("Should add zero to number", function () {
|
|
183
|
+
const x = c32.from_string("12345678901234567890");
|
|
184
|
+
const y = c32.from_string("0");
|
|
185
|
+
assert.equal(x!.add(y!).toString(), "12345678901234567890");
|
|
186
|
+
// this.done();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("Should add number to zero", function () {
|
|
190
|
+
const x = c32.from_string("0");
|
|
191
|
+
const y = c32.from_string("12345678901234567890");
|
|
192
|
+
assert.equal(x!.add(y!).toString(), "12345678901234567890");
|
|
193
|
+
// this.done();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("Should add two zeros", function () {
|
|
197
|
+
const x = c32.from_string("0");
|
|
198
|
+
const y = c32.from_string("0");
|
|
199
|
+
assert.equal(x!.add(y!).toString(), "0");
|
|
200
|
+
// this.done();
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
describe("#sub", function () {
|
|
205
|
+
it("Should subtract numbers", function () {
|
|
206
|
+
const x = CrunchyWith32Bit.from_8bit([170, 1, 79, 119, 242, 62]);
|
|
207
|
+
const y = CrunchyWith32Bit.from_8bit([17, 241, 123, 250, 42, 2]);
|
|
208
|
+
|
|
209
|
+
// console.log("Should subtract numbers:", x, y, x.sub(y));
|
|
210
|
+
assert.deepEqual(x.sub(y).to_8bit(), [152, 15, 211, 125, 200, 60]);
|
|
211
|
+
// x.to_8bit().should.eql([170, 1, 79, 119, 242, 62]);
|
|
212
|
+
// y.should.eql([17, 241, 123, 250, 42, 2]);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("Should subtract one", function () {
|
|
216
|
+
const x = CrunchyWith32Bit.from_8bit([240, 0, 0, 0, 0, 0]);
|
|
217
|
+
const y = CrunchyWith32Bit.from_8bit([1]);
|
|
218
|
+
|
|
219
|
+
assert.deepEqual(x.sub(y).to_8bit(), [239, 255, 255, 255, 255, 255]);
|
|
220
|
+
|
|
221
|
+
// x.should.eql([240, 0, 0, 0, 0, 0]);
|
|
222
|
+
// y.should.eql([1]);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("Should subtract numbers expecting negative result", function () {
|
|
226
|
+
const x = CrunchyWith32Bit.from_8bit([26]);
|
|
227
|
+
const y = CrunchyWith32Bit.from_8bit([255]);
|
|
228
|
+
|
|
229
|
+
assert.deepEqual(x.sub(y).to_8bit(), [-229]);
|
|
230
|
+
|
|
231
|
+
// x.should.eql([26]);
|
|
232
|
+
// y.should.eql([255]);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("Should subtract numbers expecting negative result", function () {
|
|
236
|
+
const x = CrunchyWith32Bit.from_8bit([188, 196]);
|
|
237
|
+
const y = CrunchyWith32Bit.from_8bit([188, 197]);
|
|
238
|
+
|
|
239
|
+
assert.deepEqual(x.sub(y).to_8bit(), [-1]);
|
|
240
|
+
|
|
241
|
+
// x.should.eql([188, 196]);
|
|
242
|
+
// y.should.eql([188, 197]);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("Should subtract negative number from positive", function () {
|
|
246
|
+
const x = CrunchyWith32Bit.from_8bit([240, 0, 0, 0, 0, 0]);
|
|
247
|
+
const y = CrunchyWith32Bit.from_8bit([-1]);
|
|
248
|
+
// console.log("negative:", x, y, x.sub(y));
|
|
249
|
+
assert.deepEqual(x.sub(y).to_8bit(), [240, 0, 0, 0, 0, 1]);
|
|
250
|
+
|
|
251
|
+
// x.should.eql([240, 0, 0, 0, 0, 0]);
|
|
252
|
+
// y.should.eql([-1]);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("Should subtract positive number from negative", function () {
|
|
256
|
+
const x = CrunchyWith32Bit.from_8bit([-240, 0, 0, 0, 0, 0]);
|
|
257
|
+
const y = CrunchyWith32Bit.from_8bit([1]);
|
|
258
|
+
|
|
259
|
+
assert.deepEqual(x.sub(y).to_8bit(), [-240, 0, 0, 0, 0, 1]);
|
|
260
|
+
|
|
261
|
+
// x.should.eql([-240, 0, 0, 0, 0, 0]);
|
|
262
|
+
// y.should.eql([1]);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("Should subtract two negative numbers", function () {
|
|
266
|
+
const x = CrunchyWith32Bit.from_8bit([-240, 0, 0, 0, 0, 0]);
|
|
267
|
+
const y = CrunchyWith32Bit.from_8bit([-1]);
|
|
268
|
+
|
|
269
|
+
assert.deepEqual(x.sub(y).to_8bit(), [-239, 255, 255, 255, 255, 255]);
|
|
270
|
+
|
|
271
|
+
// x.should.eql([-240, 0, 0, 0, 0, 0]);
|
|
272
|
+
// y.should.eql([-1]);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("Should subtract two equal numbers expecting zero", function () {
|
|
276
|
+
const x = CrunchyWith32Bit.from_8bit([20]);
|
|
277
|
+
const y = CrunchyWith32Bit.from_8bit([20]);
|
|
278
|
+
|
|
279
|
+
assert.deepEqual(x.sub(y).to_8bit(), [0]);
|
|
280
|
+
|
|
281
|
+
// x.should.eql([20]);
|
|
282
|
+
// y.should.eql([20]);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("Should subtract zero", function () {
|
|
286
|
+
const x = CrunchyWith32Bit.from_8bit([244, 137, 7, 161]);
|
|
287
|
+
const y = CrunchyWith32Bit.from_8bit([0]);
|
|
288
|
+
|
|
289
|
+
assert.deepEqual(x.sub(y).to_8bit(), [244, 137, 7, 161]);
|
|
290
|
+
|
|
291
|
+
// x.should.eql([244, 137, 7, 161]);
|
|
292
|
+
// y.should.eql([0]);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it("Should subtract zero from zero", function () {
|
|
296
|
+
const x = CrunchyWith32Bit.from_8bit([0]);
|
|
297
|
+
const y = CrunchyWith32Bit.from_8bit([0]);
|
|
298
|
+
|
|
299
|
+
assert.deepEqual(x.sub(y).to_8bit(), [0]);
|
|
300
|
+
|
|
301
|
+
// x.should.eql([0]);
|
|
302
|
+
// y.should.eql([0]);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("Should subtract from zero", function () {
|
|
306
|
+
const x = CrunchyWith32Bit.from_8bit([0]);
|
|
307
|
+
const y = CrunchyWith32Bit.from_8bit([15]);
|
|
308
|
+
|
|
309
|
+
assert.deepEqual(x.sub(y).to_8bit(), [-15]);
|
|
310
|
+
|
|
311
|
+
// x.should.eql([0]);
|
|
312
|
+
// y.should.eql([15]);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
describe("#mul", function () {
|
|
317
|
+
it("Should multiply numbers", function () {
|
|
318
|
+
const x = CrunchyWith32Bit.from_8bit([162, 51, 95]);
|
|
319
|
+
const y = CrunchyWith32Bit.from_8bit([42, 18, 204]);
|
|
320
|
+
|
|
321
|
+
assert.deepEqual(x.mul(y).to_8bit(), [26, 168, 86, 115, 157, 180]);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it("Should multiply numbers", function () {
|
|
325
|
+
const x = CrunchyWith32Bit.from_8bit([255, 65, 34, 51, 95]);
|
|
326
|
+
const y = CrunchyWith32Bit.from_8bit([42, 18, 204]);
|
|
327
|
+
|
|
328
|
+
assert.deepEqual(x.mul(y).to_8bit(), [41, 243, 109, 152, 188, 115, 157, 180]);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it("Should multiply numbers", function () {
|
|
332
|
+
const x = CrunchyWith32Bit.from_8bit([255, 255, 255, 255]);
|
|
333
|
+
const y = CrunchyWith32Bit.from_8bit([255, 255, 255, 255]);
|
|
334
|
+
|
|
335
|
+
assert.deepEqual(x.mul(y).to_8bit(), [255, 255, 255, 254, 0, 0, 0, 1]);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it("Should multiply positive with negative number", function () {
|
|
339
|
+
const x = CrunchyWith32Bit.from_8bit([77, 242, 62]);
|
|
340
|
+
const y = CrunchyWith32Bit.from_8bit([-42, 2, 113, 43, 57, 65]);
|
|
341
|
+
|
|
342
|
+
assert.deepEqual(x.mul(y).to_8bit(), [-12, 202, 124, 133, 146, 125, 36, 79, 190]);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it("Should multiply negative with positive number", function () {
|
|
346
|
+
const x = CrunchyWith32Bit.from_8bit([-255, 17, 162, 62]);
|
|
347
|
+
const y = CrunchyWith32Bit.from_8bit([255, 17, 162, 62]);
|
|
348
|
+
|
|
349
|
+
assert.deepEqual(x.mul(y).to_8bit(), [-254, 36, 34, 110, 119, 14, 135, 4]);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("Should multiply two negative numbers", function () {
|
|
353
|
+
const x = CrunchyWith32Bit.from_8bit([-162, 51, 95]);
|
|
354
|
+
const y = CrunchyWith32Bit.from_8bit([-42, 18, 204]);
|
|
355
|
+
|
|
356
|
+
assert.deepEqual(x.mul(y).to_8bit(), [26, 168, 86, 115, 157, 180]);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("Should multiply by zero", function () {
|
|
360
|
+
const x = CrunchyWith32Bit.from_8bit([77, 242, 62]);
|
|
361
|
+
const y = CrunchyWith32Bit.from_8bit([0]);
|
|
362
|
+
|
|
363
|
+
assert.deepEqual(x.mul(y).to_8bit(), [0]);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it("Should multiply zero by number", function () {
|
|
367
|
+
const x = CrunchyWith32Bit.from_8bit([0]);
|
|
368
|
+
const y = CrunchyWith32Bit.from_8bit([77, 242, 62]);
|
|
369
|
+
|
|
370
|
+
assert.deepEqual(x.mul(y).to_8bit(), [0]);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it("Should multiply zeros", function () {
|
|
374
|
+
const x = CrunchyWith32Bit.from_8bit([0]);
|
|
375
|
+
const y = CrunchyWith32Bit.from_8bit([0]);
|
|
376
|
+
|
|
377
|
+
assert.deepEqual(x.mul(y).to_8bit(), [0]);
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
describe("#div", function () {
|
|
382
|
+
it("Should divide numbers", function () {
|
|
383
|
+
const x = CrunchyWith32Bit.from_8bit([52, 155, 168, 23, 6, 85]);
|
|
384
|
+
const y = CrunchyWith32Bit.from_8bit([19, 26, 247]);
|
|
385
|
+
|
|
386
|
+
assert.deepEqual(x.div(y)!.to_8bit(), [2, 192, 234, 136]);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it("Should divide by one", function () {
|
|
390
|
+
const x = CrunchyWith32Bit.from_8bit([15, 127, 73, 1]);
|
|
391
|
+
const y = CrunchyWith32Bit.from_8bit([1]);
|
|
392
|
+
|
|
393
|
+
assert.deepEqual(x.div(y)!.to_8bit(), [15, 127, 73, 1]);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it("Should divide by self", function () {
|
|
397
|
+
const x = CrunchyWith32Bit.from_8bit([15, 127, 73, 1]);
|
|
398
|
+
const y = CrunchyWith32Bit.from_8bit([15, 127, 73, 1]);
|
|
399
|
+
|
|
400
|
+
assert.deepEqual(x.div(y)!.to_8bit(), [1]);
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it("Should divide negative number", function () {
|
|
404
|
+
const x = CrunchyWith32Bit.from_8bit([-170, 153, 136]);
|
|
405
|
+
const y = CrunchyWith32Bit.from_8bit([17, 68]);
|
|
406
|
+
|
|
407
|
+
assert.deepEqual(x.div(y)!.to_8bit(), [-9, 225]);
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
it("Should divide by negative number", function () {
|
|
411
|
+
const x = CrunchyWith32Bit.from_8bit([170, 153, 136, 119, 102, 85]);
|
|
412
|
+
const y = CrunchyWith32Bit.from_8bit([-17, 68]);
|
|
413
|
+
|
|
414
|
+
assert.deepEqual(x.div(y)!.to_8bit(), [-9, 225, 129, 255, 9]);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
it("Should divide two negative numbers", function () {
|
|
418
|
+
const x = CrunchyWith32Bit.from_8bit([-52, 155, 168, 23, 6, 85]);
|
|
419
|
+
const y = CrunchyWith32Bit.from_8bit([-19, 26, 247]);
|
|
420
|
+
|
|
421
|
+
assert.deepEqual(x.div(y)!.to_8bit(), [2, 192, 234, 136]);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
it("Should divide zero", function () {
|
|
425
|
+
const x = CrunchyWith32Bit.from_8bit([0]);
|
|
426
|
+
const y = CrunchyWith32Bit.from_8bit([17, 68]);
|
|
427
|
+
|
|
428
|
+
assert.deepEqual(x.div(y)!.to_8bit(), [0]);
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
it("Shouldn't divide by zero", function () {
|
|
432
|
+
const x = CrunchyWith32Bit.from_8bit([170, 153]);
|
|
433
|
+
const y = CrunchyWith32Bit.from_8bit([0]);
|
|
434
|
+
|
|
435
|
+
assert.isNotOk(x.div(y));
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it("Shouldn't divide zero by zero", function () {
|
|
439
|
+
const x = CrunchyWith32Bit.from_8bit([0]);
|
|
440
|
+
const y = CrunchyWith32Bit.from_8bit([0]);
|
|
441
|
+
|
|
442
|
+
assert.isNotOk(x.div(y));
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
describe("#leftShift", function () {
|
|
447
|
+
it("Should left shift a number", function () {
|
|
448
|
+
const x = CrunchyWith32Bit.from_8bit([22, 11]);
|
|
449
|
+
const s = 5;
|
|
450
|
+
|
|
451
|
+
assert.deepEqual(x.shl(s).to_8bit(), [2, 193, 96]);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it("Should left shift a number more", function () {
|
|
455
|
+
const x = CrunchyWith32Bit.from_8bit([1]);
|
|
456
|
+
const s = 64;
|
|
457
|
+
|
|
458
|
+
assert.deepEqual(x.shl(s).to_8bit(), [1, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it("Should left shift zero", function () {
|
|
462
|
+
const x = CrunchyWith32Bit.from_8bit([0]);
|
|
463
|
+
const s = 80;
|
|
464
|
+
|
|
465
|
+
assert.deepEqual(x.shl(s).to_8bit(), [0]);
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it("Should left shift negative", function () {
|
|
469
|
+
const x = CrunchyWith32Bit.from_8bit([-3]);
|
|
470
|
+
const s = 8;
|
|
471
|
+
|
|
472
|
+
assert.deepEqual(x.shl(s).to_8bit(), [-3, 0]);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it("Should left shift one", function () {
|
|
476
|
+
const x = CrunchyWith32Bit.from_8bit([1, 0, 0, 0, 0]);
|
|
477
|
+
const s = 1;
|
|
478
|
+
|
|
479
|
+
assert.deepEqual(x.shl(s).to_8bit(), [2, 0, 0, 0, 0]);
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
describe("#rightShift", function () {
|
|
484
|
+
it("Should right shift a number to zero", function () {
|
|
485
|
+
const x = CrunchyWith32Bit.from_14bit([167837953]);
|
|
486
|
+
// assert.deepEqual(x.rsh(32).num, [0]);
|
|
487
|
+
assert.deepEqual(x.shr(32).num, [0]);
|
|
488
|
+
assert.deepEqual(x.shr(33).num, [0]);
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
it("Should right shift a number", function () {
|
|
492
|
+
const x = CrunchyWith32Bit.from_8bit([22, 11]);
|
|
493
|
+
const s = 5;
|
|
494
|
+
|
|
495
|
+
assert.deepEqual(x.shr(s).to_8bit(), [176]);
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
it("Should right shift a number out of existance", function () {
|
|
499
|
+
const x = CrunchyWith32Bit.from_8bit([22, 11]);
|
|
500
|
+
const s = 20;
|
|
501
|
+
|
|
502
|
+
assert.deepEqual(x.shr(s).to_8bit(), [0]);
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
it("Should right shift a negative number", function () {
|
|
506
|
+
const x = CrunchyWith32Bit.from_8bit([-3]);
|
|
507
|
+
const s = 8;
|
|
508
|
+
assert.deepEqual(x.shr(s).to_8bit(), [-0]);
|
|
509
|
+
});
|
|
510
|
+
});
|