AndroidAPS/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintTest.java

43 lines
1.4 KiB
Java
Raw Normal View History

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());
b.set(false);
Assert.assertEquals(Boolean.FALSE, b.value());
Assert.assertEquals("", b.getReasons());
b.set(true, "Set true");
Assert.assertEquals(Boolean.TRUE, b.value());
Assert.assertEquals("Set true", b.getReasons());
b.set(false, "Set false");
Assert.assertEquals(Boolean.FALSE, b.value());
Assert.assertEquals("Set true\nSet false", b.getReasons());
2018-03-19 13:11:25 +01:00
2018-03-20 22:09:22 +01:00
Constraint<Double> d = new Constraint<>(10d);
d.set(5d, "Set 5d");
Assert.assertEquals(5d, b.value());
Assert.assertEquals("Set 5d", b.getReasons());
d.setIfSmaller(6d, "Set 6d");
Assert.assertEquals(5d, b.value());
Assert.assertEquals("Set 5d", b.getReasons());
d.setIfSmaller(4d, "Set 4d");
Assert.assertEquals(4d, b.value());
Assert.assertEquals("Set 5d\nSet 4d", b.getReasons());
2018-03-19 13:11:25 +01:00
}
}