mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-08 21:30:57 +00:00
fixed Beaufort calculation and introduced MeterPerSecondSpeedImpl
This commit is contained in:
1 parent
ad7b12a0d3
commit
faf8c27a9a
4 files changed
+75
-7
No files matched your search
+6
-1
@@ -8,7 +8,7 @@ public abstract class AbstractSpeedImpl implements Speed {
|
||||
|
||||
@Override
|
||||
public double getBeaufort() {
|
||||
return Math.exp(Math.log(getKnots()*1.852/3.6 / 0.8360)*2/3);
|
||||
return Math.exp(Math.log(getMetersPerSecond()/0.8360) * 2./3.);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,4 +48,9 @@ public abstract class AbstractSpeedImpl implements Speed {
|
||||
}
|
||||
return getMetersPerSecond() == ((Speed) object).getMetersPerSecond();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getKnots() {
|
||||
return getKilometersPerHour() * 1000. / Mile.METERS_PER_NAUTICAL_MILE;
|
||||
}
|
||||
}
|
||||
-6
@@ -1,7 +1,6 @@
|
||||
package com.sap.sailing.domain.common.impl;
|
||||
|
||||
import com.sap.sailing.domain.common.AbstractSpeedImpl;
|
||||
import com.sap.sailing.domain.common.Mile;
|
||||
import com.sap.sailing.domain.common.Speed;
|
||||
|
||||
public class KilometersPerHourSpeedImpl extends AbstractSpeedImpl implements Speed {
|
||||
@@ -12,11 +11,6 @@ public class KilometersPerHourSpeedImpl extends AbstractSpeedImpl implements Spe
|
||||
this.speedInKilometersPerHour = speedInKilometersPerHour;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getKnots() {
|
||||
return getKilometersPerHour() * 1000. / Mile.METERS_PER_NAUTICAL_MILE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMetersPerSecond() {
|
||||
return getKilometersPerHour() / 3.6;
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.sap.sailing.domain.common.impl;
|
||||
|
||||
import com.sap.sailing.domain.common.AbstractSpeedImpl;
|
||||
import com.sap.sailing.domain.common.Speed;
|
||||
|
||||
public class MeterPerSecondSpeedImpl extends AbstractSpeedImpl implements Speed {
|
||||
private static final long serialVersionUID = -524654796500981303L;
|
||||
private final double metersPerSecond;
|
||||
|
||||
public MeterPerSecondSpeedImpl(double metersPerSecond) {
|
||||
this.metersPerSecond = metersPerSecond;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMetersPerSecond() {
|
||||
return metersPerSecond;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getKilometersPerHour() {
|
||||
return metersPerSecond/3.6;
|
||||
}
|
||||
}
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
package com.sap.sailing.domain.common.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sap.sailing.domain.common.Speed;
|
||||
import com.sap.sailing.domain.common.impl.MeterPerSecondSpeedImpl;
|
||||
|
||||
public class BeaufortTest {
|
||||
@Test
|
||||
public void testOneBeaufortLow() {
|
||||
Speed speed = new MeterPerSecondSpeedImpl(0.3);
|
||||
assertEquals(1, Math.round(speed.getBeaufort()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneBeaufortHigh() {
|
||||
Speed speed = new MeterPerSecondSpeedImpl(1.5);
|
||||
assertEquals(1, Math.round(speed.getBeaufort()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoBeaufortLow() {
|
||||
Speed speed = new MeterPerSecondSpeedImpl(1.6);
|
||||
assertEquals(2, Math.round(speed.getBeaufort()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoBeaufortHigh() {
|
||||
Speed speed = new MeterPerSecondSpeedImpl(3.3);
|
||||
assertEquals(2, Math.round(speed.getBeaufort()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTenBeaufortLow() {
|
||||
Speed speed = new MeterPerSecondSpeedImpl(24.5);
|
||||
assertEquals(10, Math.round(speed.getBeaufort()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTenBeaufortHigh() {
|
||||
Speed speed = new MeterPerSecondSpeedImpl(28.4);
|
||||
assertEquals(10, Math.round(speed.getBeaufort()));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user