add unit test for getSimilarConnectedPixelsFromFrame

This commit is contained in:
juliandescottes 2017-01-14 00:56:24 +01:00
parent a4952d0db2
commit b11f7a430d

View File

@ -0,0 +1,47 @@
describe("PixelUtils visitor methods tests", function() {
var black = '#000000';
var red = '#ff0000';
var transparent = Constants.TRANSPARENT_COLOR;
var B = black, R = red, T = transparent;
beforeEach(function() {});
afterEach(function() {});
var containsPixel = function (pixels, col, row) {
return pixels.some(function (p) {
return p.col === col && p.row === row;
});
};
it("getSimilarConnectedPixelsFromFrame works", function() {
// single point
var frame = pskl.model.Frame.fromPixelGrid(test.testutils.toFrameGrid([
[T, T, B],
[B, T, B],
[T, T, B],
]));
var pixels = pskl.PixelUtils.getSimilarConnectedPixelsFromFrame(frame, 0, 0);
expect(pixels.length).toBe(5);
expect(containsPixel(pixels, 0, 0)).toBe(true);
expect(containsPixel(pixels, 1, 0)).toBe(true);
expect(containsPixel(pixels, 1, 1)).toBe(true);
expect(containsPixel(pixels, 0, 2)).toBe(true);
expect(containsPixel(pixels, 1, 2)).toBe(true);
pixels = pskl.PixelUtils.getSimilarConnectedPixelsFromFrame(frame, -1, -1);
expect(Array.isArray(pixels)).toBe(true);
expect(pixels.length).toBe(0);
pixels = pskl.PixelUtils.getSimilarConnectedPixelsFromFrame(frame, 0, 1);
expect(pixels.length).toBe(1);
expect(containsPixel(pixels, 0, 1)).toBe(true);
pixels = pskl.PixelUtils.getSimilarConnectedPixelsFromFrame(frame, 2, 1);
expect(pixels.length).toBe(3);
expect(containsPixel(pixels, 2, 0)).toBe(true);
expect(containsPixel(pixels, 2, 1)).toBe(true);
expect(containsPixel(pixels, 2, 2)).toBe(true);
});
});