-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathlib.wordarray.test.js
76 lines (64 loc) · 2.56 KB
/
lib.wordarray.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import C from '../src/index';
describe('lib-wordarray-test', () => {
test('testInit0', () => {
expect(new C.lib.WordArray().toString()).toBe('');
});
test('testInit1', () => {
expect(new C.lib.WordArray([0x12345678]).toString()).toBe('12345678');
});
test('testInit2', () => {
expect(new C.lib.WordArray([0x12345678], 2).toString()).toBe('1234');
});
test('testToStringPassedEncoder', () => {
expect(new C.lib.WordArray([0x12345678]).toString(C.enc.Latin1)).toBe('\x12\x34\x56\x78');
});
test('testToStringDefaultEncoder', () => {
expect(new C.lib.WordArray([0x12345678]).toString()).toBe('12345678');
});
test('testConcat3', () => {
let wordArray1 = new C.lib.WordArray([0x12345678], 3);
let wordArray2 = new C.lib.WordArray([0x12345678], 3);
expect(wordArray1.concat(wordArray2).toString()).toBe('123456123456');
expect(wordArray1.toString()).toBe('123456123456');
});
test('testConcat4', () => {
let wordArray1 = new C.lib.WordArray([0x12345678], 4);
let wordArray2 = new C.lib.WordArray([0x12345678], 3);
expect(wordArray1.concat(wordArray2).toString()).toBe('12345678123456');
expect(wordArray1.toString()).toBe('12345678123456');
});
test('testConcat5', () => {
let wordArray1 = new C.lib.WordArray([0x12345678], 5);
let wordArray2 = new C.lib.WordArray([0x12345678], 3);
expect(wordArray1.concat(wordArray2).toString()).toBe('1234567800123456');
expect(wordArray1.toString()).toBe('1234567800123456');
});
test('testConcatLong', () => {
let wordArray1 = new C.lib.WordArray();
let wordArray2 = new C.lib.WordArray();
let wordArray3 = new C.lib.WordArray();
for (let i = 0; i < 500000; i++) {
wordArray2.words[i] = i;
wordArray3.words[i] = i;
}
wordArray2.sigBytes = 500000;
wordArray3.sigBytes = 500000;
const expected = wordArray2.toString() + wordArray3.toString();
expect(wordArray1.concat(wordArray2.concat(wordArray3)).toString()).toBe(expected);
});
test('testClamp', () => {
let wordArray = new C.lib.WordArray([0x12345678, 0x12345678], 3);
wordArray.clamp();
expect(wordArray.words.toString()).toBe([0x12345600].toString());
});
test('testClone', () => {
let wordArray = new C.lib.WordArray([0x12345678]);
let clone = wordArray.clone();
clone.words[0] = 0;
expect(clone.toString()).not.toBe(wordArray.toString());
});
test('testRandom', () => {
expect(C.lib.WordArray.random(8).toString()).not.toBe(C.lib.WordArray.random(8).toString());
expect(C.lib.WordArray.random(8).sigBytes).toBe(8);
});
});