Skip to content

Commit

Permalink
Add unit tests for Tight gradient filter
Browse files Browse the repository at this point in the history
  • Loading branch information
CendioOssman committed May 16, 2024
1 parent c187b2e commit d80e3bf
Showing 1 changed file with 70 additions and 4 deletions.
74 changes: 70 additions & 4 deletions tests/test.tight.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,59 @@ describe('Tight Decoder', function () {
expect(display).to.have.displayed(targetData);
});

it.skip('should handle uncompressed gradient rects', function () {
// Not implemented yet
it('should handle uncompressed gradient rects', function () {
let done;
let blueData = [ 0x40, 0x02, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00 ];
let greenData = [ 0x40, 0x02, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 ];

done = testDecodeRect(decoder, 0, 0, 2, 1, blueData, display, 24);
expect(done).to.be.true;
done = testDecodeRect(decoder, 0, 1, 2, 1, blueData, display, 24);
expect(done).to.be.true;
done = testDecodeRect(decoder, 2, 0, 2, 1, greenData, display, 24);
expect(done).to.be.true;
done = testDecodeRect(decoder, 2, 1, 2, 1, greenData, display, 24);
expect(done).to.be.true;
done = testDecodeRect(decoder, 0, 2, 2, 1, greenData, display, 24);
expect(done).to.be.true;
done = testDecodeRect(decoder, 0, 3, 2, 1, greenData, display, 24);
expect(done).to.be.true;
done = testDecodeRect(decoder, 2, 2, 2, 1, blueData, display, 24);
expect(done).to.be.true;
done = testDecodeRect(decoder, 2, 3, 2, 1, blueData, display, 24);
expect(done).to.be.true;

let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
]);

expect(display).to.have.displayed(targetData);
});

it.skip('should handle compressed gradient rects', function () {
// Not implemented yet
it('should handle compressed gradient rects', function () {
let data = [
// Control byte
0x40, 0x02,
// Pixels (compressed)
0x18,
0x78, 0x9c, 0x62, 0x60, 0xf8, 0xcf, 0x00, 0x04,
0xff, 0x19, 0x19, 0xd0, 0x00, 0x44, 0x84, 0xf1,
0x3f, 0x9a, 0x30, 0x00, 0x00, 0x00, 0xff, 0xff ];

let done = testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24);

let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
]);

expect(done).to.be.true;
expect(display).to.have.displayed(targetData);
});

it('should handle empty copy rects', function () {
Expand Down Expand Up @@ -275,6 +322,25 @@ describe('Tight Decoder', function () {
expect(display).to.have.displayed(targetData);
});

it('should handle empty gradient rects', function () {
display.fillRect(0, 0, 4, 4, [ 0x00, 0x00, 0xff ]);
display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]);
display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]);

let done = testDecodeRect(decoder, 1, 2, 0, 0,
[ 0x40, 0x02 ], display, 24);

let targetData = new Uint8Array([
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
]);

expect(done).to.be.true;
expect(display).to.have.displayed(targetData);
});

it('should handle empty fill rects', function () {
display.fillRect(0, 0, 4, 4, [ 0x00, 0x00, 0xff ]);
display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]);
Expand Down

0 comments on commit d80e3bf

Please sign in to comment.