Setting the file. One moment. Integers Write Test · Clickhouse Js Node Rowbinary · ClickHouse/agent-skills · Skills Docs(opens in a new tab)
tests/Integers.write.test.ts
TypeScript·186 lines·5 KB
writeInt64,
13 writeUInt128,
14 writeInt128,
15 writeUInt256,
16 writeInt256,
17} from "../src/writers/integers.js";
18
19describe("writeUInt8", () => {
20 it("encodes 0", async () =>
21 expect(encode(writeUInt8, 0)).toEqual(
22 await query("SELECT toUInt8('0') FORMAT RowBinary"),
23 ));
24 it("encodes 255", async () =>
25 expect(encode(writeUInt8, 255)).toEqual(
26 await query("SELECT toUInt8('255') FORMAT RowBinary"),
27 ));
28});
29
30describe("writeInt8", () => {
31 it("encodes -128", async () =>
32 expect(encode(writeInt8, -128)).toEqual(
33 await query("SELECT toInt8('-128') FORMAT RowBinary"),
34 ));
35 it("encodes 0", async () =>
36 expect(encode(writeInt8, 0)).toEqual(
37 await query("SELECT toInt8('0') FORMAT RowBinary"),
38 ));
39 it("encodes 127", async () =>
40 expect(encode(writeInt8, 127)).toEqual(
41 await query("SELECT toInt8('127') FORMAT RowBinary"),
42 ));
43});
44
45describe("writeUInt16", () => {
46 it("encodes 0", async () =>
47 expect(encode(writeUInt16, 0)).toEqual(
48 await query("SELECT toUInt16('0') FORMAT RowBinary"),
49 ));
50 it("encodes 65535", async () =>
51 expect(encode(writeUInt16, 65535)).toEqual(
52 await query("SELECT toUInt16('65535') FORMAT RowBinary"),
53 ));
54});
55
56describe("writeInt16", () => {
57 it("encodes -32768", async () =>
58 expect(encode(writeInt16, -32768)).toEqual(
59 await query("SELECT toInt16('-32768') FORMAT RowBinary"),
60 ));
61 it("encodes 32767", async () =>
62 expect(encode(writeInt16, 32767)).toEqual(
63 await query("SELECT toInt16('32767') FORMAT RowBinary"),
64 ));
65});
66
67describe("writeUInt32", () => {
68 it("encodes 0", async () =>
69 expect(encode(writeUInt32, 0)).toEqual(
70 await query("SELECT toUInt32('0') FORMAT RowBinary"),
71 ));
72 it("encodes 4294967295", async () =>
73 expect(encode(writeUInt32, 4294967295)).toEqual(
74 await query("SELECT toUInt32('4294967295') FORMAT RowBinary"),
75 ));
76});
77
78describe("writeInt32", () => {
79 it("encodes -2147483648", async () =>
80 expect(encode(writeInt32, -2147483648)).toEqual(
81 await query("SELECT toInt32('-2147483648') FORMAT RowBinary"),
82 ));
83 it("encodes 2147483647", async () =>
84 expect(encode(writeInt32, 2147483647)).toEqual(
85 await query("SELECT toInt32('2147483647') FORMAT RowBinary"),
86 ));
87});
88
89describe("writeUInt64", () => {
90 it("encodes 0", async () =>
91 expect(encode(writeUInt64, 0n)).toEqual(
92 await query("SELECT toUInt64('0') FORMAT RowBinary"),
93 ));
94 it("encodes 2^64 - 1", async () =>
95 expect(encode(writeUInt64, 18446744073709551615n)).toEqual(
96 await query("SELECT toUInt64('18446744073709551615') FORMAT RowBinary"),
97 ));
98});
99
100describe("writeInt64", () => {
101 it("encodes -2^63", async () =>
102 expect(encode(writeInt64, -9223372036854775808n)).toEqual(
103 await query("SELECT toInt64('-9223372036854775808') FORMAT RowBinary"),
104 ));
105 it("encodes 2^63 - 1", async () =>
106 expect(encode(writeInt64, 9223372036854775807n)).toEqual(
107 await query("SELECT toInt64('9223372036854775807') FORMAT RowBinary"),
108 ));
109});
110
111describe("writeUInt128", () => {
112 it("encodes 0", async () =>
113 expect(encode(writeUInt128, 0n)).toEqual(
114 await query("SELECT toUInt128('0') FORMAT RowBinary"),
115 ));
116 it("encodes 2^128 - 1", async () =>
117 expect(
118 encode(writeUInt128, 340282366920938463463374607431768211455n),
119 ).toEqual(
120 await query(
121 "SELECT toUInt128('340282366920938463463374607431768211455') FORMAT RowBinary",
122 ),
123 ));
124});
125
126describe("writeInt128", () => {
127 it("encodes -2^127", async () =>
128 expect(
129 encode(writeInt128, -170141183460469231731687303715884105728n),
130 ).toEqual(
131 await query(
132 "SELECT toInt128('-170141183460469231731687303715884105728') FORMAT RowBinary",
133 ),
134 ));
135 it("encodes 2^127 - 1", async () =>
136 expect(
137 encode(writeInt128, 170141183460469231731687303715884105727n),
138 ).toEqual(
139 await query(
140 "SELECT toInt128('170141183460469231731687303715884105727') FORMAT RowBinary",
141 ),
142 ));
143});
144
145describe("writeUInt256", () => {
146 it("encodes 0", async () =>
147 expect(encode(writeUInt256, 0n)).toEqual(
148 await query("SELECT toUInt256('0') FORMAT RowBinary"),
149 ));
150 it("encodes 2^256 - 1", async () =>
151 expect(
152 encode(
153 writeUInt256,
154 115792089237316195423570985008687907853269984665640564039457584007913129639935n,
155 ),
156 ).toEqual(
157 await query(
158 "SELECT toUInt256('115792089237316195423570985008687907853269984665640564039457584007913129639935') FORMAT RowBinary",
159 ),
160 ));
161});
162
163describe("writeInt256", () => {
164 it("encodes -2^255", async () =>
165 expect(
166 encode(
167 writeInt256,
168 -57896044618658097711785492504343953926634992332820282019728792003956564819968n,
169 ),
170 ).toEqual(
171 await query(
172 "SELECT toInt256('-57896044618658097711785492504343953926634992332820282019728792003956564819968') FORMAT RowBinary",
173 ),
174 ));
175 it("encodes 2^255 - 1", async () =>
176 expect(
177 encode(
178 writeInt256,
179 57896044618658097711785492504343953926634992332820282019728792003956564819967n,
180 ),
181 ).toEqual(
182 await query(
183 "SELECT toInt256('57896044618658097711785492504343953926634992332820282019728792003956564819967') FORMAT RowBinary",
184 ),
185 ));
186});