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;
|
|
|
|
|
2019-03-21 21:29:09 +01:00
|
|
|
import org.junit.Before;
|
2018-03-19 13:11:25 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.runner.RunWith;
|
2018-07-30 20:23:48 +02:00
|
|
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
2018-03-19 13:11:25 +01:00
|
|
|
import org.powermock.modules.junit4.PowerMockRunner;
|
|
|
|
|
2018-07-30 20:23:48 +02:00
|
|
|
import info.AAPSMocker;
|
|
|
|
import info.nightscout.androidaps.MainApp;
|
2019-03-21 21:29:09 +01:00
|
|
|
import info.nightscout.androidaps.logging.L;
|
2019-02-26 20:38:27 +01:00
|
|
|
import info.nightscout.androidaps.utils.SP;
|
2018-07-30 20:23:48 +02:00
|
|
|
|
2018-03-19 13:11:25 +01:00
|
|
|
/**
|
|
|
|
* Created by mike on 19.03.2018.
|
|
|
|
*/
|
|
|
|
|
|
|
|
@RunWith(PowerMockRunner.class)
|
2019-03-21 21:29:09 +01:00
|
|
|
@PrepareForTest({MainApp.class, SP.class, L.class})
|
2018-03-19 17:38:48 +01:00
|
|
|
public class ConstraintTest {
|
2018-03-19 13:11:25 +01:00
|
|
|
|
|
|
|
@Test
|
2018-07-30 20:23:48 +02:00
|
|
|
public void doTests() {
|
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());
|
2019-03-21 21:29:09 +01:00
|
|
|
d.setIfDifferent(7d, "Set 7d", this);
|
|
|
|
Assert.assertEquals(7d, d.value());
|
|
|
|
Assert.assertEquals("ConstraintTest: Set 5d\nConstraintTest: Set 6d\nConstraintTest: Set 4d\nConstraintTest: Set 7d", d.getReasons());
|
|
|
|
Assert.assertEquals("ConstraintTest: Set 4d\nConstraintTest: Set 7d", d.getMostLimitedReasons());
|
|
|
|
Assert.assertEquals(10d, d.originalValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void prepareMock() {
|
|
|
|
AAPSMocker.mockMainApp();
|
|
|
|
AAPSMocker.mockApplicationContext();
|
|
|
|
AAPSMocker.mockSP();
|
|
|
|
AAPSMocker.mockL();
|
2018-03-19 13:11:25 +01:00
|
|
|
}
|
|
|
|
}
|