-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added calculationtest and orientationtest
- Loading branch information
1 parent
5905ef9
commit 7cdede0
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
app/src/test/java/com/team34/cse_110_project_team_34/CalculationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.team34.cse_110_project_team_34; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import utilities.Calculation; | ||
|
||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class CalculationTest { | ||
double lat1 = 0; | ||
double long1 = 0; | ||
double lat2 = 40; | ||
double long2 = 30; | ||
|
||
@Test | ||
public void checkAngle() { | ||
assertEquals(Math.toDegrees(Math.asin(3/(float) 5)), Calculation.getAngle(lat1,long1,lat2,long2), 1); | ||
} | ||
|
||
@Test | ||
public void checkDistance() { | ||
assertEquals(69*Math.sqrt((lat2-lat1)*(lat2-lat1) + (long2-long1)*(long2-long1)), Calculation.getDistance(lat1,long1,lat2,long2),1); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
app/src/test/java/com/team34/cse_110_project_team_34/DatabaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package com.team34.cse_110_project_team_34;public class DatabaseTest { | ||
} |
59 changes: 59 additions & 0 deletions
59
app/src/test/java/com/team34/cse_110_project_team_34/OrientationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
|
||
package com.team34.cse_110_project_team_34; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import android.content.Context; | ||
import android.content.pm.ActivityInfo; | ||
import android.media.Image; | ||
import android.provider.SyncStateContract; | ||
import android.widget.ImageView; | ||
|
||
import androidx.lifecycle.Lifecycle; | ||
import androidx.lifecycle.MutableLiveData; | ||
import androidx.test.core.app.ActivityScenario; | ||
import androidx.test.core.app.ApplicationProvider; | ||
|
||
import com.ibm.icu.impl.units.UnitsData; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
|
||
import utilities.OrientationService; | ||
|
||
|
||
@RunWith(RobolectricTestRunner.class) | ||
public class OrientationTest { | ||
ActivityScenario<CompassActivity> scenario; | ||
|
||
@Before | ||
public void preTest() { | ||
scenario = ActivityScenario.launch(CompassActivity.class); | ||
scenario.moveToState(Lifecycle.State.CREATED); | ||
scenario.moveToState(Lifecycle.State.STARTED); | ||
scenario.moveToState(Lifecycle.State.RESUMED); | ||
} | ||
|
||
// OrientationService's azimuth is in radians | ||
// Compass's rotation is in degrees | ||
@Test | ||
public void testOrientation() { | ||
float testValue = (float) Math.PI; | ||
ActivityScenario<CompassActivity> scenario = ActivityScenario.launch(CompassActivity.class); | ||
|
||
scenario.onActivity(activity -> { | ||
OrientationService orientationService = OrientationService.getInstance(activity); | ||
MutableLiveData<Float> mockOrientation = new MutableLiveData<Float>(); | ||
|
||
mockOrientation.setValue(testValue); | ||
orientationService.setMockOrientationSource(mockOrientation); | ||
activity.observeOrientation(); | ||
|
||
ImageView compass = activity.findViewById(R.id.compass); | ||
assertEquals(Math.toDegrees(testValue), compass.getRotation(), 1); | ||
}); | ||
} | ||
} |