|
|
package net.pokeranalytics.android
|
|
|
|
|
|
import kotlinx.serialization.json.Json
|
|
|
import kotlinx.serialization.json.JsonConfiguration
|
|
|
import net.pokeranalytics.android.util.CSVNumberFormat
|
|
|
import net.pokeranalytics.android.util.Parser
|
|
|
import net.pokeranalytics.android.util.extensions.kmbFormatted
|
|
|
import org.junit.Assert
|
|
|
import org.junit.Test
|
|
|
|
|
|
class BasicUnitTest : RealmUnitTest() {
|
|
|
|
|
|
@Test
|
|
|
fun testStats() {
|
|
|
Assert.assertEquals(0, 0)
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
fun testStandardFormatting() {
|
|
|
|
|
|
val s = "2222"
|
|
|
val p = s.toDouble()
|
|
|
|
|
|
Assert.assertEquals(2222.0, p, 0.001)
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
fun testFormatting() {
|
|
|
|
|
|
val n1 = 100.0
|
|
|
val n2 = 1000.0
|
|
|
val n3 = n2 * n2 // 1M
|
|
|
val n4 = n3 * n2 // 1B
|
|
|
|
|
|
val s1 = n1.kmbFormatted()
|
|
|
// val s2 = n2.kmbFormatted()
|
|
|
val s2b = n2.kmbFormatted(1000.0)
|
|
|
val s3 = n3.kmbFormatted()
|
|
|
val s4 = n4.kmbFormatted()
|
|
|
|
|
|
Assert.assertEquals("100", s1)
|
|
|
// Assert.assertEquals("1/e000", s2) // weird error Expected :1 000, Actual :1 000
|
|
|
Assert.assertEquals("1K", s2b)
|
|
|
Assert.assertEquals("1M", s3)
|
|
|
Assert.assertEquals("1B", s4)
|
|
|
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
fun testParser() {
|
|
|
|
|
|
val r1 = Parser.parseNumber("2")
|
|
|
Assert.assertNotNull(r1)
|
|
|
Assert.assertEquals(2, r1!!.toInt())
|
|
|
|
|
|
val r2 = Parser.parseNumber("gr")
|
|
|
Assert.assertNull(r2)
|
|
|
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
fun testCSVFormatter() {
|
|
|
val str1 = CSVNumberFormat.format(1111.2567)
|
|
|
Assert.assertEquals("1111.2567", str1)
|
|
|
|
|
|
val str2 = CSVNumberFormat.format(1000)
|
|
|
Assert.assertEquals("1000", str2)
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
fun testDeserialization() {
|
|
|
val json = Json(JsonConfiguration.Stable)
|
|
|
val f = json.parseJson("""{"a":42}""")
|
|
|
|
|
|
val v = f.jsonObject["a"]?.primitive?.int
|
|
|
|
|
|
Assert.assertEquals(true, f.contains("a"))
|
|
|
Assert.assertEquals(false, f.contains("b"))
|
|
|
Assert.assertEquals(42, v)
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
fun testDoWhile() {
|
|
|
|
|
|
var h = 0
|
|
|
var i = 0
|
|
|
do {
|
|
|
h++
|
|
|
} while (i < 0)
|
|
|
|
|
|
Assert.assertEquals(1, h)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|