Add test for LowPassFilter
Summary: Eating my own dogfood. Reviewed By: mweststrate Differential Revision: D21545655 fbshipit-source-id: 1e2690478ad8a986915a98a8275a168fa4c3a23f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
dcaff4babc
commit
5fe3e9a44a
46
desktop/app/src/utils/__tests__/LowPassFilter.node.tsx
Normal file
46
desktop/app/src/utils/__tests__/LowPassFilter.node.tsx
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*
|
||||||
|
* @format
|
||||||
|
*/
|
||||||
|
|
||||||
|
import LowPassFilter from '../LowPassFilter';
|
||||||
|
|
||||||
|
test('hasFullBuffer', () => {
|
||||||
|
const lpf = new LowPassFilter();
|
||||||
|
expect(lpf.hasFullBuffer()).toBeFalsy();
|
||||||
|
|
||||||
|
lpf.push(1);
|
||||||
|
lpf.push(2);
|
||||||
|
lpf.push(3);
|
||||||
|
lpf.push(4);
|
||||||
|
lpf.push(5);
|
||||||
|
|
||||||
|
expect(lpf.hasFullBuffer()).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('push on full buffer returns shifted value', () => {
|
||||||
|
const lpf = new LowPassFilter();
|
||||||
|
expect(lpf.push(1)).toBe(0);
|
||||||
|
expect(lpf.push(2)).toBe(0);
|
||||||
|
expect(lpf.push(3)).toBe(0);
|
||||||
|
expect(lpf.push(4)).toBe(0);
|
||||||
|
expect(lpf.push(5)).toBe(0);
|
||||||
|
expect(lpf.push(6)).toBe(1);
|
||||||
|
expect(lpf.push(7)).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('next returns smoothed value', () => {
|
||||||
|
const lpf = new LowPassFilter();
|
||||||
|
expect(lpf.next(1)).toBe(0.9);
|
||||||
|
expect(lpf.next(2)).toBe(1.881);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('next returns smoothed value with custom smoothing', () => {
|
||||||
|
const lpf = new LowPassFilter(0.5);
|
||||||
|
expect(lpf.next(1)).toBe(0.5);
|
||||||
|
expect(lpf.next(2)).toBe(1.125);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user