Trying to get some automated tests working....
This commit is contained in:
@@ -6,10 +6,11 @@ import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SdAlgHr {
|
||||
private final static String TAG = "SdAlgHr";
|
||||
private Context mContext;
|
||||
private OsdUtil mUtil;
|
||||
private boolean mSimpleHrAlarmActive;
|
||||
private double mSimpleHrAlarmThreshMin;
|
||||
private double mSimpleHrAlarmThreshMax;
|
||||
@@ -24,11 +25,13 @@ public class SdAlgHr {
|
||||
private double mAverageHrAlarmThreshMin;
|
||||
private double mAverageHrAlarmThreshMax;
|
||||
|
||||
private ArrayList<Double> mHrHist;
|
||||
|
||||
public SdAlgHr(Context context) {
|
||||
Log.d(TAG, "SdAlgHr Constructor");
|
||||
Log.i(TAG, "SdAlgHr Constructor");
|
||||
mContext = context;
|
||||
mUtil = new OsdUtil(mContext, new Handler());
|
||||
mHrHist = new ArrayList<Double>();
|
||||
updatePrefs();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
@@ -47,8 +50,7 @@ public class SdAlgHr {
|
||||
retVal = Double.parseDouble(prefValStr);
|
||||
} catch (Exception ex) {
|
||||
Log.v(TAG, "readDoublePref() - Problem with preference!");
|
||||
mUtil.writeToSysLogFile(TAG+".readDoublePref() - Problem with preference!");
|
||||
mUtil.showToast(TAG+":"+mContext.getString(R.string.problem_parsing_preferences));
|
||||
//mUtil.showToast(TAG+":"+mContext.getString(R.string.problem_parsing_preferences));
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
@@ -59,25 +61,104 @@ public class SdAlgHr {
|
||||
* - defined in res/xml/prefs.xml
|
||||
*/
|
||||
Log.i(TAG, "updatePrefs()");
|
||||
mUtil.writeToSysLogFile(TAG+".updatePrefs()");
|
||||
|
||||
SharedPreferences SP = PreferenceManager
|
||||
.getDefaultSharedPreferences(mContext);
|
||||
mSimpleHrAlarmActive = SP.getBoolean("HRAlarmActive", false);
|
||||
mSimpleHrAlarmThreshMin = readDoublePref(SP, "HRThreshMin", "20");
|
||||
mSimpleHrAlarmThreshMax = readDoublePref(SP, "HRThreshMax", "150");
|
||||
|
||||
Log.d(TAG,"updatePrefs(): mSimpleHrAlarmActive="+mSimpleHrAlarmActive);
|
||||
Log.d(TAG,"updatePrefs(): mSimpleHrAlarmThreshMin="+mSimpleHrAlarmThreshMin);
|
||||
Log.d(TAG,"updatePrefs(): mSimpleHrAlarmThreshMax="+mSimpleHrAlarmThreshMax);
|
||||
|
||||
mAdaptiveHrAlarmActive = SP.getBoolean("HRAdaptiveAlarmActive", false);
|
||||
mAdaptiveHrAlarmWindowSecs = readDoublePref(SP, "HRAdaptiveAlarmWindowSecs", "30");
|
||||
mAdaptiveHrAlarmWindowDp = (int)Math.round(mAdaptiveHrAlarmWindowSecs/5.0);
|
||||
mAdaptiveHrAlarmThresh = readDoublePref(SP, "HRAdaptiveAlarmThresh", "20");
|
||||
Log.d(TAG,"updatePrefs(): mAdaptiveHrAlarmActive="+mAdaptiveHrAlarmActive);
|
||||
Log.d(TAG,"updatePrefs(): mAdaptiveHrWindowSecs="+mAdaptiveHrAlarmWindowSecs);
|
||||
Log.d(TAG,"updatePrefs(): mAdaptiveHrWindowDp="+mAdaptiveHrAlarmWindowDp);
|
||||
Log.d(TAG,"updatePrefs(): mAdaptiveHrAlarmThresh="+mAdaptiveHrAlarmThresh);
|
||||
|
||||
mAverageHrAlarmActive = SP.getBoolean("HRAverageAlarmActive", false);
|
||||
mAverageHrAlarmWindowSecs = readDoublePref(SP, "HRAverageAlarmWindowSecs", "120");
|
||||
mAverageHrAlarmWindowDp = (int)Math.round(mAverageHrAlarmWindowSecs/5.0);
|
||||
mAverageHrAlarmThreshMin = readDoublePref(SP, "HRAverageAlarmThreshMin", "40");
|
||||
mAverageHrAlarmThreshMax = readDoublePref(SP, "HRAverageAlarmThreshMax", "120");
|
||||
Log.d(TAG,"updatePrefs(): mAverageHrAlarmActive="+mAverageHrAlarmActive);
|
||||
Log.d(TAG,"updatePrefs(): mAverageHrAlarmWindowSecs="+mAverageHrAlarmWindowSecs);
|
||||
Log.d(TAG,"updatePrefs(): mAverageHrAlarmWindowDp="+mAverageHrAlarmWindowDp);
|
||||
Log.d(TAG,"updatePrefs(): mAverageHrAlarmThreshMin="+mAverageHrAlarmThreshMin);
|
||||
Log.d(TAG,"updatePrefs(): mAverageHrAlarmThreshMax="+mAverageHrAlarmThreshMax);
|
||||
|
||||
}
|
||||
|
||||
private void addToHist(double hrVal) {
|
||||
/**
|
||||
* Add value hrVal to the heart rate history list, truncating the list if it is
|
||||
* longer than the required length.
|
||||
*/
|
||||
Log.d(TAG,"addToHist() - length before="+mHrHist.size());
|
||||
mHrHist.add(hrVal);
|
||||
Log.d(TAG,"addToHist() - length before="+mHrHist.size());
|
||||
}
|
||||
|
||||
private boolean checkSimpleHr(double hrVal) {
|
||||
/**
|
||||
* Check heart rate value against simple thresholds
|
||||
*/
|
||||
boolean retVal = false;
|
||||
if (mSimpleHrAlarmActive) {
|
||||
if ((hrVal > mSimpleHrAlarmThreshMax)
|
||||
|| (hrVal <mSimpleHrAlarmThreshMin)) {
|
||||
retVal = true;
|
||||
}
|
||||
}
|
||||
return(retVal);
|
||||
}
|
||||
|
||||
private boolean checkAdaptiveHr(double hrVal) {
|
||||
// FIXME Make this do something
|
||||
return(false);
|
||||
}
|
||||
|
||||
private boolean checkAverageHr(double hrVal) {
|
||||
// FIXME Make this do something
|
||||
return(false);
|
||||
}
|
||||
|
||||
public double getAverageHrVal() {
|
||||
double hrSum = 0.;
|
||||
int hrCount = 0;
|
||||
double retVal;
|
||||
for (int n=0; n<mHrHist.size(); n++) {
|
||||
if (mHrHist.get(n) > -1) {
|
||||
hrSum += mHrHist.get(n);
|
||||
hrCount++;
|
||||
}
|
||||
}
|
||||
if (hrCount>0) {
|
||||
retVal = hrSum / hrCount;
|
||||
} else {
|
||||
retVal = -1;
|
||||
}
|
||||
return(retVal);
|
||||
}
|
||||
|
||||
public ArrayList<Boolean> checkHr(double hrVal) {
|
||||
/**
|
||||
* Checks the current Heart Rate reading hrVal against the
|
||||
* three possible heart rate alarm algorithms (simple, adaptive, average)
|
||||
* and returns an ArrayList of the alarm status of each algorithm in the above order.
|
||||
* true=ALARM, false=OK.
|
||||
*/
|
||||
Log.v(TAG, "checkHr("+hrVal+")");
|
||||
addToHist(hrVal);
|
||||
ArrayList<Boolean> retVal = new ArrayList<Boolean>();
|
||||
retVal.add(checkSimpleHr(hrVal));
|
||||
retVal.add(checkAdaptiveHr(hrVal));
|
||||
retVal.add(checkAverageHr(hrVal));
|
||||
return(retVal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
package uk.org.openseizuredetector;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.TimeZone;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(sdk = {Build.VERSION_CODES.O_MR1}, packageName = "uk.org.openseizuredetector")
|
||||
public class LogManagerTest extends TestCase {
|
||||
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
SdData getFakeSdData() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWriteToLocalDb() {
|
||||
//SdData sd1 = getFakeSdData();
|
||||
//mLm.writeToLocalDb(sd1);
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
public void testGetDatapointById() {
|
||||
}
|
||||
|
||||
public void testSetDatapointToUploaded() {
|
||||
}
|
||||
|
||||
public void testSetDatapointStatus() {
|
||||
}
|
||||
|
||||
public void testGetDatapointsByDate() {
|
||||
}
|
||||
|
||||
public void testGetEventsList() {
|
||||
}
|
||||
|
||||
public void testPruneLocalDb() {
|
||||
}
|
||||
|
||||
public void testGetNextEventToUpload() {
|
||||
}
|
||||
|
||||
public void testGetNearestDatapointToDate() {
|
||||
}
|
||||
|
||||
public void testGetLocalEventsCount() {
|
||||
}
|
||||
|
||||
public void testGetLocalDatapointsCount() {
|
||||
}
|
||||
|
||||
public void testWriteToRemoteServer() {
|
||||
}
|
||||
|
||||
public void testUploadSdData() {
|
||||
}
|
||||
|
||||
public void testAuthCallback() {
|
||||
}
|
||||
|
||||
public void testFinishUpload() {
|
||||
}
|
||||
|
||||
public void testEventCallback() {
|
||||
}
|
||||
|
||||
public void testUploadNextDatapoint() {
|
||||
}
|
||||
|
||||
public void testDatapointCallback() {
|
||||
}
|
||||
|
||||
public void testClose() {
|
||||
}
|
||||
|
||||
public void testStopRemoteLogTimer() {
|
||||
}
|
||||
|
||||
public void testStopAutoPruneTimer() {
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package uk.org.openseizuredetector;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Handler;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import java.util.regex.Pattern;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by graham on 01/01/16.
|
||||
*/
|
||||
public class OsdUtilTest {
|
||||
|
||||
@Test
|
||||
public void testIsServerRunning() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartServer() throws Exception {
|
||||
//Activity a = new Activity();
|
||||
Handler handler = new Handler();
|
||||
OsdUtil util = new OsdUtil(null,handler);
|
||||
assertThat(util.isServerRunning(), is(true));
|
||||
assertThat(true, is (true));
|
||||
//assertThat(true, is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopServer() throws Exception {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package uk.org.openseizuredetector;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SdAlgHrTest extends TestCase {
|
||||
private SdAlgHr mSdAlgHr = null;
|
||||
|
||||
//@Mock
|
||||
private Context mContext;
|
||||
|
||||
|
||||
private SharedPreferences sharedPrefs;
|
||||
private static PreferenceManager mPreferenceManager;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
//mContext = ApplicationProvider.getApplicationContext();
|
||||
this.sharedPrefs = Mockito.mock(SharedPreferences.class);
|
||||
this.mContext = Mockito.mock(Context.class);
|
||||
mPreferenceManager = Mockito.mock(PreferenceManager.class);
|
||||
//Mockito.when(mContext.getSharedPreferences(anyString(), anyInt())).thenReturn(sharedPrefs);
|
||||
Mockito.when(mPreferenceManager.getDefaultSharedPreferences(any())).thenReturn(sharedPrefs);
|
||||
mSdAlgHr = new SdAlgHr(mContext);
|
||||
assertNotNull(mSdAlgHr);
|
||||
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckHr() throws Exception{
|
||||
setUp();
|
||||
assertNotNull(mSdAlgHr);
|
||||
mSdAlgHr.checkHr(60.);
|
||||
mSdAlgHr.checkHr(70.);
|
||||
mSdAlgHr.checkHr(80.);
|
||||
double hrAv = mSdAlgHr.getAverageHrVal();
|
||||
assertEquals(hrAv, 70);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package uk.org.openseizuredetector;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.TimeZone;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(sdk = {Build.VERSION_CODES.O_MR1}, packageName = "uk.org.openseizuredetector")
|
||||
public class SdDataTest extends TestCase {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
SdData sd = new SdData();
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
|
||||
public void testFromJSON() {
|
||||
}
|
||||
|
||||
public void testTestToString() {
|
||||
}
|
||||
|
||||
public void testToJSON() {
|
||||
}
|
||||
|
||||
public void testToDataString() {
|
||||
}
|
||||
|
||||
public void testToCSVString() {
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package uk.org.openseizuredetector;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
|
||||
import com.google.firebase.FirebaseApp;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class WebApiConnectionTest {
|
||||
WebApiConnection mWac;
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Context context = ApplicationProvider.getApplicationContext();
|
||||
FirebaseApp.initializeApp(context);
|
||||
mWac = new WebApiConnection(context);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isLoggedIn() {
|
||||
assertTrue(mWac.isLoggedIn());
|
||||
assertFalse(mWac.isLoggedIn());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createEvent() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEvent() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEvents() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateEvent() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDatapoint() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUserProfile() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user