Skip to content

Commit

Permalink
Fix parsing numbers below 1
Browse files Browse the repository at this point in the history
Signed-off-by: mueller-ma <[email protected]>
  • Loading branch information
mueller-ma committed Dec 26, 2023
1 parent 39cfe3c commit 3dfed8f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions mobile/src/test/java/org/openhab/habdroid/model/ParsedStateTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2010-2023 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.openhab.habdroid.model

import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

class ParsedStateTest {
@Test
fun testParseAsBoolean() {
listOf("ON", "100", "1", "0.1").forEach {
assertTrue("State $it should be parsed as true", ParsedState.parseAsBoolean(it))
}
listOf("OFF", "0").forEach {
assertFalse("State $it should be parsed as false", ParsedState.parseAsBoolean(it))
}
}

@Test
fun testParseAsNumber() {
mapOf(
"ON" to 100f,
"OFF" to 0f,
"3" to 3f,
"0" to 0f,
"42.42" to 42.42f
).forEach {
assertEquals("${it.key} should be parsed as ${it.value}", ParsedState.NumberState(it.value), ParsedState.parseAsNumber(it.key, null))
}
}
}

0 comments on commit 3dfed8f

Please sign in to comment.