added regression test for bug fixed by 20a3aa6c2d

This commit is contained in:
Axel Uhl committed 2011-06-10 21:46:59 +02:00
1 parent a1daeaedf4
commit 989fa4258c
2 files changed
+35 -2

No files matched your search

@@ -2,8 +2,12 @@ package com.sap.sailing.domain.test;
import static org.junit.Assert.assertEquals;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.junit.Test;
import com.sap.sailing.domain.base.TimePoint;
import com.sap.sailing.domain.base.impl.DegreeBearingImpl;
import com.sap.sailing.domain.base.impl.DegreePosition;
import com.sap.sailing.domain.base.impl.KnotSpeedWithBearingImpl;
@@ -77,4 +81,35 @@ public class WindTest {
assertEquals(10, estimate.getKnots(), 0.000000001);
assertEquals(105, estimate.getBearing().getDegrees(), 0.00000001);
}
@Test
public void testUsingNewerThanRequestedIfCloserThanOlder() throws ParseException {
/*
Imagine the following wind measurements:
2009-07-11T13:45:00.000+0200@null: 10.0kn from 278.0� avg(30000ms): 2009-07-11T13:45:00.000+0200@null: 10.0kn from 278.0�
2009-07-11T13:45:05.000+0200@null: 10.0kn from 265.0� avg(30000ms): 2009-07-11T13:45:05.000+0200@null: 10.0kn from 269.0�
2009-07-12T17:31:40.000+0200@null: 10.0kn from 260.0� avg(30000ms): 2009-07-12T17:31:40.000+0200@null: 10.0kn from 260.0�
Now assume a query for 2009-07-12T17:30:00 which is closest to the newest entry but (much) more than
the averaging interval after the previous entry (2009-07-11T13:45:05.000). This test ensures that
the WindTrack uses the newer entry even though it's after the time point requested because it's
much closer, and the previous entry would be out of the averaging interval anyway.
*/
SimpleDateFormat df = new SimpleDateFormat("yyyy-DD-mm'T'hh:mm:ss");
Wind wind1 = new WindImpl(null, new MillisecondsTimePoint(df.parse("2009-07-11T13:45:00").getTime()),
new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(98)));
Wind wind2 = new WindImpl(null, new MillisecondsTimePoint(df.parse("2009-07-11T13:45:05").getTime()),
new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(85)));
Wind wind3 = new WindImpl(null, new MillisecondsTimePoint(df.parse("2009-07-11T17:31:40").getTime()),
new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(80)));
WindTrack track = new WindTrackImpl(/* millisecondsOverWhichToAverage */ 30000);
track.add(wind1);
track.add(wind2);
track.add(wind3);
TimePoint timePoint = new MillisecondsTimePoint(df.parse("2009-07-11T17:31:38").getTime());
Wind result = track.getEstimatedWind(null, timePoint);
assertEquals(wind3.getKnots(), result.getKnots(), 0.000000001);
assertEquals(wind3.getBearing().getDegrees(), result.getBearing().getDegrees(), 0.0000000001);
}
}