Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iwoplaza committed Jun 30, 2024
1 parent 2f8cc7f commit 58e9f29
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/io/bufferReaderWriter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,49 @@ describe('BufferWriter/BufferReader', () => {
expect(reader.readFloat32()).to.be.closeTo(floatList[i], 0.001);
}
});

it('should encode a Uint8Array', () => {
const uint8s = new Uint8Array([0, 1, 1, 2, 3, 5, 8, 255]);

const buffer = Buffer.alloc(8);
const writer = new BufferWriter(buffer);
writer.writeSlice(uint8s);

const reader = new BufferReader(buffer);
expect(reader.readByte()).to.eq(0);
expect(reader.readByte()).to.eq(1);
expect(reader.readByte()).to.eq(1);
expect(reader.readByte()).to.eq(2);
expect(reader.readByte()).to.eq(3);
expect(reader.readByte()).to.eq(5);
expect(reader.readByte()).to.eq(8);
expect(reader.readByte()).to.eq(255);
});

it('should encode a Uint32Array', () => {
const uint32s = new Uint32Array([
0,
1,
1,
2,
3,
5,
8,
Number.MAX_SAFE_INTEGER,
]);

const buffer = Buffer.alloc(8 * 4);
const writer = new BufferWriter(buffer);
writer.writeSlice(uint32s);

const reader = new BufferReader(buffer);
expect(reader.readUint32()).to.eq(0);

Check failure on line 98 in src/io/bufferReaderWriter.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 16.x)

src/io/bufferReaderWriter.test.ts > BufferWriter/BufferReader > should encode a Uint32Array

AssertionError: expected 33620224 to equal +0 - Expected + Received - 0 + 33620224 ❯ src/io/bufferReaderWriter.test.ts:98:36

Check failure on line 98 in src/io/bufferReaderWriter.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20.x)

src/io/bufferReaderWriter.test.ts > BufferWriter/BufferReader > should encode a Uint32Array

AssertionError: expected 33620224 to equal +0 - Expected + Received - 0 + 33620224 ❯ src/io/bufferReaderWriter.test.ts:98:36
expect(reader.readUint32()).to.eq(1);
expect(reader.readUint32()).to.eq(1);
expect(reader.readUint32()).to.eq(2);
expect(reader.readUint32()).to.eq(3);
expect(reader.readUint32()).to.eq(5);
expect(reader.readUint32()).to.eq(8);
expect(reader.readUint32()).to.eq(Number.MAX_SAFE_INTEGER);
});
});

0 comments on commit 58e9f29

Please sign in to comment.