IobTest
This commit is contained in:
parent
1b9b20cd41
commit
689fda5969
|
@ -7,6 +7,16 @@ public class Iob {
|
||||||
public double iobContrib = 0d;
|
public double iobContrib = 0d;
|
||||||
public double activityContrib = 0d;
|
public double activityContrib = 0d;
|
||||||
|
|
||||||
|
public Iob iobContrib(double iobContrib) {
|
||||||
|
this.iobContrib = iobContrib;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iob activityContrib(double activityContrib) {
|
||||||
|
this.activityContrib = activityContrib;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Iob plus(Iob iob) {
|
public Iob plus(Iob iob) {
|
||||||
iobContrib += iob.iobContrib;
|
iobContrib += iob.iobContrib;
|
||||||
activityContrib += iob.activityContrib;
|
activityContrib += iob.activityContrib;
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package info.nightscout.androidaps.data;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 27.03.2018.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
public class IobTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void plusTest() {
|
||||||
|
Iob a = new Iob().iobContrib(1).activityContrib(2);
|
||||||
|
Iob b = new Iob().iobContrib(3).activityContrib(4);
|
||||||
|
a.plus(b);
|
||||||
|
Assert.assertEquals(4d, a.iobContrib, 0.01d);
|
||||||
|
Assert.assertEquals(6d, a.activityContrib, 0.01d);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void equalTest() {
|
||||||
|
Iob a1 = new Iob().iobContrib(1).activityContrib(2);
|
||||||
|
Iob a2 = new Iob().iobContrib(1).activityContrib(2);
|
||||||
|
Iob b = new Iob().iobContrib(3).activityContrib(4);
|
||||||
|
|
||||||
|
Assert.assertEquals(true, a1.equals(a1));
|
||||||
|
Assert.assertEquals(true, a1.equals(a2));
|
||||||
|
Assert.assertEquals(false, a1.equals(b));
|
||||||
|
Assert.assertEquals(false, a1.equals(null));
|
||||||
|
Assert.assertEquals(false, a1.equals(new Object()));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void hashCodeTest() {
|
||||||
|
Iob a = new Iob().iobContrib(1).activityContrib(2);
|
||||||
|
Assert.assertNotEquals(0, a.hashCode());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue