### Question:
LowPassFilter implements Filter { public double filterValue(double nextRawValue) { double calibratedValue; calibratedValue = Double.isNaN(nextRawValue) ? currentValue : calibrateValue(nextRawValue); currentValue = calibratedValue; return calibratedValue; } LowPassFilter(double weight); double filterValue(double nextRawValue);  }### Answer:
@Test @DisplayName("should return positive values") void positiveFilterValue() { final double updatedValue = 10; filter.filterValue(updatedValue); double value = filter.filterValue(updatedValue); assertEquals(1.9, value); }
@Test @DisplayName("should return negative values") void negativeFilterValue() { filter.filterValue(100); double value = filter.filterValue(1); assertEquals(9.1, value); }
@Test @DisplayName("should return values with a set error span") void valueTesting() { for (int i = 0; i < 100; i++) { filter.filterValue(0.3); } filter.filterValue(0.7); for (int i = 0; i < 4; i++) { filter.filterValue(0.3); } double value = filter.filterValue(0.3); assertEquals(0.3,value,0.05); }
@Test @DisplayName("should handle noise spikes") void extremeValueTesting() { for (int i = 0; i < 100; i++) { filter.filterValue(0.3); } filter.filterValue(0.7); double value = filter.filterValue(0.3); assertEquals(0.3,value,0.05); }
@Test @DisplayName("should balance incoming stream of noise") void noiseControl() { double[] arr = {0.3, 0.35, 0.32, 0.28, 0.77, 0.3, 0.28, 0.34, 0.7}; double temp = 0; for (double v : arr) { temp = filter.filterValue(v); } assertEquals(0.3, temp, 0.05); }
@Test @DisplayName("should handle NaN values without fail") void errorProneSensorValue() { double arr[] = { NaN, 0.3, 0.56, 0.34, 0.78, 0.28, NaN, 0.35, NaN }; double value = filter.filterValue(0.37); for (double reading : arr) { value = filter.filterValue(reading); } assertThat(value, not(NaN)); }