2018-03-19 18:21:02 +01:00
|
|
|
package info.nightscout.androidaps.interfaces;
|
2018-03-19 13:11:25 +01:00
|
|
|
|
|
|
|
import junit.framework.Assert;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
import org.powermock.modules.junit4.PowerMockRunner;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by mike on 19.03.2018.
|
|
|
|
*/
|
|
|
|
|
|
|
|
@RunWith(PowerMockRunner.class)
|
2018-03-19 17:38:48 +01:00
|
|
|
public class ConstraintTest {
|
2018-03-19 13:11:25 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void doTests() throws Exception {
|
2018-03-20 22:09:22 +01:00
|
|
|
Constraint<Boolean> b = new Constraint<>(true);
|
|
|
|
Assert.assertEquals(Boolean.TRUE, b.value());
|
|
|
|
Assert.assertEquals("", b.getReasons());
|
2018-03-23 17:36:49 +01:00
|
|
|
Assert.assertEquals("", b.getMostLimitedReasons());
|
2018-03-20 22:09:22 +01:00
|
|
|
b.set(false);
|
|
|
|
Assert.assertEquals(Boolean.FALSE, b.value());
|
|
|
|
Assert.assertEquals("", b.getReasons());
|
2018-03-23 17:36:49 +01:00
|
|
|
Assert.assertEquals("", b.getMostLimitedReasons());
|
2018-03-21 22:06:28 +01:00
|
|
|
b.set(true, "Set true", this);
|
2018-03-20 22:09:22 +01:00
|
|
|
Assert.assertEquals(Boolean.TRUE, b.value());
|
2018-03-21 22:06:28 +01:00
|
|
|
Assert.assertEquals("ConstraintTest: Set true", b.getReasons());
|
2018-03-23 17:36:49 +01:00
|
|
|
Assert.assertEquals("ConstraintTest: Set true", b.getMostLimitedReasons());
|
2018-03-21 22:06:28 +01:00
|
|
|
b.set(false, "Set false", this);
|
2018-03-20 22:09:22 +01:00
|
|
|
Assert.assertEquals(Boolean.FALSE, b.value());
|
2018-03-21 22:06:28 +01:00
|
|
|
Assert.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getReasons());
|
2018-03-23 17:36:49 +01:00
|
|
|
Assert.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getMostLimitedReasons());
|
2018-03-19 13:11:25 +01:00
|
|
|
|
2018-03-20 22:09:22 +01:00
|
|
|
Constraint<Double> d = new Constraint<>(10d);
|
2018-03-21 22:06:28 +01:00
|
|
|
d.set(5d, "Set 5d", this);
|
2018-03-20 23:47:37 +01:00
|
|
|
Assert.assertEquals(5d, d.value());
|
2018-03-21 22:06:28 +01:00
|
|
|
Assert.assertEquals("ConstraintTest: Set 5d", d.getReasons());
|
2018-03-23 17:36:49 +01:00
|
|
|
Assert.assertEquals("ConstraintTest: Set 5d", d.getMostLimitedReasons());
|
2018-03-21 22:06:28 +01:00
|
|
|
d.setIfSmaller(6d, "Set 6d", this);
|
2018-03-20 23:47:37 +01:00
|
|
|
Assert.assertEquals(5d, d.value());
|
2018-03-21 22:06:28 +01:00
|
|
|
Assert.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d", d.getReasons());
|
2018-03-23 17:36:49 +01:00
|
|
|
Assert.assertEquals("ConstraintTest: Set 5d", d.getMostLimitedReasons());
|
2018-03-21 22:06:28 +01:00
|
|
|
d.setIfSmaller(4d, "Set 4d", this);
|
2018-03-20 23:47:37 +01:00
|
|
|
Assert.assertEquals(4d, d.value());
|
2018-03-21 22:06:28 +01:00
|
|
|
Assert.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d", d.getReasons());
|
2018-03-23 17:36:49 +01:00
|
|
|
Assert.assertEquals("ConstraintTest: Set 4d", d.getMostLimitedReasons());
|
2018-03-21 20:24:02 +01:00
|
|
|
Assert.assertEquals(10d, d.originalValue());
|
2018-03-19 13:11:25 +01:00
|
|
|
}
|
|
|
|
}
|