mirror of
https://github.com/hanzoai/sharp.git
synced 2026-10-30 19:37:10 +00:00
- Ensure all tests have an expected assertion count - Ensure all tests have at least one assertion - Use async/await unless test is callback-specific
59 lines
1.2 KiB
JavaScript
59 lines
1.2 KiB
JavaScript
/*!
|
|
Copyright 2013 Lovell Fuller and others.
|
|
SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
const { suite, test } = require('node:test');
|
|
|
|
const sharp = require('../../');
|
|
|
|
const row = [0, 3, 15, 63, 127, 255];
|
|
const input = Buffer.from(Array.from(row, () => row).flat());
|
|
const raw = {
|
|
width: 6,
|
|
height: 6,
|
|
channels: 1
|
|
};
|
|
|
|
suite('Median filter', () => {
|
|
test('default window (3x3)', async (t) => {
|
|
t.plan(1);
|
|
const data = await sharp(input, { raw })
|
|
.median()
|
|
.toColourspace('b-w')
|
|
.raw()
|
|
.toBuffer();
|
|
|
|
t.assert.deepStrictEqual(data.subarray(0, 6), Buffer.from(row));
|
|
});
|
|
|
|
test('3x3 window', async (t) => {
|
|
t.plan(1);
|
|
const data = await sharp(input, { raw })
|
|
.median(3)
|
|
.toColourspace('b-w')
|
|
.raw()
|
|
.toBuffer();
|
|
|
|
t.assert.deepStrictEqual(data.subarray(0, 6), Buffer.from(row));
|
|
});
|
|
|
|
test('5x5 window', async (t) => {
|
|
t.plan(1);
|
|
const data = await sharp(input, { raw })
|
|
.median(5)
|
|
.toColourspace('b-w')
|
|
.raw()
|
|
.toBuffer();
|
|
|
|
t.assert.deepStrictEqual(data.subarray(0, 6), Buffer.from(row));
|
|
});
|
|
|
|
test('invalid radius', (t) => {
|
|
t.plan(1);
|
|
t.assert.throws(() => {
|
|
sharp().median(0.1);
|
|
});
|
|
});
|
|
});
|