kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
add distance unit test and fix bug reported via crashyltics
rodzic
3e29ebe0c0
commit
49ed2b8e1f
|
@ -125,7 +125,7 @@ data class NodeInfo(
|
|||
fun distanceStr(o: NodeInfo?) = distance(o)?.let { dist ->
|
||||
when {
|
||||
dist == 0 -> null // same point
|
||||
dist < 1000 -> "%.0f m".format(dist)
|
||||
dist < 1000 -> "%.0f m".format(dist.toDouble())
|
||||
else -> "%.1f km".format(dist / 1000.0)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package com.geeksville.mesh
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class NodeInfoTest {
|
||||
val ni1 = NodeInfo(4, MeshUser("+one", "User One", "U1"), Position(37.1, 121.1, 35))
|
||||
val ni2 = NodeInfo(5, MeshUser("+two", "User Two", "U2"), Position(37.11, 121.1, 40))
|
||||
val ni3 = NodeInfo(6, MeshUser("+three", "User Three", "U3"), Position(37.101, 121.1, 40))
|
||||
|
||||
@Test
|
||||
fun distanceGood() {
|
||||
Assert.assertEquals(ni1.distance(ni2), 1111)
|
||||
Assert.assertEquals(ni1.distance(ni3), 111)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun distanceStrGood() {
|
||||
Assert.assertEquals(ni1.distanceStr(ni2), "1.1 km")
|
||||
Assert.assertEquals(ni1.distanceStr(ni3), "111 m")
|
||||
}
|
||||
}
|
Ładowanie…
Reference in New Issue