From 626f5998183b3423685022a69012359197d043fe Mon Sep 17 00:00:00 2001 From: ankita-kalra Date: Fri, 21 Aug 2015 23:52:08 +0530 Subject: [PATCH] Removed Whitespaces, and Changed according to comments --- .../malariatest/MalariaDatabaseTest.java | 566 ++++-------------- 1 file changed, 124 insertions(+), 442 deletions(-) diff --git a/androidTest/java/com/peacecorps/malariatest/MalariaDatabaseTest.java b/androidTest/java/com/peacecorps/malariatest/MalariaDatabaseTest.java index 39e6fb28..a8844b29 100644 --- a/androidTest/java/com/peacecorps/malariatest/MalariaDatabaseTest.java +++ b/androidTest/java/com/peacecorps/malariatest/MalariaDatabaseTest.java @@ -21,6 +21,9 @@ public class MalariaDatabaseTest extends AndroidTestCase { private DatabaseSQLiteHelper db; private FirstAnalyticFragment faf; + int date=0,month=0,year=0; + double percentage=0.0; + String yesResponse="yes"; public void setUp() { @@ -31,19 +34,15 @@ public void setUp() public void testAddEntryinIOMMEmethod() { - int date=30; - int month=5; - int year=2015; - - double percentage=23.00; - + date=30; + month=5; + year=2015; + percentage=23.00; db.insertOrUpdateMissedMedicationEntry(date,month,year,percentage); long x=db.getFirstTime(); - String date_header=""+date+"/"+month+"/"+year; SimpleDateFormat sdf= new SimpleDateFormat("dd/MM/yyyy"); Date d = Calendar.getInstance().getTime(); - try{ d=sdf.parse(date_header); } @@ -51,346 +50,193 @@ public void testAddEntryinIOMMEmethod() { e.printStackTrace(); } - Calendar c=Calendar.getInstance(); - c.setTime(d); - long y = c.getTimeInMillis(); assertEquals(x,y); } public void testDosesInaRowWithNoEntry(){ - - int x = db.getDosesInaRowDaily(); - assertEquals(0,x); - - } public void testDosesInaRowWithASingleEntry(){ - - int date=30; - int month=5; - int year=2015; - + date=30; + month=5; + year=2015; double percentage=23.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - + db.updateMedicationEntry(date, month, year, yesResponse, percentage); int x = db.getDosesInaRowDaily(); - assertEquals(1,x); - - } public void testDosesInaRowWithDoubleEntry(){ - int date=30; - int month=5; - int year=2015; - - double percentage=23.00; - - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - - date=29;month=5;year=2015;percentage=28.00; - - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - - int x = db.getDosesInaRowDaily(); - - assertEquals(2,x); - + date=30; + month=5; + year=2015; + percentage=23.00; + db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); + db.updateMedicationEntry(date, month, year, yesResponse, percentage); + date=29;month=5;year=2015;percentage=28.00; + db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); + db.updateMedicationEntry(date,month,year,yesResponse,percentage); + int x = db.getDosesInaRowDaily(); + assertEquals(2,x); } public void testDosesInaRowWithDiscontinuedYesEntry(){ - int date=30; - int month=5; - int year=2015; - - double percentage=23.00; - - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - - date=29;month=5;year=2015;percentage=28.00; - - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - - date=28;month=5;year=2015;percentage=28.00; - - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"no",percentage); - - date=27;month=5;year=2015;percentage=28.00; - - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - - int x = db.getDosesInaRowDaily(); - - assertEquals(2, x); - - - + date=30; + month=5; + year=2015; + percentage=23.00; + db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); + db.updateMedicationEntry(date, month, year, yesResponse, percentage); + date=29;month=5;year=2015;percentage=28.00; + db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); + db.updateMedicationEntry(date,month,year,yesResponse,percentage); + date=28;month=5;year=2015;percentage=28.00; + db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); + db.updateMedicationEntry(date,month,year,"no",percentage); + date=27;month=5;year=2015;percentage=28.00; + db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); + db.updateMedicationEntry(date, month, year, yesResponse, percentage); + int x = db.getDosesInaRowDaily(); + assertEquals(2, x); } public void testDosesInaRowWithDiscontiuedDateYesEntry(){ - - int date=30; - int month=5; - int year=2015; - - double percentage=23.00; - - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - - date=29;month=5;year=2015;percentage=28.00; - - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - - date=27;month=5;year=2015;percentage=28.00; - - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - - date=26;month=5;year=2015;percentage=28.00; - - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - + date=30; + month=5; + year=2015; + percentage=23.00; + db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); + db.updateMedicationEntry(date, month, year,yesResponse, percentage); + date=29;month=5;year=2015;percentage=28.00; + db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); + db.updateMedicationEntry(date,month,year,yesResponse,percentage); + date=27;month=5;year=2015;percentage=28.00; + db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); + db.updateMedicationEntry(date,month,year,yesResponse,percentage); + date=26;month=5;year=2015;percentage=28.00; + db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); + db.updateMedicationEntry(date, month, year, yesResponse, percentage); int x = db.getDosesInaRowDaily(); - long a=db.getFirstTime(); - assertEquals(2, x); } public void testDosesInaRowWithDiscontinuedBoundaryDateYesEntry(){ - - int date=30; - int month=5; - int year=2015; - - double percentage=23.00; - + date=30; + month=5; + year=2015; + percentage=23.00; db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - + db.updateMedicationEntry(date, month, year, yesResponse, percentage); date=1;month=6;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - + db.updateMedicationEntry(date,month,year,yesResponse,percentage); date=2;month=6;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - + db.updateMedicationEntry(date,month,year,yesResponse,percentage); date=3;month=6;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - - int x = db.getDosesInaRowDaily(); - + db.updateMedicationEntry(date, month, year,yesResponse, percentage); + x = db.getDosesInaRowDaily(); assertEquals(4,x); - } public void testDosesInaRowWeeklyIrregular(){ - - int date=24; - int month=5; - int year=2015; - - double percentage=23.00; - + date=24; + month=5; + year=2015; + percentage=23.00; db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - + db.updateMedicationEntry(date, month, year, yesResponse, percentage); date=17;month=5;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - + db.updateMedicationEntry(date,month,year,yesResponse,percentage); date=9;month=5;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - + db.updateMedicationEntry(date,month,year,yesResponse,percentage); date=3;month=5;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - + db.updateMedicationEntry(date, month, year, yesResponse, percentage); int x = db.getDosesInaRowWeekly(); - assertEquals(4,x); - - } public void testDosesInaRowWeeklyDiscontinued(){ - - int date=30; - int month=5; - int year=2015; - - double percentage=23.00; - + date=30; + month=5; + year=2015; + percentage=23.00; db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - + db.updateMedicationEntry(date, month, year, yesResponse, percentage); date=23;month=5;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - + db.updateMedicationEntry(date,month,year,yesResponse,percentage); date=16;month=5;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - + db.updateMedicationEntry(date,month,year,yesResponse,percentage); date=3;month=5;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - + db.updateMedicationEntry(date, month, year,yesResponse, percentage); int x = db.getDosesInaRowWeekly(); - assertEquals(3,x); - - } public void testDosesInaRowWeeklyNoEntry(){ - int x = db.getDosesInaRowWeekly(); - assertEquals(0,x); - - } public void testDosesInaRowWeeklyIrregularDifferentMonths(){ - - int date=24; - int month=5; - int year=2015; - - double percentage=23.00; - + date=24; + month=5; + year=2015; + percentage=23.00; db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - + db.updateMedicationEntry(date, month, year, yesResponse, percentage); date=17;month=5;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - + db.updateMedicationEntry(date,month,year,yesResponse,percentage); date=9;month=5;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - + db.updateMedicationEntry(date,month,year,yesResponse,percentage); date=31;month=4;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - + db.updateMedicationEntry(date, month, year, yesResponse, percentage); date=28;month=4;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - + db.updateMedicationEntry(date, month, year, yesResponse, percentage); int x = db.getDosesInaRowWeekly(); - assertEquals(5,x); - - } - - public void testAdherence() { - - - int date=30; - int month=7; - int year=2015; - - double percentage=23.00; - + date=30; + month=7; + year=2015; + percentage=23.00; db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - + db.updateMedicationEntry(date, month, year, yesResponse, percentage); date=29;month=7;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - + db.updateMedicationEntry(date,month,year,yesResponse,percentage); date=27;month=7;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - + db.updateMedicationEntry(date,month,year,yesResponse,percentage); date=26;month=7;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - - + db.updateMedicationEntry(date, month, year, "yesResponse", percentage); long a=db.getFirstTime(); - date=30;month=7;year=2015; - String date_header=""+date+"/"+month+"/"+year; SimpleDateFormat sdf= new SimpleDateFormat("dd/MM/yyyy"); Date d = Calendar.getInstance().getTime(); - try{ d=sdf.parse(date_header); } @@ -398,287 +244,123 @@ public void testAdherence() { e.printStackTrace(); } - Calendar c=Calendar.getInstance(); - c.setTime(d); - long y = c.getTimeInMillis(); - - long today= Calendar.getInstance().getTimeInMillis(); - SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); String formattedDate = df.format(Calendar.getInstance().getTime()); - // formattedDate have current date/time - //Toast.makeText(this, formattedDate, Toast.LENGTH_SHORT).show(); - long oneDay = 1000 * 60 * 60 * 24; - long interval=(y-a)/oneDay+1; - long takenCount=db.countTaken(); - double ar=(double)takenCount/(double)interval*100; - - //double arm= faf.updateAdherence(); - assertEquals(80.0,ar); - - /*int date=22; - int month=6; - int year=2015; - - double percentage=23.00; - - db.insertOrUpdateMissedMedicationEntry(date,month,year,percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - - date=23; - month=6; - year=2015; - - percentage=45.00; - - db.insertOrUpdateMissedMedicationEntry(date,month,year,percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - - date=27;month=6;year=2015;percentage=28.00; - - db.insertOrUpdateMissedMedicationEntry(date,month,year,percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - long x=0; - db.getFirstTime(); - - Log.d("TestRunner","first run time->"+x); - - Date d = Calendar.getInstance().getTime(); - - Calendar c=Calendar.getInstance(); - - c.setTime(d); - - long y = c.getTimeInMillis(); - - long oneDay = 1000 * 60 * 60 * 24; - - double chk=(double)(y-x)/(double)oneDay; - - double ar=faf.updateAdherence(); - - assertEquals(ar,chk); - - /*int date=22; - int month=6; - int year=2015; - - double percentage=23.00; - - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - - date=23;month=6;year=2015;percentage=28.00; - - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - - date=27;month=6;year=2015;percentage=28.00; - - long x=db.getFirstTime(); - - String date_header=""+date+"/"+month+"/"+year; - SimpleDateFormat sdf= new SimpleDateFormat("dd/MM/yyyy"); - Date d = Calendar.getInstance().getTime(); - - try{ - d=sdf.parse(date_header); - } - catch (ParseException e) - { - e.printStackTrace(); - } - - Calendar c=Calendar.getInstance(); - - c.setTime(d); - - long y = c.getTimeInMillis(); - assertEquals(x,y); - */ - } public void testCountTaken() { - int date=28; - int month=6; - int year=2015; - - double percentage=00.00; - + date=28; + month=6; + year=2015; + percentage=00.00; db.insertOrUpdateMissedMedicationEntry(date,month,year,percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - + db.updateMedicationEntry(date, month, year, yesResponse, percentage); date=7; month=6; year=2015; - percentage=00.00; - db.insertOrUpdateMissedMedicationEntry(date,month,year,percentage); - - db.updateMedicationEntry(date, month,year,"yes",percentage); - + db.updateMedicationEntry(date, month,year,yesResponse,percentage); int x= db.countTaken(); - - assertEquals(2,x); - } public void testWeekdays() { - int date=30; - int month=12; - int year=2014; - + date=30; + month=12; + year=2014; Date s=db.getDateObject(""+year+"-"+month+"-"+date); - date=6; month=1; year=2015; - Date e = db.getDateObject(""+year+"-"+month+"-"+date); - int x= db.getIntervalWeekly(s, e, 3); - assertEquals(2,x); - } public void testDailyDays() { - int date=30; - int month=12; - int year=2014; - + date=30; + month=12; + year=2014; Date s=db.getDateObject(""+year+"-"+month+"-"+date); - date=6; month=1; year=2015; - Date e = db.getDateObject(""+year+"-"+month+"-"+date); - int x= db.getIntervalDaily(s, e); - assertEquals(8,x); - } public void testgetCountTakenBetween() { - int date=1; - int month=8; - int year=2015; - + date=1; + month=8; + year=2015; Date s=db.getDateObject(""+year+"-"+month+"-"+date); - date=15; month=8; year=2015; - Date e = db.getDateObject(""+year+"-"+month+"-"+date); - date=2; month=8; year=2015; - - double percentage=23.00; - + percentage=23.00; db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - + db.updateMedicationEntry(date, month, year, yesResponse, percentage); date=3;month=8;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - + db.updateMedicationEntry(date,month,year,yesResponse,percentage); date=4;month=8;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - + db.updateMedicationEntry(date,month,year,yesResponse,percentage); date=6;month=8;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - - + db.updateMedicationEntry(date, month, year, yesResponse, percentage); int cnt=db.getCountTakenBetween(s,e); - assertEquals(4,cnt); - } public void testgetCountTakenBetweenBoundary() { - int date=1; - int month=8; - int year=2015; - + date=1; + month=8; + year=2015; Date s=db.getDateObject(""+year+"-"+month+"-"+date); - date=15; month=8; year=2015; - Date e = db.getDateObject(""+year+"-"+month+"-"+date); - date=1; month=8; year=2015; - - double percentage=23.00; - + percentage=23.00; db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - + db.updateMedicationEntry(date, month, year, yesResponse, percentage); date=3;month=8;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - + db.updateMedicationEntry(date,month,year,yesResponse,percentage); date=4;month=8;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date,month,year,"yes",percentage); - + db.updateMedicationEntry(date,month,year,yesResponse,percentage); date=15;month=8;year=2015;percentage=28.00; - db.insertOrUpdateMissedMedicationEntry(date, month, year, percentage); - - db.updateMedicationEntry(date, month, year, "yes", percentage); - - + db.updateMedicationEntry(date, month, year, yesResponse, percentage); int cnt=db.getCountTakenBetween(s,e); - assertEquals(4,cnt); }