mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
add unit test for getSimilarConnectedPixelsFromFrame
This commit is contained in:
parent
a4952d0db2
commit
b11f7a430d
47
test/js/utils/PixelUtilsTest_visit_connected.js
Normal file
47
test/js/utils/PixelUtilsTest_visit_connected.js
Normal 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);
|
||||
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user