-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Improve GramsValueFormatter + TwelveHourFormatter coverage
Signed-off-by: Leonardo Colman Lopes <[email protected]>
- Loading branch information
Showing
4 changed files
with
106 additions
and
1 deletion.
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
48 changes: 48 additions & 0 deletions
48
...rc/test/kotlin/br/com/colman/petals/statistics/graph/formatter/GramsValueFormatterTest.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,48 @@ | ||
package br.com.colman.petals.statistics.graph.formatter | ||
|
||
import com.github.mikephil.charting.data.Entry | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class GramsValueFormatterTest : FunSpec({ | ||
val formatter = GramsValueFormatter | ||
|
||
test("formats positive value with two decimal places") { | ||
val entry = Entry(0f, 123.456f) | ||
formatter.getFormattedValue(999f, entry, 0, null) shouldBe "123.46g" | ||
} | ||
|
||
test("formats exact two decimal places correctly") { | ||
val entry = Entry(0f, 7.89f) | ||
formatter.getFormattedValue(0f, entry, 0, null) shouldBe "7.89g" | ||
} | ||
|
||
test("rounds up correctly") { | ||
val entry = Entry(0f, 2.999f) | ||
formatter.getFormattedValue(0f, entry, 0, null) shouldBe "3.00g" | ||
} | ||
|
||
test("formats zero value correctly") { | ||
val entry = Entry(0f, 0f) | ||
formatter.getFormattedValue(0f, entry, 0, null) shouldBe "0.00g" | ||
} | ||
|
||
test("formats negative value correctly") { | ||
val entry = Entry(0f, -3.5f) | ||
formatter.getFormattedValue(0f, entry, 0, null) shouldBe "-3.50g" | ||
} | ||
|
||
test("handles null entry by showing '0.00g'") { | ||
formatter.getFormattedValue(0f, null, 0, null) shouldBe "0.00g" | ||
} | ||
|
||
test("ignores value parameter and uses entry.y") { | ||
val entry = Entry(0f, 5f) | ||
formatter.getFormattedValue(10f, entry, 0, null) shouldBe "5.00g" | ||
} | ||
|
||
test("formats large numbers correctly") { | ||
val entry = Entry(0f, 999999.999f) | ||
formatter.getFormattedValue(0f, entry, 0, null) shouldBe "1000000.00g" | ||
} | ||
}) |
56 changes: 56 additions & 0 deletions
56
...rc/test/kotlin/br/com/colman/petals/statistics/graph/formatter/TwelveHourFormatterTest.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,56 @@ | ||
package br.com.colman.petals.statistics.graph.formatter | ||
|
||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class TwelveHourFormatterTest : FunSpec({ | ||
val formatter = TwelveHourFormatter | ||
|
||
test("12.0 should return '12'") { | ||
formatter.getFormattedValue(12.0f, null) shouldBe "12" | ||
} | ||
|
||
test("0.0 should return '0'") { | ||
formatter.getFormattedValue(0.0f, null) shouldBe "0" | ||
} | ||
|
||
test("13.0 should return '1'") { | ||
formatter.getFormattedValue(13.0f, null) shouldBe "1" | ||
} | ||
|
||
test("24.0 should return '0'") { | ||
formatter.getFormattedValue(24.0f, null) shouldBe "0" | ||
} | ||
|
||
test("12.5 rounds to 13 and returns '1'") { | ||
formatter.getFormattedValue(12.5f, null) shouldBe "1" | ||
} | ||
|
||
test("11.5 rounds to 12 and returns '12'") { | ||
formatter.getFormattedValue(11.5f, null) shouldBe "12" | ||
} | ||
|
||
test("1.0 should return '1'") { | ||
formatter.getFormattedValue(1.0f, null) shouldBe "1" | ||
} | ||
|
||
test("23.0 should return '11'") { | ||
formatter.getFormattedValue(23.0f, null) shouldBe "11" | ||
} | ||
|
||
test("12.9 rounds to 13 and returns '1'") { | ||
formatter.getFormattedValue(12.9f, null) shouldBe "1" | ||
} | ||
|
||
test("11.4 rounds to 11 and returns '11'") { | ||
formatter.getFormattedValue(11.4f, null) shouldBe "11" | ||
} | ||
|
||
test("-1.0 should return '-1'") { | ||
formatter.getFormattedValue(-1.0f, null) shouldBe "-1" | ||
} | ||
|
||
test("-13.0 should return '-1'") { | ||
formatter.getFormattedValue(-13.0f, null) shouldBe "-1" | ||
} | ||
}) |