mirror of
https://github.com/sexybiggetje/pixdisp.git
synced 2024-11-21 17:21:01 +01:00
Update README with test info, add drowingoperations tests, add getMatrix function to driver for tests.
This commit is contained in:
parent
7f106f4a3f
commit
f2c885ac8c
4 changed files with 109 additions and 3 deletions
|
@ -19,6 +19,13 @@ Navigate to http://localhost:8080/
|
|||
|
||||
Matrix driver & Unicorn Hat HD driver inspired by https://github.com/vesteraas/node-unicornhathd
|
||||
|
||||
### Unit tests
|
||||
This application has some unit tests, making use of [Jest](http://facebook.github.io/jest/). Jest is configured as a dev dependency.
|
||||
|
||||
execute:
|
||||
|
||||
npm test
|
||||
|
||||
### Drawing
|
||||
![Device drawing](https://raw.githubusercontent.com/sexybiggetje/pixdisp/screenshots/device.jpg "Drawing on the device")
|
||||
|
||||
|
|
91
__tests__/drawingoperations.js
Normal file
91
__tests__/drawingoperations.js
Normal file
|
@ -0,0 +1,91 @@
|
|||
'use strict';
|
||||
|
||||
let driver, config;
|
||||
|
||||
let { DriverFactory } = require( '../drivers/driverfactory' );
|
||||
let { Dummy } = require( '../drivers/dummy' );
|
||||
|
||||
let driverFactory = new DriverFactory();
|
||||
|
||||
beforeEach(() => {
|
||||
config = {
|
||||
"driver": "dummy",
|
||||
"matrix": {
|
||||
"width": 4,
|
||||
"height": 4,
|
||||
"brightness": 1,
|
||||
"flipHorizontal": false,
|
||||
"flipVertical": false
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
test( 'Matrix creation', () => {
|
||||
driver = driverFactory.createFromConfig( config );
|
||||
|
||||
expect( driver.getSize() ).toEqual( { width: 4, height: 4 } );
|
||||
expect( driver.getBuffer().length ).toEqual( 48 );
|
||||
} );
|
||||
|
||||
test( 'Set a pixel', () => {
|
||||
driver = driverFactory.createFromConfig( config );
|
||||
|
||||
driver.setPixel( 0, 0, 255, 255, 255, 1 );
|
||||
driver.setPixel( 3, 0, 255, 255, 255, 1 );
|
||||
driver.setPixel( 0, 3, 255, 255, 255, 1 );
|
||||
driver.setPixel( 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[ 3 ][ 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[ 0 ][ 1 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
expect( matrix[ 3 ][ 1 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
expect( matrix[ 1 ][ 3 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
expect( matrix[ 2 ][ 3 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
|
||||
} );
|
||||
|
||||
test( 'Draw a line', () => {
|
||||
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} );
|
||||
|
||||
} );
|
||||
|
||||
test( 'Draw a circle', () => {
|
||||
config.matrix.width = 8;
|
||||
config.matrix.height = 8;
|
||||
|
||||
driver = driverFactory.createFromConfig( config );
|
||||
|
||||
driver.drawCircle( 3, 3, 4, 255, 255, 255, 1 );
|
||||
|
||||
let matrix = driver.getMatrix();
|
||||
|
||||
expect( matrix[ 1 ][ 0 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
expect( matrix[ 2 ][ 0 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
expect( matrix[ 2 ][ 6 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
expect( matrix[ 3 ][ 6 ] ).toEqual( { r: 255, g: 255, b: 255, a: 1} );
|
||||
|
||||
expect( matrix[ 0 ][ 0 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
expect( matrix[ 0 ][ 7 ] ).toEqual( { r: 0, g: 0, b: 0, a: 1} );
|
||||
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} );
|
||||
|
||||
} );
|
|
@ -64,8 +64,8 @@ class Driver {
|
|||
* Set pixel color
|
||||
*/
|
||||
setPixel( x, y, r = 0, g = 0, b = 0, a = 1 ) {
|
||||
if ( x >= 0 && x <= this.width &&
|
||||
y >= 0 && y <= this.height ) {
|
||||
if ( x >= 0 && x < this.width &&
|
||||
y >= 0 && y < this.height ) {
|
||||
this.matrix[x][y].r = r;
|
||||
this.matrix[x][y].g = g;
|
||||
this.matrix[x][y].b = b;
|
||||
|
@ -169,6 +169,13 @@ class Driver {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current matrix at any given state
|
||||
*/
|
||||
getMatrix() {
|
||||
return this.matrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the buffer for writing
|
||||
* @return {Buffer}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
},
|
||||
"jest": {
|
||||
"name": "pixdisp",
|
||||
"testRegex": "(/__tests__/.[^_]*|(\\.|/)(test|spec))\\.jsx?$"
|
||||
"testRegex": "(/__tests__/.[^_]*|(\\.|/)(test|spec))\\.jsx?$",
|
||||
"verbose": true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue