made safe for empty wind tracks

This commit is contained in:
Axel Uhl committed 2011-06-21 13:15:58 +02:00
1 parent 337cf37bb8
commit 4468e905d6
2 files changed
+14 -3

No files matched your search

@@ -1,6 +1,7 @@
package com.sap.sailing.domain.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -19,6 +20,12 @@ import com.sap.sailing.domain.tracking.impl.WindTrackImpl;
public class WindTest {
private static final int AVERAGING_INTERVAL_MILLIS = 30000 /* 30s averaging interval */;
@Test
public void testEmptyTrackYieldsNullAsWindEstimate() {
WindTrack track = new WindTrackImpl(AVERAGING_INTERVAL_MILLIS);
assertNull(track.getEstimatedWind(new DegreePosition(0, 0), MillisecondsTimePoint.now()));
}
/**
* If the wind track has areas with no data, and wind information is requested for such an interval,
@@ -138,7 +138,7 @@ public class WindTrackImpl extends TrackImpl<Wind> implements WindTrack {
} else {
beforeWind = null;
}
} else {
} else if (afterWind != null) {
if (afterIntervalStart == null) {
afterIntervalStart = afterWind.getTimePoint();
}
@@ -154,8 +154,12 @@ public class WindTrackImpl extends TrackImpl<Wind> implements WindTrack {
}
}
} while (beforeIntervalLength + afterIntervalLength < millisecondsOverWhichToAverage && (beforeWind != null || afterWind != null));
SpeedWithBearing avgWindSpeed = new KnotSpeedWithBearingImpl(knotSum / count, new DegreeBearingImpl(bearingDegSum/count));
return new WindImpl(p, at, avgWindSpeed);
if (count == 0) {
return null;
} else {
SpeedWithBearing avgWindSpeed = new KnotSpeedWithBearingImpl(knotSum / count, new DegreeBearingImpl(bearingDegSum/count));
return new WindImpl(p, at, avgWindSpeed);
}
}
@Override