|
1 | 1 | import { describe, expect, it } from "vitest"; |
2 | 2 | import type { ReconstructionInfo } from "./XetBlob"; |
3 | | -import { bg4_regoup_bytes, XetBlob } from "./XetBlob"; |
| 3 | +import { bg4_regroup_bytes, bg4_split_bytes, XetBlob } from "./XetBlob"; |
4 | 4 | import { sum } from "./sum"; |
5 | 5 |
|
6 | 6 | describe("XetBlob", () => { |
@@ -173,30 +173,72 @@ describe("XetBlob", () => { |
173 | 173 |
|
174 | 174 | describe("bg4_regoup_bytes", () => { |
175 | 175 | it("should regroup bytes when the array is %4 length", () => { |
176 | | - expect(bg4_regoup_bytes(new Uint8Array([1, 5, 2, 6, 3, 7, 4, 8]))).toEqual( |
| 176 | + expect(bg4_regroup_bytes(new Uint8Array([1, 5, 2, 6, 3, 7, 4, 8]))).toEqual( |
177 | 177 | new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]) |
178 | 178 | ); |
179 | 179 | }); |
180 | 180 |
|
181 | 181 | it("should regroup bytes when the array is %4 + 1 length", () => { |
182 | | - expect(bg4_regoup_bytes(new Uint8Array([1, 5, 9, 2, 6, 3, 7, 4, 8]))).toEqual( |
| 182 | + expect(bg4_regroup_bytes(new Uint8Array([1, 5, 9, 2, 6, 3, 7, 4, 8]))).toEqual( |
183 | 183 | new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9]) |
184 | 184 | ); |
185 | 185 | }); |
186 | 186 |
|
187 | 187 | it("should regroup bytes when the array is %4 + 2 length", () => { |
188 | | - expect(bg4_regoup_bytes(new Uint8Array([1, 5, 9, 2, 6, 10, 3, 7, 4, 8]))).toEqual( |
| 188 | + expect(bg4_regroup_bytes(new Uint8Array([1, 5, 9, 2, 6, 10, 3, 7, 4, 8]))).toEqual( |
189 | 189 | new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) |
190 | 190 | ); |
191 | 191 | }); |
192 | 192 |
|
193 | 193 | it("should regroup bytes when the array is %4 + 3 length", () => { |
194 | | - expect(bg4_regoup_bytes(new Uint8Array([1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8]))).toEqual( |
| 194 | + expect(bg4_regroup_bytes(new Uint8Array([1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8]))).toEqual( |
195 | 195 | new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) |
196 | 196 | ); |
197 | 197 | }); |
198 | 198 | }); |
199 | 199 |
|
| 200 | + describe("bg4_split_bytes", () => { |
| 201 | + it("should split bytes when the array is %4 length", () => { |
| 202 | + expect(bg4_split_bytes(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]))).toEqual( |
| 203 | + new Uint8Array([1, 5, 2, 6, 3, 7, 4, 8]) |
| 204 | + ); |
| 205 | + }); |
| 206 | + |
| 207 | + it("should split bytes when the array is %4 + 1 length", () => { |
| 208 | + expect(bg4_split_bytes(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9]))).toEqual( |
| 209 | + new Uint8Array([1, 5, 9, 2, 6, 3, 7, 4, 8]) |
| 210 | + ); |
| 211 | + }); |
| 212 | + |
| 213 | + it("should split bytes when the array is %4 + 2 length", () => { |
| 214 | + expect(bg4_split_bytes(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))).toEqual( |
| 215 | + new Uint8Array([1, 5, 9, 2, 6, 10, 3, 7, 4, 8]) |
| 216 | + ); |
| 217 | + }); |
| 218 | + |
| 219 | + it("should split bytes when the array is %4 + 3 length", () => { |
| 220 | + expect(bg4_split_bytes(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]))).toEqual( |
| 221 | + new Uint8Array([1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8]) |
| 222 | + ); |
| 223 | + }); |
| 224 | + |
| 225 | + it("should be the inverse of bg4_regroup_bytes", () => { |
| 226 | + const testArrays = [ |
| 227 | + new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]), |
| 228 | + new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9]), |
| 229 | + new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), |
| 230 | + new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]), |
| 231 | + new Uint8Array([42]), |
| 232 | + new Uint8Array([1, 2]), |
| 233 | + new Uint8Array([1, 2, 3]), |
| 234 | + ]; |
| 235 | + |
| 236 | + testArrays.forEach((arr) => { |
| 237 | + expect(bg4_regroup_bytes(bg4_split_bytes(arr))).toEqual(arr); |
| 238 | + }); |
| 239 | + }); |
| 240 | + }); |
| 241 | + |
200 | 242 | describe("when mocked", () => { |
201 | 243 | describe("loading many chunks every read", () => { |
202 | 244 | it("should load different slices", async () => { |
|
0 commit comments