|
3 | 3 | */ |
4 | 4 | package de.dmi3y.behaiv; |
5 | 5 |
|
| 6 | +import de.dmi3y.behaiv.kernel.DummyKernel; |
| 7 | +import de.dmi3y.behaiv.node.BehaivNode; |
| 8 | +import de.dmi3y.behaiv.node.MockActionableNode; |
| 9 | +import de.dmi3y.behaiv.provider.TestProvider; |
| 10 | +import io.reactivex.rxjava3.core.Observable; |
| 11 | +import org.apache.commons.math3.util.Pair; |
| 12 | +import org.junit.Before; |
6 | 13 | import org.junit.Test; |
7 | | -import static org.junit.Assert.*; |
| 14 | + |
| 15 | +import java.util.ArrayList; |
| 16 | + |
| 17 | +import static de.dmi3y.behaiv.kernel.DummyKernelTest.GYM; |
| 18 | +import static de.dmi3y.behaiv.kernel.DummyKernelTest.HOME; |
| 19 | +import static de.dmi3y.behaiv.kernel.DummyKernelTest.JOG; |
| 20 | +import static de.dmi3y.behaiv.kernel.DummyKernelTest.WORK; |
| 21 | +import static org.junit.Assert.assertEquals; |
8 | 22 |
|
9 | 23 | public class LibraryTest { |
10 | | - @Test public void testSomeLibraryMethod() { |
11 | | -// Behaiv classUnderTest = new Behaiv(); |
12 | | -// assertTrue("someLibraryMethod should return 'true'", classUnderTest.someLibraryMethod()); |
| 24 | + Behaiv behaiv; |
| 25 | + private TestProvider positionProvider; |
| 26 | + private TestProvider timeProvider; |
| 27 | + private ArrayList<Pair<ArrayList<Double>, String>> data; |
| 28 | + |
| 29 | + public static final String WORK_SCREEN = "WORK_SCREEN"; |
| 30 | + |
| 31 | + @Before |
| 32 | + public void setUp() throws Exception { |
| 33 | + behaiv = Behaiv.with(new DummyKernel()); |
| 34 | + positionProvider = new TestProvider(new String[]{"latitude", "longitude"}, new Double[]{10.10, 10.10}); |
| 35 | + timeProvider = new TestProvider(new String[]{"time"}, new Double[]{9.0 * 60 + 30.0}); |
| 36 | + behaiv.setProvider(positionProvider); |
| 37 | + behaiv.setProvider(timeProvider); |
| 38 | + ArrayList<Double> list = new ArrayList<>(); |
| 39 | + data = new ArrayList<>(); |
| 40 | + |
| 41 | + |
| 42 | + list.add(5 * 60 + 00.0); |
| 43 | + list.add(HOME[0]); |
| 44 | + list.add(HOME[1]); |
| 45 | + list.add(0.0); |
| 46 | + data.add(new Pair<>(list, "SELFIMPROVEMENT_SCREEN")); |
| 47 | + list = new ArrayList<>(); |
| 48 | + list.add(5 * 60 + 10.0); |
| 49 | + list.add(HOME[0]); |
| 50 | + list.add(HOME[1]); |
| 51 | + list.add(0.0); |
| 52 | + data.add(new Pair<>(list, "SELFIMPROVEMENT_SCREEN")); |
| 53 | + list = new ArrayList<>(); |
| 54 | + list.add(6 * 60 + 10.0); |
| 55 | + list.add(GYM[0]); |
| 56 | + list.add(GYM[1]); |
| 57 | + list.add(1.0); |
| 58 | + data.add(new Pair<>(list, "SPORT_SCREEN")); |
| 59 | + list = new ArrayList<>(); |
| 60 | + list.add(7 * 60 + 30.0); |
| 61 | + list.add(HOME[0]); |
| 62 | + list.add(HOME[1]); |
| 63 | + list.add(1.0); |
| 64 | + data.add(new Pair<>(list, "SELFIMPROVEMENT_SCREEN")); |
| 65 | + list = new ArrayList<>(); |
| 66 | + list.add(8 * 60 + 30.0); |
| 67 | + list.add(WORK[0]); |
| 68 | + list.add(WORK[1]); |
| 69 | + list.add(0.0); |
| 70 | + |
| 71 | + data.add(new Pair<>(list, WORK_SCREEN)); |
| 72 | + list = new ArrayList<>(); |
| 73 | + list.add(10 * 60 + 30.0); |
| 74 | + list.add(WORK[0]); |
| 75 | + list.add(WORK[1]); |
| 76 | + list.add(1.0); |
| 77 | + data.add(new Pair<>(list, WORK_SCREEN)); |
| 78 | + list = new ArrayList<>(); |
| 79 | + list.add(11 * 60 + 30.0); |
| 80 | + list.add(WORK[0]); |
| 81 | + list.add(WORK[1]); |
| 82 | + list.add(1.0); |
| 83 | + data.add(new Pair<>(list, WORK_SCREEN)); |
| 84 | + list = new ArrayList<>(); |
| 85 | + list.add(16 * 60 + 30.0); |
| 86 | + list.add(WORK[0]); |
| 87 | + list.add(WORK[1]); |
| 88 | + list.add(0.0); |
| 89 | + data.add(new Pair<>(list, WORK_SCREEN)); |
| 90 | + list = new ArrayList<>(); |
| 91 | + list.add(17 * 60 + 10.0); |
| 92 | + list.add(WORK[0]); |
| 93 | + list.add(WORK[1]); |
| 94 | + list.add(0.0); |
| 95 | + data.add(new Pair<>(list, WORK_SCREEN)); |
| 96 | + list = new ArrayList<>(); |
| 97 | + list.add(18 * 60 + 50.0); |
| 98 | + list.add(WORK[0]); |
| 99 | + list.add(WORK[1]); |
| 100 | + list.add(0.0); |
| 101 | + data.add(new Pair<>(list, WORK_SCREEN)); |
| 102 | + list = new ArrayList<>(); |
| 103 | + list.add(19 * 60 + 5.0); |
| 104 | + list.add(JOG[0]); |
| 105 | + list.add(JOG[1]); |
| 106 | + list.add(1.0); |
| 107 | + data.add(new Pair<>(list, "SPORT_SCREEN")); |
| 108 | + list = new ArrayList<>(); |
| 109 | + list.add(19 * 60 + 10.0); |
| 110 | + list.add(JOG[0]); |
| 111 | + list.add(JOG[1]); |
| 112 | + list.add(1.0); |
| 113 | + data.add(new Pair<>(list, "SPORT_SCREEN")); |
| 114 | + list = new ArrayList<>(); |
| 115 | + list.add(19 * 60 + 25.0); |
| 116 | + list.add(JOG[0]); |
| 117 | + list.add(JOG[1]); |
| 118 | + list.add(1.0); |
| 119 | + data.add(new Pair<>(list, "SPORT_SCREEN")); |
| 120 | + list = new ArrayList<>(); |
| 121 | + list.add(21 * 60 + 00.0); |
| 122 | + list.add(HOME[0]); |
| 123 | + list.add(HOME[1]); |
| 124 | + list.add(0.0); |
| 125 | + data.add(new Pair<>(list, "ADD_SCREEN")); |
13 | 126 | } |
| 127 | + |
| 128 | + @Test |
| 129 | + public void behaivTest_basicTestFlow_predictsJob() throws Exception { |
| 130 | + for (Pair<ArrayList<Double>, String> fToL : data) { |
| 131 | + ArrayList<Double> features = fToL.getFirst(); |
| 132 | + timeProvider.next(new Double[]{features.get(0)}); |
| 133 | + positionProvider.next(new Double[]{features.get(1), features.get(2)}); |
| 134 | + capture(fToL.getSecond()); |
| 135 | + } |
| 136 | + |
| 137 | + Observable<String> register = behaiv.register(new BehaivNode() { |
| 138 | + }); |
| 139 | + timeProvider.next(new Double[]{11 * 60 + 30.0}); |
| 140 | + positionProvider.next(new Double[]{WORK[0], WORK[1]}); |
| 141 | + behaiv.startCapturing(true); |
| 142 | + String predictionResult = register.blockingFirst(); |
| 143 | + assertEquals(WORK_SCREEN, predictionResult); |
| 144 | + |
| 145 | + } |
| 146 | + |
| 147 | + public void capture(String screenName) throws InterruptedException { |
| 148 | + behaiv.startCapturing(false); |
| 149 | + Thread.sleep(100); |
| 150 | + behaiv.register(new MockActionableNode(), screenName); |
| 151 | + behaiv.stopCapturing(false); |
| 152 | + } |
| 153 | + |
14 | 154 | } |
0 commit comments