|
|
|
|
@ -3,11 +3,11 @@ package net.pokeranalytics.android.unitTests |
|
|
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4 |
|
|
|
|
import io.realm.RealmList |
|
|
|
|
import io.realm.RealmResults |
|
|
|
|
import net.pokeranalytics.android.components.RealmInstrumentedUnitTest |
|
|
|
|
import net.pokeranalytics.android.calculus.Calculator |
|
|
|
|
import net.pokeranalytics.android.calculus.ComputableGroup |
|
|
|
|
import net.pokeranalytics.android.calculus.ComputedResults |
|
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
|
import net.pokeranalytics.android.components.RealmInstrumentedUnitTest |
|
|
|
|
import net.pokeranalytics.android.model.realm.* |
|
|
|
|
import net.pokeranalytics.android.model.realm.Currency |
|
|
|
|
import org.junit.Assert |
|
|
|
|
@ -33,7 +33,7 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
endDate: Int = 1, |
|
|
|
|
bankroll: Bankroll? = null, |
|
|
|
|
game: Game? = null, |
|
|
|
|
location : Location? = null, |
|
|
|
|
location: Location? = null, |
|
|
|
|
tournamentName: TournamentName? = null, |
|
|
|
|
tournamentFeatures: RealmList<TournamentFeature> = RealmList(), |
|
|
|
|
numberOfTable: Int = 1, |
|
|
|
|
@ -48,8 +48,8 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
session.limit = limit |
|
|
|
|
session.numberOfTables = numberOfTable |
|
|
|
|
session.tableSize = tableSize |
|
|
|
|
session.result?.netResult = netResult |
|
|
|
|
session.startDate = startDate |
|
|
|
|
session.result?.netResult = netResult |
|
|
|
|
val cal = Calendar.getInstance() // creates calendar |
|
|
|
|
cal.time = startDate // sets calendar time/date |
|
|
|
|
cal.add(Calendar.HOUR_OF_DAY, endDate) // adds one hour |
|
|
|
|
@ -81,6 +81,11 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
fun testSessionStats() { |
|
|
|
|
|
|
|
|
|
val realm = this.mockRealm |
|
|
|
|
|
|
|
|
|
val computableResults = realm.where(ComputableResult::class.java).findAll() |
|
|
|
|
|
|
|
|
|
assertEquals(0, computableResults.size) |
|
|
|
|
|
|
|
|
|
realm.beginTransaction() |
|
|
|
|
|
|
|
|
|
val s1 = newSessionInstance(realm) |
|
|
|
|
@ -95,10 +100,6 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
|
|
|
|
|
s2.tableSize = 5 |
|
|
|
|
|
|
|
|
|
realm.insert(s1) |
|
|
|
|
realm.insert(s2) |
|
|
|
|
realm.commitTransaction() |
|
|
|
|
|
|
|
|
|
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm") |
|
|
|
|
|
|
|
|
|
val sd1 = sdf.parse("01/1/2019 10:00") |
|
|
|
|
@ -106,19 +107,22 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
val sd2 = sdf.parse("02/1/2019 08:00") |
|
|
|
|
val ed2 = sdf.parse("02/1/2019 11:00") // 3 hours |
|
|
|
|
|
|
|
|
|
realm.beginTransaction() |
|
|
|
|
|
|
|
|
|
s1.startDate = sd1 |
|
|
|
|
s1.endDate = ed1 |
|
|
|
|
s2.startDate = sd2 |
|
|
|
|
s2.endDate = ed2 |
|
|
|
|
|
|
|
|
|
realm.copyToRealmOrUpdate(s1) |
|
|
|
|
realm.copyToRealmOrUpdate(s2) |
|
|
|
|
val d1 = s1.sessionSet?.netDuration |
|
|
|
|
val d2 = s2.sessionSet?.netDuration |
|
|
|
|
|
|
|
|
|
realm.commitTransaction() |
|
|
|
|
|
|
|
|
|
val computableResults = realm.where(ComputableResult::class.java).findAll() |
|
|
|
|
assertEquals(2, computableResults.size) |
|
|
|
|
|
|
|
|
|
computableResults.forEach { |
|
|
|
|
println(">>>>>> rated net = ${it.ratedNet} ") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val sets = realm.where(SessionSet::class.java).findAll() |
|
|
|
|
val stats: List<Stat> = listOf(Stat.NETRESULT, Stat.AVERAGE) |
|
|
|
|
val group = ComputableGroup("test", computableResults, sets, stats) |
|
|
|
|
@ -239,14 +243,12 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
fun testOverlappingSessions1() { |
|
|
|
|
|
|
|
|
|
val realm = this.mockRealm |
|
|
|
|
realm.beginTransaction() |
|
|
|
|
|
|
|
|
|
realm.executeTransaction { |
|
|
|
|
|
|
|
|
|
val s1 = newSessionInstance(realm) |
|
|
|
|
val s2 = newSessionInstance(realm) |
|
|
|
|
|
|
|
|
|
realm.insert(s1) |
|
|
|
|
realm.insert(s2) |
|
|
|
|
|
|
|
|
|
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm") |
|
|
|
|
|
|
|
|
|
val sd1 = sdf.parse("01/1/2019 09:00") |
|
|
|
|
@ -262,10 +264,7 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
// netDuration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800 |
|
|
|
|
// netDuration = 4h, hourly = 100, bb100 = 150 / 75 * 100 = +200 |
|
|
|
|
|
|
|
|
|
realm.copyToRealmOrUpdate(s1) |
|
|
|
|
realm.copyToRealmOrUpdate(s2) |
|
|
|
|
|
|
|
|
|
realm.commitTransaction() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val computableResults = realm.where(ComputableResult::class.java).findAll() |
|
|
|
|
val sets = realm.where(SessionSet::class.java).findAll() |
|
|
|
|
@ -474,7 +473,8 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
val sd1 = sdf.parse("01/1/2019 09:00") |
|
|
|
|
val ed1 = sdf.parse("01/1/2019 10:00") |
|
|
|
|
|
|
|
|
|
s1.startDate = sd1 // timeFrame?.setDate(sd1, ed1) // netDuration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800 |
|
|
|
|
s1.startDate = |
|
|
|
|
sd1 // timeFrame?.setDate(sd1, ed1) // netDuration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800 |
|
|
|
|
s1.endDate = ed1 |
|
|
|
|
|
|
|
|
|
realm.copyToRealmOrUpdate(s1) |
|
|
|
|
@ -624,7 +624,7 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
fun testRatedNetResultSessions() { |
|
|
|
|
|
|
|
|
|
val realm = this.mockRealm |
|
|
|
|
realm.beginTransaction() |
|
|
|
|
realm.executeTransaction { |
|
|
|
|
|
|
|
|
|
val s1 = newSessionInstance(realm) |
|
|
|
|
val s2 = newSessionInstance(realm) |
|
|
|
|
@ -644,13 +644,7 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
s1.result?.netResult = 100.0 |
|
|
|
|
s2.result?.netResult = 200.0 |
|
|
|
|
|
|
|
|
|
realm.insert(s1) |
|
|
|
|
realm.insert(s2) |
|
|
|
|
|
|
|
|
|
realm.copyToRealmOrUpdate(s1) |
|
|
|
|
realm.copyToRealmOrUpdate(s2) |
|
|
|
|
|
|
|
|
|
realm.commitTransaction() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val computableResults = realm.where(ComputableResult::class.java).findAll() |
|
|
|
|
val sets = realm.where(SessionSet::class.java).findAll() |
|
|
|
|
@ -667,7 +661,8 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
fun testUpdateRatedNetResultSessions() { |
|
|
|
|
|
|
|
|
|
val realm = this.mockRealm |
|
|
|
|
realm.beginTransaction() |
|
|
|
|
|
|
|
|
|
realm.executeTransaction { |
|
|
|
|
|
|
|
|
|
val s1 = newSessionInstance(realm) |
|
|
|
|
val s2 = newSessionInstance(realm) |
|
|
|
|
@ -687,13 +682,7 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
s1.result?.netResult = 100.0 |
|
|
|
|
s2.result?.netResult = 200.0 |
|
|
|
|
|
|
|
|
|
realm.insert(s1) |
|
|
|
|
realm.insert(s2) |
|
|
|
|
|
|
|
|
|
realm.copyToRealmOrUpdate(s1) |
|
|
|
|
realm.copyToRealmOrUpdate(s2) |
|
|
|
|
|
|
|
|
|
realm.commitTransaction() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val computableResults = realm.where(ComputableResult::class.java).findAll() |
|
|
|
|
val sets = realm.where(SessionSet::class.java).findAll() |
|
|
|
|
@ -708,7 +697,7 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
println("currency set rate real test starts here") |
|
|
|
|
|
|
|
|
|
val updatedC2 = realm.where(Currency::class.java).equalTo("id", "2").findFirst() |
|
|
|
|
updatedC2?.let {currency -> |
|
|
|
|
updatedC2?.let { currency -> |
|
|
|
|
val newC2 = realm.copyFromRealm(currency) |
|
|
|
|
newC2.rate = 3.0 |
|
|
|
|
realm.executeTransaction { |
|
|
|
|
|