Skip to content

Commit

Permalink
added calculationtest and orientationtest
Browse files Browse the repository at this point in the history
  • Loading branch information
giraffe2003 committed Mar 17, 2023
1 parent 5905ef9 commit 7cdede0
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
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);
}
}
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 {
}
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);
});
}
}

0 comments on commit 7cdede0

Please sign in to comment.