Skip to content

Commit

Permalink
fix: dimension.toString() displays "dimensionless" when dimension is …
Browse files Browse the repository at this point in the history
…None
  • Loading branch information
Peva Blanchard committed Jul 12, 2023
1 parent 25526aa commit e19d5f1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class Dimension(
private val elements: Map<String, Double>

override fun toString(): String {
if (elements.isEmpty()) {
return "dimensionless"
}
return elements.entries.joinToString(".") {
simpleDimToString(it)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ch.kleis.lcaplugin.core.lang.dimension

import kotlin.test.assertEquals
import org.junit.Test


class DimensionTest {

@Test
fun test_toString_whenNone() {
// given
val dimension = Dimension.None

// when
val actual = "$dimension"

// then
assertEquals("dimensionless", actual)
}

@Test
fun test_toString_whenSimpleDim() {
// given
val dimension = Dimension.of("something")

// when
val actual ="$dimension"

// then
assertEquals("something", actual)
}

@Test
fun test_toString_whenSmallPower() {
// given
val dimension = Dimension.of("something", 2)

// when
val actual ="$dimension"

// then
assertEquals("something²", actual)
}
}

0 comments on commit e19d5f1

Please sign in to comment.