Merge branch 'V3.1' of https://github.com/OpenSeizureDetector/Android_Pebble_SD into V3.1
This commit is contained in:
@@ -20,6 +20,9 @@ android {
|
||||
|
||||
testOptions {
|
||||
unitTests.returnDefaultValues = true
|
||||
unitTests {
|
||||
includeAndroidResources = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +45,7 @@ dependencies {
|
||||
implementation 'com.github.wendykierp:JTransforms:3.0'
|
||||
implementation 'com.google.android.gms:play-services-location:10.0.0'
|
||||
//implementation 'com.github.RohitSurwase.UCE-Handler:uce_handler:1.3'
|
||||
testImplementation 'org.robolectric:robolectric:4.3'
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,17 @@ package uk.org.openseizuredetector;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SdAnalyserTest {
|
||||
public SdAnalyser sda;
|
||||
|
||||
public String alarmJSON = "{ dataType: 'raw', " +
|
||||
"data: [" +
|
||||
public String alarmJSON = "{ 'dataType': 'raw', " +
|
||||
"'data': [" +
|
||||
"1644, 1316, 1144, 1332, 1716, 1716, 1392, 1148, 1276, 1660, " +
|
||||
"1716, 1496, 1196, 1232, 1572, 1684, 1552, 1236, 1228, 1528, " +
|
||||
"1648, 1572, 1268, 1208, 1492, 1680, 1596, 1272, 1192, 1424, " +
|
||||
@@ -24,13 +27,13 @@ public class SdAnalyserTest {
|
||||
"1188, 1360, 1680, 1724, 1424, 1192, 1224, 1556, 1744, 1588, " +
|
||||
"1260, 1220, 1472, 1692, 1608, 1328, 1192, 1412, 1668, 1656, " +
|
||||
"1356, 1216, 1304, 1636, 1712], " +
|
||||
"HR:54, " +
|
||||
"Mute:0 " +
|
||||
"'HR':54, " +
|
||||
"'Mute':0 " +
|
||||
"}";
|
||||
|
||||
private String okJSON = "{ " +
|
||||
"dataType: 'raw', " +
|
||||
"data: [" +
|
||||
"\"dataType\": \"raw\", " +
|
||||
"\"data\": [" +
|
||||
"1140, 1188, 1144, 1172, 1228, 1212, 1236, 1236, 1256, 1320, " +
|
||||
"1316, 1280, 1240, 1280, 1324, 1284, 1292, 1268, 1284, 1276, " +
|
||||
"1296, 1324, 1308, 1288, 1304, 1276, 1304, 1304, 1276, 1296, " +
|
||||
@@ -44,8 +47,8 @@ public class SdAnalyserTest {
|
||||
"1268, 1292, 1292, 1304, 1288, 1284, 1280, 1276, 1288, 1280, " +
|
||||
"1300, 1288, 1320, 1268, 1288, 1280, 1304, 1280, 1280, 1288, " +
|
||||
"1292, 1308, 1268, 1292, 1280], " +
|
||||
"HR:57, " +
|
||||
"Mute:0 " +
|
||||
"\"HR\":57, " +
|
||||
"\"Mute\":0 " +
|
||||
"}";
|
||||
|
||||
@Before
|
||||
@@ -65,7 +68,7 @@ public class SdAnalyserTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void freq2fftBin() {
|
||||
public void testFreq2fftBin() {
|
||||
int n;
|
||||
n = sda.freq2fftBin(0.0);
|
||||
assertEquals(0,n);
|
||||
@@ -74,7 +77,7 @@ public class SdAnalyserTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMagnitude() {
|
||||
public void testGetMagnitude() {
|
||||
double[] fft = {1, 1,
|
||||
2, 1,
|
||||
2, 2};
|
||||
@@ -87,4 +90,54 @@ public class SdAnalyserTest {
|
||||
assertEquals(8.0, m, m * 1e-4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAccelDataFromJson() {
|
||||
double[] retVal;
|
||||
|
||||
retVal = sda.getAccelDataFromJSON(okJSON);
|
||||
assertNotNull(retVal);
|
||||
assertEquals(125,retVal.length);
|
||||
assertEquals(1140,retVal[0],0.001);
|
||||
assertEquals(1280,retVal[124],0.001);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetSpectrumRatio() {
|
||||
double[] okRawVals;
|
||||
double[] alarmRawVals;
|
||||
okRawVals = sda.getAccelDataFromJSON(okJSON);
|
||||
alarmRawVals = sda.getAccelDataFromJSON(alarmJSON);
|
||||
|
||||
double okRatio;
|
||||
double alarmRatio;
|
||||
|
||||
okRatio = sda.getSpectrumRatio(okRawVals);
|
||||
alarmRatio = sda.getSpectrumRatio(alarmRawVals);
|
||||
|
||||
assertTrue("Check Spectrum Ratio for OK data "+okRatio+" is <="+sda.mAlarmRatioThresh,
|
||||
okRatio <= sda.mAlarmRatioThresh);
|
||||
assertTrue("Check Spectrum Ratio for ALARM data "+alarmRatio+" is >"+sda.mAlarmRatioThresh,
|
||||
alarmRatio > sda.mAlarmRatioThresh);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testgetAlarmState() {
|
||||
double[] okRawVals;
|
||||
double[] alarmRawVals;
|
||||
okRawVals = sda.getAccelDataFromJSON(okJSON);
|
||||
alarmRawVals = sda.getAccelDataFromJSON(alarmJSON);
|
||||
|
||||
int okAlarmState;
|
||||
int alarmAlarmState;
|
||||
|
||||
okAlarmState = sda.getAlarmState(okRawVals);
|
||||
alarmAlarmState = sda.getAlarmState(alarmRawVals);
|
||||
|
||||
assertEquals("check OK start detected from raw data",0, okAlarmState);
|
||||
assertEquals("check alarm state detected from raw data",1, alarmAlarmState);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user