commit
578ec83ca5
@ -1,24 +0,0 @@ |
|||||||
package net.pokeranalytics.android |
|
||||||
|
|
||||||
import androidx.test.InstrumentationRegistry |
|
||||||
import androidx.test.runner.AndroidJUnit4 |
|
||||||
|
|
||||||
import org.junit.Test |
|
||||||
import org.junit.runner.RunWith |
|
||||||
|
|
||||||
import org.junit.Assert.* |
|
||||||
|
|
||||||
/** |
|
||||||
* Instrumented test, which will execute on an Android device. |
|
||||||
* |
|
||||||
* See [testing documentation](http://d.android.com/tools/testing). |
|
||||||
*/ |
|
||||||
@RunWith(AndroidJUnit4::class) |
|
||||||
class ExampleInstrumentedTest { |
|
||||||
@Test |
|
||||||
fun useAppContext() { |
|
||||||
// Context of the app under test. |
|
||||||
val appContext = InstrumentationRegistry.getTargetContext() |
|
||||||
assertEquals("net.pokeranalytics.android", appContext.packageName) |
|
||||||
} |
|
||||||
} |
|
||||||
@ -0,0 +1,106 @@ |
|||||||
|
package net.pokeranalytics.android |
||||||
|
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4 |
||||||
|
import net.pokeranalytics.android.calculus.Calculator |
||||||
|
import net.pokeranalytics.android.calculus.ComputedResults |
||||||
|
import net.pokeranalytics.android.calculus.SessionGroup |
||||||
|
import net.pokeranalytics.android.calculus.Stat |
||||||
|
import net.pokeranalytics.android.model.realm.Session |
||||||
|
import net.pokeranalytics.android.model.realm.TimeFrame |
||||||
|
import org.junit.Assert |
||||||
|
import org.junit.Assert.assertEquals |
||||||
|
import org.junit.Test |
||||||
|
import org.junit.runner.RunWith |
||||||
|
import java.text.SimpleDateFormat |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
/** |
||||||
|
* Instrumented test, which will execute on an Android device. |
||||||
|
* |
||||||
|
* See [testing documentation](http://d.android.com/tools/testing). |
||||||
|
*/ |
||||||
|
@RunWith(AndroidJUnit4::class) |
||||||
|
|
||||||
|
class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
||||||
|
|
||||||
|
// convenience extension |
||||||
|
fun Session.Companion.testInstance(netResult: Double, startDate: Date, endDate: Date?): Session { |
||||||
|
var session: Session = Session.newInstance() |
||||||
|
session.result?.netResult = netResult |
||||||
|
session.timeFrame?.setDate(startDate, endDate) |
||||||
|
return session |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
fun testSessionStats() { |
||||||
|
|
||||||
|
val realm = this.mockRealm |
||||||
|
realm.beginTransaction() |
||||||
|
|
||||||
|
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm") |
||||||
|
|
||||||
|
val sd1 = sdf.parse("01/1/2019 10:00") |
||||||
|
val ed1 = sdf.parse("01/1/2019 11:00") |
||||||
|
val sd2 = sdf.parse("02/1/2019 08:00") |
||||||
|
val ed2 = sdf.parse("02/1/2019 11:00") |
||||||
|
|
||||||
|
var s1 = realm.createObject(Session::class.java, "1") |
||||||
|
var s2 = realm.createObject(Session::class.java, "2") |
||||||
|
|
||||||
|
s1.timeFrame = realm.createObject(TimeFrame::class.java) |
||||||
|
s2.timeFrame = realm.createObject(TimeFrame::class.java) |
||||||
|
|
||||||
|
s1.result = realm.createObject(net.pokeranalytics.android.model.realm.Result::class.java) |
||||||
|
s2.result = realm.createObject(net.pokeranalytics.android.model.realm.Result::class.java) |
||||||
|
|
||||||
|
// var s1: Session = Session.newInstance() |
||||||
|
// var s2: Session = Session.newInstance() |
||||||
|
|
||||||
|
s1.result?.netResult = -100.0 |
||||||
|
s2.result?.netResult = 300.0 |
||||||
|
|
||||||
|
realm.insert(s1) |
||||||
|
realm.insert(s2) |
||||||
|
realm.commitTransaction() |
||||||
|
|
||||||
|
realm.beginTransaction() |
||||||
|
s1.timeFrame?.setDate(sd1, ed1) |
||||||
|
s2.timeFrame?.setDate(sd2, ed2) |
||||||
|
|
||||||
|
realm.copyToRealmOrUpdate(s1) |
||||||
|
realm.copyToRealmOrUpdate(s2) |
||||||
|
|
||||||
|
realm.commitTransaction() |
||||||
|
|
||||||
|
val sessions = realm.where(Session::class.java).findAll() |
||||||
|
val group = SessionGroup(name = "test", sessions = sessions) |
||||||
|
|
||||||
|
val results: ComputedResults = Calculator.compute(group, Calculator.Options()) |
||||||
|
val delta = 0.01 |
||||||
|
|
||||||
|
val sum = results.computedStat(Stat.NETRESULT) |
||||||
|
if (sum != null) { |
||||||
|
assertEquals(200.0, sum.value, delta) |
||||||
|
} else { |
||||||
|
Assert.fail("No Net result stat") |
||||||
|
} |
||||||
|
|
||||||
|
val average = results.computedStat(Stat.AVERAGE) |
||||||
|
if (average != null) { |
||||||
|
assertEquals(100.0, average.value, delta) |
||||||
|
} else { |
||||||
|
Assert.fail("No AVERAGE stat") |
||||||
|
} |
||||||
|
|
||||||
|
val duration = results.computedStat(Stat.DURATION) |
||||||
|
if (duration != null) { |
||||||
|
assertEquals(4.0, duration.value, delta) |
||||||
|
} else { |
||||||
|
Assert.fail("No duration stat") |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,26 @@ |
|||||||
|
package net.pokeranalytics.android |
||||||
|
|
||||||
|
import io.realm.Realm |
||||||
|
import io.realm.RealmConfiguration |
||||||
|
import org.junit.After |
||||||
|
import org.junit.Before |
||||||
|
|
||||||
|
open class RealmInstrumentedUnitTest { |
||||||
|
|
||||||
|
lateinit var mockRealm: Realm |
||||||
|
|
||||||
|
@Before |
||||||
|
fun setup() { |
||||||
|
|
||||||
|
val testConfig = RealmConfiguration.Builder().inMemory().name("test-realm").build() |
||||||
|
Realm.setDefaultConfiguration(testConfig) |
||||||
|
mockRealm = Realm.getDefaultInstance() |
||||||
|
} |
||||||
|
|
||||||
|
@After |
||||||
|
@Throws(Exception::class) |
||||||
|
public fun tearDown() { |
||||||
|
mockRealm.close() |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -1,11 +1,11 @@ |
|||||||
package net.pokeranalytics.android.ui.fragment.components |
package net.pokeranalytics.android.ui.fragment.components |
||||||
|
|
||||||
import android.text.InputType |
import android.text.InputType |
||||||
import net.pokeranalytics.android.ui.adapter.components.DisplayableDataSource |
import io.realm.RealmResults |
||||||
|
|
||||||
class BottomSheetData( |
class BottomSheetData( |
||||||
var defaultValue: Any? = null, |
var defaultValue: Any? = null, |
||||||
var hint: String? = "", |
var hint: String? = "", |
||||||
var inputType: Int? = InputType.TYPE_CLASS_TEXT, |
var inputType: Int? = InputType.TYPE_CLASS_TEXT, |
||||||
var data: ArrayList<DisplayableDataSource>? = ArrayList() |
var data: RealmResults<*>? = null |
||||||
) |
) |
||||||
@ -1,13 +1,11 @@ |
|||||||
<?xml version="1.0" encoding="utf-8"?> |
<?xml version="1.0" encoding="utf-8"?> |
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
android:layout_width="match_parent" |
android:layout_width="match_parent" |
||||||
android:layout_height="match_parent" |
android:layout_height="wrap_content"> |
||||||
android:orientation="horizontal"> |
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView |
<androidx.recyclerview.widget.RecyclerView |
||||||
android:id="@+id/gameNameRecyclerView" |
android:id="@+id/gameNameRecyclerView" |
||||||
android:layout_width="match_parent" |
android:layout_width="match_parent" |
||||||
android:layout_height="wrap_content" |
android:layout_height="200dp" /> |
||||||
android:minHeight="200dp" /> |
|
||||||
|
|
||||||
</LinearLayout> |
</FrameLayout> |
||||||
@ -1,28 +1,21 @@ |
|||||||
<?xml version="1.0" encoding="utf-8"?> |
<?xml version="1.0" encoding="utf-8"?> |
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
|
||||||
xmlns:tools="http://schemas.android.com/tools" |
xmlns:tools="http://schemas.android.com/tools" |
||||||
android:layout_width="match_parent" |
android:layout_width="match_parent" |
||||||
android:layout_height="wrap_content" |
android:layout_height="wrap_content" |
||||||
|
android:orientation="vertical" |
||||||
android:background="@color/gray_dark"> |
android:background="@color/gray_dark"> |
||||||
|
|
||||||
<androidx.appcompat.widget.Toolbar |
<androidx.appcompat.widget.Toolbar |
||||||
android:id="@+id/bottomSheetToolbar" |
android:id="@+id/bottomSheetToolbar" |
||||||
android:layout_width="0dp" |
|
||||||
style="@style/PokerAnalyticsTheme.Toolbar" |
style="@style/PokerAnalyticsTheme.Toolbar" |
||||||
|
android:layout_width="match_parent" |
||||||
android:layout_height="?actionBarSize" |
android:layout_height="?actionBarSize" |
||||||
app:layout_constraintEnd_toEndOf="parent" |
|
||||||
app:layout_constraintStart_toStartOf="parent" |
|
||||||
app:layout_constraintTop_toTopOf="parent" |
|
||||||
tools:title="Test" /> |
tools:title="Test" /> |
||||||
|
|
||||||
<FrameLayout |
<FrameLayout |
||||||
android:id="@+id/bottomSheetContainer" |
android:id="@+id/bottomSheetContainer" |
||||||
android:layout_width="0dp" |
android:layout_width="match_parent" |
||||||
android:layout_height="wrap_content" |
android:layout_height="wrap_content" /> |
||||||
app:layout_constraintBottom_toBottomOf="parent" |
|
||||||
app:layout_constraintEnd_toEndOf="parent" |
|
||||||
app:layout_constraintStart_toStartOf="parent" |
|
||||||
app:layout_constraintTop_toBottomOf="@+id/bottomSheetToolbar" /> |
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout> |
</LinearLayout> |
||||||
@ -1,27 +1,26 @@ |
|||||||
<?xml version="1.0" encoding="utf-8"?> |
<?xml version="1.0" encoding="utf-8"?> |
||||||
<androidx.constraintlayout.widget.ConstraintLayout |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
xmlns:android="http://schemas.android.com/apk/res/android" |
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||||
xmlns:tools="http://schemas.android.com/tools" |
xmlns:tools="http://schemas.android.com/tools" |
||||||
|
android:id="@+id/container" |
||||||
android:layout_width="match_parent" |
android:layout_width="match_parent" |
||||||
android:layout_height="wrap_content" |
android:layout_height="wrap_content" |
||||||
android:background="?selectableItemBackground" |
android:background="?selectableItemBackground" |
||||||
android:id="@+id/container" |
|
||||||
android:padding="16dp"> |
android:padding="16dp"> |
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView |
<androidx.appcompat.widget.AppCompatTextView |
||||||
android:id="@+id/title" |
android:id="@+id/title" |
||||||
android:layout_width="0dp" |
android:layout_width="0dp" |
||||||
android:layout_height="wrap_content" |
android:layout_height="wrap_content" |
||||||
app:layout_constraintEnd_toEndOf="parent" |
android:layout_marginStart="8dp" |
||||||
android:layout_marginEnd="8dp" |
|
||||||
android:layout_marginTop="8dp" |
android:layout_marginTop="8dp" |
||||||
|
android:layout_marginEnd="8dp" |
||||||
|
android:layout_marginBottom="8dp" |
||||||
android:textSize="20sp" |
android:textSize="20sp" |
||||||
tools:text="Data Type Title" |
app:layout_constraintBottom_toBottomOf="parent" |
||||||
app:layout_constraintTop_toTopOf="parent" |
app:layout_constraintEnd_toEndOf="parent" |
||||||
app:layout_constraintStart_toStartOf="parent" |
app:layout_constraintStart_toStartOf="parent" |
||||||
android:layout_marginStart="8dp" |
app:layout_constraintTop_toTopOf="parent" |
||||||
android:layout_marginBottom="8dp" |
tools:text="Data Type Title" /> |
||||||
app:layout_constraintBottom_toBottomOf="parent"/> |
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout> |
</androidx.constraintlayout.widget.ConstraintLayout> |
||||||
@ -1,22 +1,25 @@ |
|||||||
package net.pokeranalytics.android |
package net.pokeranalytics.android |
||||||
|
|
||||||
//import androidx.test.core.app.ApplicationProvider |
|
||||||
import io.realm.Realm |
import io.realm.Realm |
||||||
import io.realm.RealmConfiguration |
import io.realm.RealmConfiguration |
||||||
|
import org.junit.After |
||||||
|
import org.junit.Before |
||||||
|
|
||||||
open class RealmUnitTest { |
open class RealmUnitTest { |
||||||
|
|
||||||
companion object { |
lateinit var mockRealm: Realm |
||||||
|
|
||||||
fun realmInstance() : Realm { |
@Before |
||||||
|
fun setup() { |
||||||
// Application |
|
||||||
|
|
||||||
// Realm.init(ApplicationProvider.getApplicationContext<PokerAnalyticsApplication>()) |
|
||||||
val testConfig = RealmConfiguration.Builder().inMemory().name("test-realm").build() |
val testConfig = RealmConfiguration.Builder().inMemory().name("test-realm").build() |
||||||
return Realm.getInstance(testConfig) |
Realm.setDefaultConfiguration(testConfig) |
||||||
|
mockRealm = Realm.getDefaultInstance() |
||||||
} |
} |
||||||
|
|
||||||
|
@After |
||||||
|
@Throws(Exception::class) |
||||||
|
public fun tearDown() { |
||||||
|
mockRealm.close() |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
Loading…
Reference in new issue