package com.easternedgerobotics.rov.math;

import org.junit.Test;
import rx.observers.TestSubscriber;
import rx.schedulers.TestScheduler;
import rx.subjects.TestSubject;

@SuppressWarnings("checkstyle:MagicNumber")
public final class MovingAverageTest {
    @Test
    public final void averageCalculationDoesReturnTheCorrectResult() {
        final TestScheduler scheduler = new TestScheduler();
        final TestSubject<Float> numbers = TestSubject.create(scheduler);
        final TestSubscriber<Float> subscriber = new TestSubscriber<>();
        MovingAverage.from(numbers, 2).subscribe(subscriber);

        numbers.onNext(1f);
        scheduler.triggerActions();
        subscriber.assertValueCount(1);
        subscriber.assertValue(1f);

        numbers.onNext(9f);
        scheduler.triggerActions();
        subscriber.assertValueCount(2);
        subscriber.assertValues(1f, 5f);

        numbers.onNext(20f);
        scheduler.triggerActions();
        subscriber.assertValueCount(3);
        subscriber.assertValues(1f, 5f, 14.5f);

        numbers.onNext(40f);
        scheduler.triggerActions();
        subscriber.assertValueCount(4);
        subscriber.assertValues(1f, 5f, 14.5f, 30f);
    }
}

@@ -623,16 +623,18 @@
 onNext(1
+.5
 f);%0A    
@@ -737,16 +737,18 @@
 tValue(1
+.5
 f);%0A%0A   
@@ -771,9 +771,11 @@
 ext(
-9
+8.5
 f);%0A
@@ -883,19 +883,23 @@
 Values(1
+.5
 f, 
+8.
 5f);%0A%0A  
@@ -920,17 +920,19 @@
 onNext(2
-0
+1.5
 f);%0A    
@@ -1036,26 +1036,28 @@
 Values(1
+.5
 f, 
+8.
 5f, 1
-4.
 5f);%0A%0A  
@@ -1078,17 +1078,19 @@
 onNext(4
-0
+1.5
 f);%0A    

Update moving average tests to show floating point truncation