mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Move tests to appropriate modules (#3377)
This commit is contained in:
parent
e1da9fda01
commit
9a6c78fcd1
7 changed files with 12 additions and 66 deletions
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2025 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.geeksville.mesh
|
||||
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import com.geeksville.mesh.ConfigProtos.Config.DisplayConfig.DisplayUnits
|
||||
import org.junit.After
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.meshtastic.core.model.MeshUser
|
||||
import org.meshtastic.core.model.NodeInfo
|
||||
import org.meshtastic.core.model.Position
|
||||
import java.util.Locale
|
||||
|
||||
class NodeInfoTest {
|
||||
private val model = MeshProtos.HardwareModel.ANDROID_SIM
|
||||
private val node =
|
||||
listOf(
|
||||
NodeInfo(4, MeshUser("+zero", "User Zero", "U0", model)),
|
||||
NodeInfo(5, MeshUser("+one", "User One", "U1", model), Position(37.1, 121.1, 35)),
|
||||
NodeInfo(6, MeshUser("+two", "User Two", "U2", model), Position(37.11, 121.1, 40)),
|
||||
NodeInfo(7, MeshUser("+three", "User Three", "U3", model), Position(37.101, 121.1, 40)),
|
||||
NodeInfo(8, MeshUser("+four", "User Four", "U4", model), Position(37.116, 121.1, 40)),
|
||||
)
|
||||
|
||||
private val currentDefaultLocale = LocaleListCompat.getDefault().get(0) ?: Locale.US
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
Locale.setDefault(Locale.US)
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
Locale.setDefault(currentDefaultLocale)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun distanceGood() {
|
||||
Assert.assertEquals(node[1].distance(node[2]), 1111)
|
||||
Assert.assertEquals(node[1].distance(node[3]), 111)
|
||||
Assert.assertEquals(node[1].distance(node[4]), 1779)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun distanceStrGood() {
|
||||
Assert.assertEquals(node[1].distanceStr(node[2], DisplayUnits.METRIC_VALUE), "1.1 km")
|
||||
Assert.assertEquals(node[1].distanceStr(node[3], DisplayUnits.METRIC_VALUE), "111 m")
|
||||
Assert.assertEquals(node[1].distanceStr(node[4], DisplayUnits.IMPERIAL_VALUE), "1.1 mi")
|
||||
Assert.assertEquals(node[1].distanceStr(node[3], DisplayUnits.IMPERIAL_VALUE), "364 ft")
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2025 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.geeksville.mesh
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.meshtastic.core.model.Position
|
||||
|
||||
class PositionTest {
|
||||
@Test
|
||||
fun degGood() {
|
||||
Assert.assertEquals(Position.degI(89.0), 890000000)
|
||||
Assert.assertEquals(Position.degI(-89.0), -890000000)
|
||||
|
||||
Assert.assertEquals(Position.degD(Position.degI(89.0)), 89.0, 0.01)
|
||||
Assert.assertEquals(Position.degD(Position.degI(-89.0)), -89.0, 0.01)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun givenPositionCreatedWithoutTime_thenTimeIsSet() {
|
||||
val position = Position(37.1, 121.1, 35)
|
||||
Assert.assertTrue(position.time != 0)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2025 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.geeksville.mesh.model
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.meshtastic.core.model.DeviceVersion
|
||||
|
||||
class DeviceVersionTest {
|
||||
/** make sure we match the python and device code behavior */
|
||||
@Test
|
||||
fun canParse() {
|
||||
assertEquals(10000, DeviceVersion("1.0.0").asInt)
|
||||
assertEquals(10101, DeviceVersion("1.1.1").asInt)
|
||||
assertEquals(12357, DeviceVersion("1.23.57").asInt)
|
||||
assertEquals(12357, DeviceVersion("1.23.57.abde123").asInt)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue