diff options
author | Martin Ashby <martin@martin-laptop.lan> | 2018-05-17 18:18:11 +0100 |
---|---|---|
committer | Martin Ashby <martin@martin-laptop.lan> | 2018-05-17 18:18:11 +0100 |
commit | d40c7d9f09d9b012837d6060a4c598b23b19646f (patch) | |
tree | 8fa1f99664b3b6a74f7a0fd5856b7d0c41767b1f /src/Utils.test.js | |
parent | aa86cb02fd95404fdfba8cf9d13cb5c18138b6b5 (diff) | |
download | unicornpaint-d40c7d9f09d9b012837d6060a4c598b23b19646f.tar.gz unicornpaint-d40c7d9f09d9b012837d6060a4c598b23b19646f.tar.bz2 unicornpaint-d40c7d9f09d9b012837d6060a4c598b23b19646f.tar.xz unicornpaint-d40c7d9f09d9b012837d6060a4c598b23b19646f.zip |
Palette, tools, load & save working
Diffstat (limited to 'src/Utils.test.js')
-rw-r--r-- | src/Utils.test.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/Utils.test.js b/src/Utils.test.js new file mode 100644 index 0000000..6c9161b --- /dev/null +++ b/src/Utils.test.js @@ -0,0 +1,81 @@ +import { colorEqual, coordsEqual, xy, rgb, findContiguousPixels } from './Utils' + +test('test colorEqual function', () => { + expect(colorEqual([0, 0, 0], [0, 0, 0])) + .toBe(true) + expect(colorEqual([1, 0, 0], [0, 0, 0])) + .toBe(false) + expect(colorEqual([0, 1, 0], [0, 0, 0])) + .toBe(false) + expect(colorEqual([0, 0, 1], [0, 0, 0])) + .toBe(false) + + expect(colorEqual([0, 0, 1], {r: 0, g: 0, b: 1})) + .toBe(true) + expect(colorEqual({r: 0, g: 0, b: 1}, [0, 0, 1])) + .toBe(true) + + expect(colorEqual({r: 0, g: 0, b: 0}, [0, 0, 1])) + .toBe(false) + expect(colorEqual([0, 0, 1], {r: 0, g: 0, b: 0})) + .toBe(false) + + expect(colorEqual(undefined, {r: 0, g: 0, b: 0})) + .toBe(false) + expect(colorEqual({r: 0, g: 0, b: 0}, undefined)) + .toBe(false) +}) + +test('coordEqual function', () => { + expect(coordsEqual([0, 0], [0, 0])) + .toBe(true) + expect(coordsEqual([0, 1], [0, 0])) + .toBe(false) + expect(coordsEqual([1, 0], [0, 0])) + .toBe(false) + + expect(coordsEqual([1, 0], [0, 0])) + .toBe(false) + + expect(coordsEqual(undefined, [0, 0])) + .toBe(false) + expect(coordsEqual([0, 0], undefined)) + .toBe(false) +}) + +test('contiguousPixels', () => { + let allBlack = [ + [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]], + [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]], + [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]], + [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] + ] + + let contiguousPx = findContiguousPixels(0, 0, allBlack) + expect(contiguousPx.length) + .toBe(16) + + expect(findContiguousPixels(0, 0, [ + [[0, 0, 0], [0, 0, 1], [0, 0, 0], [0, 0, 0]], + [[0, 0, 1], [0, 0, 1], [0, 0, 0], [0, 0, 0]], + [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]], + [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] + ]).length) + .toBe(1) + + expect(findContiguousPixels(1, 1, [ + [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]], + [[0, 0, 0], [0, 0, 1], [0, 0, 1], [0, 0, 0]], + [[0, 0, 0], [0, 0, 1], [0, 0, 1], [0, 0, 0]], + [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] + ]).length) + .toBe(4) + + expect(findContiguousPixels(1, 1, [ + [[0, 0, 1], [0, 0, 1], [0, 0, 1], [0, 0, 1]], + [[0, 0, 1], [0, 0, 0], [0, 0, 0], [0, 0, 1]], + [[0, 0, 1], [0, 0, 0], [0, 0, 0], [0, 0, 1]], + [[0, 0, 1], [0, 0, 1], [0, 0, 1], [0, 0, 1]] + ]).length) + .toBe(4) +})
\ No newline at end of file |