package net.pokeranalytics.android.unitTests

import androidx.test.ext.junit.runners.AndroidJUnit4
import net.pokeranalytics.android.components.SessionInstrumentedUnitTest
import net.pokeranalytics.android.model.realm.Bankroll
import net.pokeranalytics.android.model.realm.Result
import net.pokeranalytics.android.model.realm.Session
import org.junit.Test
import org.junit.runner.RunWith
import java.util.*

@RunWith(AndroidJUnit4::class)
class StatPerformanceUnitTest : SessionInstrumentedUnitTest() {

	@Test
	fun testSessionNetResultOnLoad() {
		val realm = mockRealm
		realm.beginTransaction()

		val bankroll = realm.createObject(Bankroll::class.java, "1")
		bankroll.live = false

		for (index in 0..100) {
			Session.testInstance((-2000..2000).random().toDouble(), bankroll = bankroll)
			println("*** creating $index")
		}

		realm.commitTransaction()

		val d1 = Date()
		realm.where(Result::class.java).sum("netResult")

		val d2 = Date()
		val duration = (d2.time - d1.time)
		println("*** ended in $duration milliseconds")
	}

}