From 10e7ce5764b3b456e1f909cd6b6a90f076c2e014 Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Thu, 17 May 2018 20:17:01 +0100 Subject: Fixed rotation problem. Added rotate function. Added docker file --- src/Utils.test.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src/Utils.test.js') diff --git a/src/Utils.test.js b/src/Utils.test.js index 6c9161b..33d63f0 100644 --- a/src/Utils.test.js +++ b/src/Utils.test.js @@ -1,4 +1,4 @@ -import { colorEqual, coordsEqual, xy, rgb, findContiguousPixels } from './Utils' +import { colorEqual, coordsEqual, xy, rgb, findContiguousPixels, rotatePixelsClock, rotatePixelsCounterClock } from './Utils' test('test colorEqual function', () => { expect(colorEqual([0, 0, 0], [0, 0, 0])) @@ -78,4 +78,38 @@ test('contiguousPixels', () => { [[0, 0, 1], [0, 0, 1], [0, 0, 1], [0, 0, 1]] ]).length) .toBe(4) +}) + +test('rotate clockwise function', () => { + let rot1 = rotatePixelsClock([ + [[0, 0, 1], [0, 0, 0], [0, 0, 0], [0, 0, 2]], + [[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, 4], [0, 0, 0], [0, 0, 0], [0, 0, 3]] + ]) + expect(rot1[0][3][2]) + .toBe(1) + expect(rot1[3][3][2]) + .toBe(2) + expect(rot1[3][0][2]) + .toBe(3) + expect(rot1[0][0][2]) + .toBe(4) +}) + +test('rotate counter-clockwise function', () => { + let rot1 = rotatePixelsCounterClock([ + [[0, 0, 1], [0, 0, 0], [0, 0, 0], [0, 0, 2]], + [[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, 4], [0, 0, 0], [0, 0, 0], [0, 0, 3]] + ]) + expect(rot1[0][3][2]) + .toBe(3) + expect(rot1[3][3][2]) + .toBe(4) + expect(rot1[3][0][2]) + .toBe(1) + expect(rot1[0][0][2]) + .toBe(2) }) \ No newline at end of file -- cgit v1.2.3-ZIG