|
|
|
@ -1,20 +1,31 @@ |
|
|
|
package net.pokeranalytics.android.unitTests |
|
|
|
package net.pokeranalytics.android.unitTests |
|
|
|
|
|
|
|
|
|
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4 |
|
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4 |
|
|
|
import net.pokeranalytics.android.components.RealmInstrumentedUnitTest |
|
|
|
import io.realm.Realm |
|
|
|
import net.pokeranalytics.android.calculus.Calculator |
|
|
|
import net.pokeranalytics.android.calculus.bankroll.BankrollCalculator |
|
|
|
import net.pokeranalytics.android.calculus.ComputableGroup |
|
|
|
import net.pokeranalytics.android.calculus.bankroll.BankrollReportSetup |
|
|
|
import net.pokeranalytics.android.calculus.ComputedResults |
|
|
|
import net.pokeranalytics.android.components.SessionInstrumentedUnitTest |
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
import net.pokeranalytics.android.model.realm.Bankroll |
|
|
|
import net.pokeranalytics.android.model.realm.* |
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
import net.pokeranalytics.android.model.realm.Currency |
|
|
|
import net.pokeranalytics.android.model.realm.Transaction |
|
|
|
|
|
|
|
import net.pokeranalytics.android.model.realm.TransactionType |
|
|
|
import org.junit.Assert |
|
|
|
import org.junit.Assert |
|
|
|
import org.junit.Test |
|
|
|
import org.junit.Test |
|
|
|
import org.junit.runner.RunWith |
|
|
|
import org.junit.runner.RunWith |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
|
|
@RunWith(AndroidJUnit4::class) |
|
|
|
@RunWith(AndroidJUnit4::class) |
|
|
|
class BankrollInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
class BankrollInstrumentedUnitTest : SessionInstrumentedUnitTest() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun createDefaultTransactionTypes(realm: Realm) { |
|
|
|
|
|
|
|
TransactionType.Value.values().forEachIndexed { index, value -> |
|
|
|
|
|
|
|
val type = TransactionType() |
|
|
|
|
|
|
|
type.additive = value.additive |
|
|
|
|
|
|
|
type.kind = index |
|
|
|
|
|
|
|
type.lock = true |
|
|
|
|
|
|
|
realm.insertOrUpdate(type) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// convenience extension |
|
|
|
// convenience extension |
|
|
|
fun Session.Companion.testInstance(netResult: Double, startDate: Date, endDate: Date?): Session { |
|
|
|
fun Session.Companion.testInstance(netResult: Double, startDate: Date, endDate: Date?): Session { |
|
|
|
@ -26,9 +37,45 @@ class BankrollInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testSessionStats() { |
|
|
|
fun testReport() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val realm = mockRealm |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
realm.executeTransaction { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.createDefaultTransactionTypes(realm) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var br1 = realm.createObject(Bankroll::class.java, "1") |
|
|
|
|
|
|
|
var br2 = realm.createObject(Bankroll::class.java, "2") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
br1.initialValue = 100.0 |
|
|
|
|
|
|
|
br2.initialValue = 1000.0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val t1 = realm.createObject(Transaction::class.java, UUID.randomUUID().toString()) |
|
|
|
|
|
|
|
t1.amount = 100.0 |
|
|
|
|
|
|
|
t1.bankroll = br1 |
|
|
|
|
|
|
|
t1.type = TransactionType.getByValue(TransactionType.Value.BONUS, realm) |
|
|
|
|
|
|
|
val t2 = realm.createObject(Transaction::class.java, UUID.randomUUID().toString()) |
|
|
|
|
|
|
|
t2.amount = 500.0 |
|
|
|
|
|
|
|
t2.bankroll = br2 |
|
|
|
|
|
|
|
t2.type = TransactionType.getByValue(TransactionType.Value.BONUS, realm) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val s1 = newSessionInstance(realm) |
|
|
|
|
|
|
|
s1.bankroll = br1 |
|
|
|
|
|
|
|
s1.result?.cashout = 200.0 |
|
|
|
|
|
|
|
val s2 = newSessionInstance(realm) |
|
|
|
|
|
|
|
s2.bankroll = br2 |
|
|
|
|
|
|
|
s2.result?.cashout = 500.0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val brSetup1 = BankrollReportSetup(br1) |
|
|
|
|
|
|
|
val report1 = BankrollCalculator.computeReport(brSetup1) |
|
|
|
|
|
|
|
Assert.assertEquals(400.0, report1.total, EPSILON) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val brSetup2 = BankrollReportSetup(br2) |
|
|
|
|
|
|
|
val report2 = BankrollCalculator.computeReport(brSetup2) |
|
|
|
|
|
|
|
Assert.assertEquals(2000.0, report2.total, EPSILON) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|