parent
cf70562735
commit
1ccd36edc2
@ -1,24 +1,79 @@ |
||||
package net.pokeranalytics.android.model.realm |
||||
|
||||
import io.realm.RealmObject |
||||
import io.realm.annotations.PrimaryKey |
||||
import io.realm.RealmResults |
||||
import io.realm.annotations.LinkingObjects |
||||
import java.util.* |
||||
|
||||
|
||||
|
||||
open class TimeFrame : RealmObject() { |
||||
|
||||
// A start date |
||||
var startDate: Date = Date() |
||||
set(value) { |
||||
field = value |
||||
this.computeDuration() |
||||
if (this.session != null) { |
||||
this.notifyDateChange() |
||||
} |
||||
} |
||||
|
||||
// An end date |
||||
var endDate: Date? = null |
||||
set(value) { |
||||
field = value |
||||
this.computeDuration() |
||||
if (this.session != null) { |
||||
this.notifyDateChange() |
||||
} |
||||
} |
||||
|
||||
// The break duration |
||||
var breakDuration: Double = 0.0 |
||||
var breakDuration: Long = 0L |
||||
set(value) { |
||||
field = value |
||||
this.computeDuration() |
||||
} |
||||
|
||||
// the total duration |
||||
var duration: Double = 0.0 |
||||
var duration: Long = 0L |
||||
private set |
||||
|
||||
// indicates a state of pause |
||||
var paused: Boolean = false |
||||
|
||||
@LinkingObjects("timeFrame") |
||||
private val session: RealmResults<Session>? = null |
||||
|
||||
@LinkingObjects("timeFrame") |
||||
private val group: RealmResults<TimeFrameGroup>? = null |
||||
|
||||
private fun computeDuration() { |
||||
|
||||
var endDate: Date |
||||
if (this.endDate != null) { |
||||
endDate = this.endDate!! |
||||
} else { |
||||
endDate = Date() |
||||
} |
||||
this.duration = endDate.time - startDate.time - this.breakDuration |
||||
} |
||||
|
||||
private fun notifyDateChange() { |
||||
// val realm = Realm.getDefaultInstance() |
||||
// |
||||
// var query: RealmQuery<TimeFrame> = realm.where(TimeFrame::class.java) |
||||
// query.greaterThan("startDate", this.startDate.time) |
||||
// |
||||
// this.endDate?.let { endDate -> |
||||
// query.or() |
||||
// .greaterThan("startDate", endDate.time) |
||||
// .lessThan("endDate", endDate.time) |
||||
// } |
||||
// |
||||
// |
||||
// realm.close() |
||||
} |
||||
|
||||
} |
||||
|
||||
@ -1,17 +1,52 @@ |
||||
package net.pokeranalytics.android |
||||
|
||||
import net.pokeranalytics.android.calculus.* |
||||
import net.pokeranalytics.android.model.realm.TimeFrameGroup |
||||
import org.junit.Assert.fail |
||||
import org.junit.Test |
||||
|
||||
import org.junit.Assert.* |
||||
|
||||
/** |
||||
* Example local unit test, which will execute on the development machine (host). |
||||
* |
||||
* See [testing documentation](http://d.android.com/tools/testing). |
||||
*/ |
||||
|
||||
class ExampleUnitTest { |
||||
|
||||
class Grade(someValue: Double) : SessionInterface { |
||||
// override var serie: Serie = Serie(TimeFrame()) |
||||
override var value: Double = someValue |
||||
|
||||
override var serie: TimeFrameGroup = TimeFrameGroup() |
||||
override var estimatedHands: Double = 0.0 |
||||
override var bbNetResult: Double = 0.0 |
||||
override var bigBlindSessionCount: Int = 0 // 0 or 1 |
||||
override var buyin: Double = 0.0 |
||||
|
||||
} |
||||
|
||||
@Test |
||||
fun addition_isCorrect() { |
||||
assertEquals(4, 2 + 2) |
||||
fun testStats() { |
||||
|
||||
val grades: List<Grade> = listOf(Grade(someValue = 10.0), Grade(someValue = 20.0)) |
||||
val group = SessionGroup(name = "test", sessions = grades) |
||||
|
||||
val results: ComputedResults = Calculator.compute(group, Calculator.Options()) |
||||
|
||||
val sum = results.computedStat(Stat.NETRESULT) |
||||
if (sum != null) { |
||||
assert(sum.value == 30.0) |
||||
} else { |
||||
fail("No Net result stat") |
||||
} |
||||
|
||||
val average = results.computedStat(Stat.AVERAGE) |
||||
if (average != null) { |
||||
assert(average.value == 15.0) |
||||
} else { |
||||
fail("No AVERAGE stat") |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
Loading…
Reference in new issue