mirror of
https://github.com/sexybiggetje/pixdisp.git
synced 2024-11-25 02:31:01 +01:00
Add silence option for Dummy driver. Add some more tests to increase coverage.
This commit is contained in:
parent
d1fc3bb2ef
commit
0434fb6b1a
3 changed files with 82 additions and 3 deletions
|
@ -89,3 +89,69 @@ test( 'Draw a circle', () => {
|
|||
expect( matrix[ 3 ][ 1 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
|
||||
} );
|
||||
|
||||
test( 'Draw a rectangle', () => {
|
||||
driver = driverFactory.createFromConfig( config );
|
||||
|
||||
driver.drawRect( 0, 0, 4, 4, 255, 255, 255, 1 );
|
||||
|
||||
let matrix = driver.getMatrix();
|
||||
|
||||
expect( matrix[ 0 ][ 0 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
expect( matrix[ 0 ][ 3 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
expect( matrix[ 3 ][ 3 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
expect( matrix[ 3 ][ 0 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
|
||||
expect( matrix[ 1 ][ 1 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
expect( matrix[ 1 ][ 2 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
expect( matrix[ 2 ][ 1 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
expect( matrix[ 2 ][ 2 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
|
||||
} );
|
||||
|
||||
test( 'Draw a filled rectangle', () => {
|
||||
driver = driverFactory.createFromConfig( config );
|
||||
|
||||
driver.drawRectFilled( 0, 0, 4, 4, 255, 255, 255, 1 );
|
||||
|
||||
let matrix = driver.getMatrix();
|
||||
|
||||
expect( matrix[ 0 ][ 0 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
expect( matrix[ 0 ][ 3 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
expect( matrix[ 3 ][ 3 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
expect( matrix[ 3 ][ 0 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
|
||||
expect( matrix[ 1 ][ 1 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
expect( matrix[ 1 ][ 2 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
expect( matrix[ 2 ][ 1 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
expect( matrix[ 2 ][ 2 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
|
||||
} );
|
||||
|
||||
test( 'Draw a line and clear the matrix', () => {
|
||||
driver = driverFactory.createFromConfig( config );
|
||||
|
||||
driver.drawLine( 0, 0, 3, 3, 255, 255, 255, 1 );
|
||||
|
||||
let matrix = driver.getMatrix();
|
||||
|
||||
expect( matrix[ 0 ][ 0 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
expect( matrix[ 1 ][ 1 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
expect( matrix[ 2 ][ 2 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
expect( matrix[ 3 ][ 3 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
|
||||
expect( matrix[ 0 ][ 1 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
expect( matrix[ 1 ][ 2 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
expect( matrix[ 2 ][ 3 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
expect( matrix[ 3 ][ 0 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
|
||||
driver.clear( 0, 0, 0, 1 );
|
||||
|
||||
matrix = driver.getMatrix();
|
||||
|
||||
expect( matrix[ 0 ][ 0 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
expect( matrix[ 1 ][ 1 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
expect( matrix[ 2 ][ 2 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
expect( matrix[ 3 ][ 3 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
|
||||
} );
|
|
@ -21,10 +21,19 @@ beforeEach(() => {
|
|||
});
|
||||
|
||||
test( 'Dummy driver to be properly created', () => {
|
||||
expect( driverFactory.createFromConfig( config ) ).toBeInstanceOf( Dummy );
|
||||
let driver = driverFactory.createFromConfig( config );
|
||||
|
||||
driver.silence = true;
|
||||
|
||||
expect( driver ).toBeInstanceOf( Dummy );
|
||||
expect( driver.write( driver.getBuffer() ) ).toBeUndefined();
|
||||
} );
|
||||
|
||||
test( 'Pimoroni Unicorn driver to be properly created', () => {
|
||||
config.driver = "pimoroniunicorn";
|
||||
expect( driverFactory.createFromConfig( config ) ).toBeInstanceOf( PimoroniUnicorn );
|
||||
|
||||
let driver = driverFactory.createFromConfig( config );
|
||||
|
||||
expect( driver ).toBeInstanceOf( PimoroniUnicorn );
|
||||
expect( driver.write( driver.getBuffer() ) ).toBeUndefined();
|
||||
} );
|
|
@ -5,11 +5,15 @@ let { Driver } = require( './driver' );
|
|||
class Dummy extends Driver {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.silence = false;
|
||||
}
|
||||
|
||||
write( buffer ) {
|
||||
if ( this.silence !== true ) {
|
||||
console.log( buffer );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.Dummy = Dummy;
|
Loading…
Reference in a new issue