-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.test.ts
More file actions
79 lines (64 loc) · 2.42 KB
/
basic.test.ts
File metadata and controls
79 lines (64 loc) · 2.42 KB
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
77
78
79
import * as tac from './index';
test('uint32toUint8', () => {
expect(tac.uint32toUint8(new Uint32Array([0x12345678])))
.toMatchObject(new Uint8Array([0x12, 0x34, 0x56, 0x78]));
});
test('uint32toUint16', () => {
expect(tac.uint32toUint16(new Uint32Array([0x12345678])))
.toMatchObject(new Uint16Array([0x1234, 0x5678]));
});
test('uint16toUint8', () => {
expect(tac.uint16toUint8(new Uint16Array([0x1234])))
.toMatchObject(new Uint8Array([0x12, 0x34]));
});
test('uint16toUint32 ok', () => {
expect(tac.uint16toUint32(new Uint16Array([0x1234, 0x5678])))
.toMatchObject(new Uint32Array([0x12345678]));
});
test('uint8toUint16 ok', () => {
expect(tac.uint8toUint16(new Uint8Array([0x12, 0x34])))
.toMatchObject(new Uint16Array([0x1234]));
});
test('uint8toUint32 ok', () => {
expect(tac.uint8toUint32(new Uint8Array([0x12, 0x34, 0x56, 0x78])))
.toMatchObject(new Uint32Array([0x12345678]));
});
test('uint16toUint32 failed', () => {
expect(() => {
tac.uint16toUint32(new Uint16Array([0x1234, 0x5678, 0x9abc]))
}).toThrowError();
});
test('uint8toUint16 failed', () => {
expect(() => {
tac.uint8toUint16(new Uint8Array([0x12, 0x34, 0x56]))
}).toThrowError();
});
test('uint8toUint32 failed', () => {
expect(() => {
tac.uint8toUint32(new Uint8Array([0x12, 0x34, 0x56, 0x78, 0x9a]))
}).toThrowError();
});
test('uint16toUint32ZeroPadding ok', () => {
expect(tac.uint16toUint32ZeroPadding(new Uint16Array([0x1234, 0x5678])))
.toMatchObject(new Uint32Array([0x12345678]));
});
test('uint8toUint16ZeroPadding ok', () => {
expect(tac.uint8toUint16ZeroPadding(new Uint8Array([0x12, 0x34])))
.toMatchObject(new Uint16Array([0x1234]));
});
test('uint8toUint32ZeroPadding ok', () => {
expect(tac.uint8toUint32ZeroPadding(new Uint8Array([0x12, 0x34, 0x56, 0x78])))
.toMatchObject(new Uint32Array([0x12345678]));
});
test('uint16toUint32ZeroPadding pedding', () => {
expect(tac.uint16toUint32ZeroPadding(new Uint16Array([0x1234, 0x5678, 0x9abc])))
.toMatchObject(new Uint32Array([0x00001234, 0x56789abc]));
});
test('uint8toUint16ZeroPadding pedding', () => {
expect(tac.uint8toUint16ZeroPadding(new Uint8Array([0x12, 0x34, 0x56])))
.toMatchObject(new Uint16Array([0x0012, 0x3456]));
});
test('uint8toUint32ZeroPadding pedding', () => {
expect(tac.uint8toUint32ZeroPadding(new Uint8Array([0x12, 0x34, 0x56, 0x78, 0x9a])))
.toMatchObject(new Uint32Array([0x00000012, 0x3456789a]));
});