diff --git a/__tests__/drawingoperations.js b/__tests__/drawingoperations.js index 94f24d8..a119765 100644 --- a/__tests__/drawingoperations.js +++ b/__tests__/drawingoperations.js @@ -88,4 +88,70 @@ test( 'Draw a circle', () => { expect( matrix[ 2 ][ 1 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} ); 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} ); + } ); \ No newline at end of file diff --git a/__tests__/driverfactory.js b/__tests__/driverfactory.js index 1a9b607..22e0aa8 100644 --- a/__tests__/driverfactory.js +++ b/__tests__/driverfactory.js @@ -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(); } ); \ No newline at end of file diff --git a/drivers/dummy.js b/drivers/dummy.js index f633df6..ae3e3aa 100644 --- a/drivers/dummy.js +++ b/drivers/dummy.js @@ -5,10 +5,14 @@ let { Driver } = require( './driver' ); class Dummy extends Driver { constructor() { super(); + + this.silence = false; } write( buffer ) { - console.log( buffer ); + if ( this.silence !== true ) { + console.log( buffer ); + } } }