forked from openhab/openhab-android
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: mueller-ma <[email protected]>
- Loading branch information
1 parent
39cfe3c
commit 3dfed8f
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
mobile/src/test/java/org/openhab/habdroid/model/ParsedStateTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} | ||
} |