|
|
|
|
@ -7,6 +7,7 @@ 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.SessionSet |
|
|
|
|
import net.pokeranalytics.android.model.realm.TimeFrame |
|
|
|
|
import org.junit.Assert |
|
|
|
|
import org.junit.Assert.assertEquals |
|
|
|
|
@ -26,7 +27,7 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
|
|
|
|
|
// convenience extension |
|
|
|
|
fun Session.Companion.testInstance(netResult: Double, startDate: Date, endDate: Date?): Session { |
|
|
|
|
val session: Session = Session.newInstance() |
|
|
|
|
val session: Session = Session.newInstance(super.mockRealm, false) |
|
|
|
|
session.result?.netResult = netResult |
|
|
|
|
session.timeFrame?.setDate(startDate, endDate) |
|
|
|
|
return session |
|
|
|
|
@ -67,8 +68,8 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
|
|
|
|
|
realm.beginTransaction() |
|
|
|
|
|
|
|
|
|
s1.timeFrame?.setDate(sd1, ed1) // duration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800 |
|
|
|
|
s2.timeFrame?.setDate(sd2, ed2) // duration = 3h, hourly = 100, bb100 = 150 / 75 * 100 = +200 |
|
|
|
|
s1.timeFrame?.setDate(sd1, ed1) // netDuration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800 |
|
|
|
|
s2.timeFrame?.setDate(sd2, ed2) // netDuration = 3h, hourly = 100, bb100 = 150 / 75 * 100 = +200 |
|
|
|
|
|
|
|
|
|
realm.copyToRealmOrUpdate(s1) |
|
|
|
|
realm.copyToRealmOrUpdate(s2) |
|
|
|
|
@ -102,7 +103,7 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
if (duration != null) { |
|
|
|
|
assertEquals(4.0, duration.value, delta) |
|
|
|
|
} else { |
|
|
|
|
Assert.fail("No duration stat") |
|
|
|
|
Assert.fail("No netDuration stat") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val hourlyRate = results.computedStat(Stat.HOURLY_RATE) |
|
|
|
|
@ -207,7 +208,6 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
|
|
|
|
|
realm.insert(s1) |
|
|
|
|
realm.insert(s2) |
|
|
|
|
realm.commitTransaction() |
|
|
|
|
|
|
|
|
|
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm") |
|
|
|
|
|
|
|
|
|
@ -216,10 +216,9 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
val sd2 = sdf.parse("01/1/2019 08:00") |
|
|
|
|
val ed2 = sdf.parse("01/1/2019 11:00") |
|
|
|
|
|
|
|
|
|
realm.beginTransaction() |
|
|
|
|
|
|
|
|
|
s1.timeFrame?.setDate(sd1, ed1) // duration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800 |
|
|
|
|
s2.timeFrame?.setDate(sd2, ed2) // duration = 4h, hourly = 100, bb100 = 150 / 75 * 100 = +200 |
|
|
|
|
s1.timeFrame?.setDate(sd1, ed1) // netDuration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800 |
|
|
|
|
s2.timeFrame?.setDate(sd2, ed2) // netDuration = 4h, hourly = 100, bb100 = 150 / 75 * 100 = +200 |
|
|
|
|
|
|
|
|
|
realm.copyToRealmOrUpdate(s1) |
|
|
|
|
realm.copyToRealmOrUpdate(s2) |
|
|
|
|
@ -274,7 +273,6 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
realm.insert(s1) |
|
|
|
|
realm.insert(s2) |
|
|
|
|
realm.insert(s3) |
|
|
|
|
realm.commitTransaction() |
|
|
|
|
|
|
|
|
|
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm") |
|
|
|
|
|
|
|
|
|
@ -285,11 +283,9 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
val sd3 = sdf.parse("01/1/2019 03:00") |
|
|
|
|
val ed3 = sdf.parse("01/1/2019 06:00") |
|
|
|
|
|
|
|
|
|
realm.beginTransaction() |
|
|
|
|
|
|
|
|
|
s1.timeFrame?.setDate(sd1, ed1) // duration = 4h |
|
|
|
|
s2.timeFrame?.setDate(sd2, ed2) // duration = 4h |
|
|
|
|
s3.timeFrame?.setDate(sd3, ed3) // duration = 3h |
|
|
|
|
s1.timeFrame?.setDate(sd1, ed1) // netDuration = 4h |
|
|
|
|
s2.timeFrame?.setDate(sd2, ed2) // netDuration = 4h |
|
|
|
|
s3.timeFrame?.setDate(sd3, ed3) // netDuration = 3h |
|
|
|
|
|
|
|
|
|
realm.copyToRealmOrUpdate(s1) |
|
|
|
|
realm.copyToRealmOrUpdate(s2) |
|
|
|
|
@ -370,9 +366,9 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
|
|
|
|
|
realm.beginTransaction() |
|
|
|
|
|
|
|
|
|
s1.timeFrame?.setDate(sd1, ed1) // duration = 4h |
|
|
|
|
s2.timeFrame?.setDate(sd2, ed2) // duration = 4h |
|
|
|
|
s3.timeFrame?.setDate(sd3, ed3) // duration = 3h |
|
|
|
|
s1.timeFrame?.setDate(sd1, ed1) // netDuration = 4h |
|
|
|
|
s2.timeFrame?.setDate(sd2, ed2) // netDuration = 4h |
|
|
|
|
s3.timeFrame?.setDate(sd3, ed3) // netDuration = 3h |
|
|
|
|
|
|
|
|
|
realm.copyToRealmOrUpdate(s1) |
|
|
|
|
realm.copyToRealmOrUpdate(s2) |
|
|
|
|
@ -393,12 +389,9 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
if (duration != null) { |
|
|
|
|
assertEquals(8.0, duration.value, delta) |
|
|
|
|
} else { |
|
|
|
|
Assert.fail("No duration stat") |
|
|
|
|
Assert.fail("No netDuration stat") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// realm.beginTransaction() |
|
|
|
|
// s1.deleteFromRealm() |
|
|
|
|
// realm.commitTransaction() |
|
|
|
|
realm.executeTransaction { |
|
|
|
|
s1.deleteFromRealm() |
|
|
|
|
} |
|
|
|
|
@ -414,4 +407,112 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
fun testSessionSetCount() { |
|
|
|
|
|
|
|
|
|
val realm = this.mockRealm |
|
|
|
|
|
|
|
|
|
realm.beginTransaction() |
|
|
|
|
val s1 = realm.createObject(Session::class.java, "1") |
|
|
|
|
|
|
|
|
|
s1.timeFrame = realm.createObject(TimeFrame::class.java) |
|
|
|
|
|
|
|
|
|
s1.result = realm.createObject(net.pokeranalytics.android.model.realm.Result::class.java) |
|
|
|
|
|
|
|
|
|
realm.insert(s1) |
|
|
|
|
|
|
|
|
|
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm") |
|
|
|
|
|
|
|
|
|
val sd1 = sdf.parse("01/1/2019 09:00") |
|
|
|
|
val ed1 = sdf.parse("01/1/2019 10:00") |
|
|
|
|
|
|
|
|
|
s1.timeFrame?.setDate(sd1, ed1) // netDuration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800 |
|
|
|
|
|
|
|
|
|
realm.copyToRealmOrUpdate(s1) |
|
|
|
|
realm.commitTransaction() |
|
|
|
|
|
|
|
|
|
val sets = realm.where(SessionSet::class.java).findAll() |
|
|
|
|
|
|
|
|
|
Assert.assertEquals(1, sets.size) |
|
|
|
|
|
|
|
|
|
val set = sets.first() |
|
|
|
|
if (set != null) { |
|
|
|
|
Assert.assertEquals(sd1.time, set.timeFrame?.startDate?.time) |
|
|
|
|
Assert.assertEquals(ed1.time, set.timeFrame?.endDate?.time) |
|
|
|
|
} else { |
|
|
|
|
Assert.fail("No set") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
fun testSessionSetCount2() { |
|
|
|
|
|
|
|
|
|
val realm = this.mockRealm |
|
|
|
|
|
|
|
|
|
realm.beginTransaction() |
|
|
|
|
val s1 = realm.createObject(Session::class.java, "1") |
|
|
|
|
val 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) |
|
|
|
|
|
|
|
|
|
realm.insert(s1) |
|
|
|
|
realm.insert(s2) |
|
|
|
|
|
|
|
|
|
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm") |
|
|
|
|
|
|
|
|
|
val sd1 = sdf.parse("01/1/2019 09:00") |
|
|
|
|
val ed1 = sdf.parse("01/1/2019 10:00") |
|
|
|
|
val sd2 = sdf.parse("01/2/2018 09:00") |
|
|
|
|
val ed2 = sdf.parse("01/2/2018 10:00") |
|
|
|
|
|
|
|
|
|
s1.timeFrame?.let { |
|
|
|
|
it.setStart(sd1) |
|
|
|
|
it.setEnd(ed1) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
s2.timeFrame?.let { |
|
|
|
|
it.setStart(sd2) |
|
|
|
|
it.setEnd(ed2) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// s1.timeFrame?.setDate(sd1, ed1) // netDuration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800 |
|
|
|
|
// s2.timeFrame?.setDate(sd2, ed2) // netDuration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800 |
|
|
|
|
|
|
|
|
|
realm.copyToRealmOrUpdate(s1) |
|
|
|
|
realm.copyToRealmOrUpdate(s2) |
|
|
|
|
|
|
|
|
|
realm.commitTransaction() |
|
|
|
|
|
|
|
|
|
val sets = realm.where(SessionSet::class.java).findAll() |
|
|
|
|
|
|
|
|
|
Assert.assertEquals(2, sets.size) |
|
|
|
|
|
|
|
|
|
// val set = sets.first() |
|
|
|
|
// if (set != null) { |
|
|
|
|
// Assert.assertEquals(sd1.time, set.timeFrame?.startDate?.time) |
|
|
|
|
// Assert.assertEquals(ed1.time, set.timeFrame?.endDate?.time) |
|
|
|
|
// } else { |
|
|
|
|
// Assert.fail("No set") |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// @Test |
|
|
|
|
// fun testDurationConversion() { |
|
|
|
|
// |
|
|
|
|
// val duration = 6.7555561274509826 |
|
|
|
|
// val longDuration = duration.toLong() |
|
|
|
|
// val formatted = longDuration.toMinutes() |
|
|
|
|
// |
|
|
|
|
// assert(formatted == "11:00") |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |