-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from kleis-technology/feature/improve-ui
cli: refactored flags, added argument override
- Loading branch information
Showing
8 changed files
with
207 additions
and
51 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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,73 @@ | ||
package ch.kleis.lcaac.cli.cmd | ||
|
||
import ch.kleis.lcaac.core.lang.evaluator.EvaluatorException | ||
import ch.kleis.lcaac.core.lang.expression.EDataRef | ||
import ch.kleis.lcaac.core.lang.expression.EQuantityScale | ||
import ch.kleis.lcaac.core.math.basic.BasicNumber | ||
import ch.kleis.lcaac.core.prelude.Prelude | ||
import org.junit.jupiter.api.assertThrows | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
|
||
class UtilsKtTest { | ||
|
||
@Test | ||
fun parseQuantityWithDefaultUnit_invalidExpression() { | ||
// given | ||
val s = "a@bc" | ||
val defaultUnit = Prelude.unitMap<BasicNumber>()["kg"]!! | ||
|
||
// when/then | ||
val actual = assertThrows<EvaluatorException> { parseQuantityWithDefaultUnit(s, defaultUnit) } | ||
assertEquals("'a@bc' is not a valid quantity", actual.message) | ||
} | ||
|
||
@Test | ||
fun parseQuantityWithDefaultUnit_invalidExpression_multipleParts() { | ||
// given | ||
val s = "12 3 4" | ||
val defaultUnit = Prelude.unitMap<BasicNumber>()["kg"]!! | ||
|
||
// when/then | ||
val actual = assertThrows<EvaluatorException> { parseQuantityWithDefaultUnit(s, defaultUnit) } | ||
assertEquals("'12 3 4' is not a valid quantity", actual.message) | ||
} | ||
|
||
@Test | ||
fun parseQuantityWithDefaultUnit_invalidExpression_invalidUnit() { | ||
// given | ||
val s = "12 $3" | ||
val defaultUnit = Prelude.unitMap<BasicNumber>()["kg"]!! | ||
|
||
// when/then | ||
val actual = assertThrows<EvaluatorException> { parseQuantityWithDefaultUnit(s, defaultUnit) } | ||
assertEquals("'12 \$3' is not a valid quantity", actual.message) | ||
} | ||
|
||
@Test | ||
fun parseQuantityWithDefaultUnit_whenNumber() { | ||
// given | ||
val s = "12.0" | ||
val defaultUnit = Prelude.unitMap<BasicNumber>()["kg"]!! | ||
|
||
// when | ||
val actual = parseQuantityWithDefaultUnit(s, defaultUnit) | ||
|
||
// then | ||
assertEquals(EQuantityScale(BasicNumber(12.0), defaultUnit), actual) | ||
} | ||
|
||
@Test | ||
fun parseQuantityWithDefaultUnit_whenExpression() { | ||
// given | ||
val s = "12.0 kg" | ||
val defaultUnit = Prelude.unitMap<BasicNumber>()["kg"]!! | ||
|
||
// when | ||
val actual = parseQuantityWithDefaultUnit(s, defaultUnit) | ||
|
||
// then | ||
assertEquals(EQuantityScale(BasicNumber(12.0), EDataRef("kg")), actual) | ||
} | ||
} |
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