2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.automation.pidcontroller.internal;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
21 * Test for LowpassFilter.
23 * @author Fabian Wolter - Initial contribution
27 class LowpassFilterTest {
29 void test0to1after1tau() {
30 double output = LowpassFilter.calculate(0, 1, 1);
31 assertEquals(0.63, output, 0.01);
35 void test0to1after2tau() {
36 double output = LowpassFilter.calculate(0, 1, 1);
37 output = LowpassFilter.calculate(output, 1, 1);
38 assertEquals(0.86, output, 0.01);
42 void test0to1after5tau() {
43 double output = LowpassFilter.calculate(0, 1, 1);
44 output = LowpassFilter.calculate(output, 1, 1);
45 output = LowpassFilter.calculate(output, 1, 1);
46 output = LowpassFilter.calculate(output, 1, 1);
47 output = LowpassFilter.calculate(output, 1, 1);
48 assertEquals(0.99, output, 0.01);
52 void test0to1after1tau2timeConstant() {
53 double output = LowpassFilter.calculate(0, 1, 2);
54 assertEquals(0.86, output, 0.01);
58 void test0to1after0_1tau() {
59 double output = LowpassFilter.calculate(0, 1, 0.1);
60 assertEquals(0.095162582, output, 0.000000001);
64 void test1to0after1tau() {
65 double output = LowpassFilter.calculate(1, 0, 1);
66 assertEquals(0.36, output, 0.01);