|
|
|
@ -5,6 +5,7 @@ import net.pokeranalytics.android.model.realm.Session |
|
|
|
import net.pokeranalytics.android.model.realm.SessionSet |
|
|
|
import net.pokeranalytics.android.model.realm.SessionSet |
|
|
|
import org.junit.Assert.fail |
|
|
|
import org.junit.Assert.fail |
|
|
|
import org.junit.Test |
|
|
|
import org.junit.Test |
|
|
|
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Example local unit test, which will execute on the development machine (host). |
|
|
|
* Example local unit test, which will execute on the development machine (host). |
|
|
|
@ -12,7 +13,7 @@ import org.junit.Test |
|
|
|
* See [testing documentation](http://d.android.com/tools/testing). |
|
|
|
* See [testing documentation](http://d.android.com/tools/testing). |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
class ExampleUnitTest { |
|
|
|
class ExampleUnitTest : RealmUnitTest() { |
|
|
|
|
|
|
|
|
|
|
|
class Grade(someValue: Double) : SessionInterface { |
|
|
|
class Grade(someValue: Double) : SessionInterface { |
|
|
|
|
|
|
|
|
|
|
|
@ -26,7 +27,7 @@ class ExampleUnitTest { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
// @Test |
|
|
|
fun testStats() { |
|
|
|
fun testStats() { |
|
|
|
|
|
|
|
|
|
|
|
val grades: List<Grade> = listOf(Grade(10.0), Grade(20.0)) |
|
|
|
val grades: List<Grade> = listOf(Grade(10.0), Grade(20.0)) |
|
|
|
@ -50,24 +51,56 @@ class ExampleUnitTest { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// convenience extension |
|
|
|
|
|
|
|
fun Session.Companion.testInstance(netResult: Double, startDate: Date, endDate: Date?): Session { |
|
|
|
|
|
|
|
var session: Session = Session.newInstance() |
|
|
|
|
|
|
|
session.result?.netResult = netResult |
|
|
|
|
|
|
|
session.timeFrame?.setDate(startDate, endDate) |
|
|
|
|
|
|
|
return session |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testSessionStats() { |
|
|
|
fun testSessionStats() { |
|
|
|
|
|
|
|
|
|
|
|
val sessions: List<Session> = listOf(Session.testInstance(-10.0), Session.testInstance(20.0)) |
|
|
|
val realm = RealmUnitTest.realmInstance() |
|
|
|
|
|
|
|
realm.beginTransaction() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Calendar.getInstance().set(2019,1,1,10,0) |
|
|
|
|
|
|
|
val sd1 = Calendar.getInstance().time |
|
|
|
|
|
|
|
Calendar.getInstance().set(2019,1,1,11,0) |
|
|
|
|
|
|
|
val ed1 = Calendar.getInstance().time |
|
|
|
|
|
|
|
val s1 = Session.testInstance(-100.0, sd1, ed1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Calendar.getInstance().set(2019,1,2,8,0) |
|
|
|
|
|
|
|
val sd2 = Calendar.getInstance().time |
|
|
|
|
|
|
|
Calendar.getInstance().set(2019,1,2,11,0) |
|
|
|
|
|
|
|
val ed2 = Calendar.getInstance().time |
|
|
|
|
|
|
|
val s2 = Session.testInstance(300.0, sd2, ed2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val sessions: List<Session> = listOf(s1, s2) |
|
|
|
val group = SessionGroup(name = "test", sessions = sessions) |
|
|
|
val group = SessionGroup(name = "test", sessions = sessions) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
realm.commitTransaction() |
|
|
|
|
|
|
|
|
|
|
|
val results: ComputedResults = Calculator.compute(group, Calculator.Options()) |
|
|
|
val results: ComputedResults = Calculator.compute(group, Calculator.Options()) |
|
|
|
|
|
|
|
|
|
|
|
val sum = results.computedStat(Stat.NETRESULT) |
|
|
|
val sum = results.computedStat(Stat.NETRESULT) |
|
|
|
if (sum != null) { |
|
|
|
if (sum != null) { |
|
|
|
assert(sum.value == 10.0) { "sum is ${sum.value}" } |
|
|
|
assert(sum.value == 200.0) { "sum is ${sum.value}" } |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
fail("No Net result stat") |
|
|
|
fail("No Net result stat") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val average = results.computedStat(Stat.AVERAGE) |
|
|
|
val average = results.computedStat(Stat.AVERAGE) |
|
|
|
if (average != null) { |
|
|
|
if (average != null) { |
|
|
|
assert(average.value == 5.0) { "average is ${average.value}" } |
|
|
|
assert(average.value == 100.0) { "average is ${average.value}" } |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
fail("No AVERAGE stat") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val duration = results.computedStat(Stat.DURATION) |
|
|
|
|
|
|
|
if (duration != null) { |
|
|
|
|
|
|
|
assert(duration.value == 4.0) { "duration is ${duration.value}" } |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
fail("No AVERAGE stat") |
|
|
|
fail("No AVERAGE stat") |
|
|
|
} |
|
|
|
} |
|
|
|
|