-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bullet graph exception when using more than 4 qualitative ranges.
- Loading branch information
Showing
3 changed files
with
98 additions
and
2 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
83 changes: 83 additions & 0 deletions
83
src/desktopTest/kotlin/io/github/koalaplot/core/bar/BulletGraphTest.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,83 @@ | ||
package io.github.koalaplot.core.bar | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import io.github.koalaplot.core.util.ExperimentalKoalaPlotApi | ||
import io.github.koalaplot.core.xygraph.IntLinearAxisModel | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class BulletGraphTest { | ||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
/** | ||
* 5 default qualitative ranges allowed. | ||
*/ | ||
@OptIn(ExperimentalKoalaPlotApi::class) | ||
@Suppress("MagicNumber") | ||
@Test | ||
fun fiveDefaultRangesTest() { | ||
composeTestRule.setContent { | ||
BulletGraphs { | ||
bullet( | ||
IntLinearAxisModel(0..100) | ||
) { | ||
ranges(0, 10, 20, 30, 40, 50) | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Trying to use more than 5 qualitative ranges should fail with an IllegalArgumentException. | ||
*/ | ||
@OptIn(ExperimentalKoalaPlotApi::class) | ||
@Suppress("MagicNumber") | ||
@Test | ||
fun moreThanFiveDefaultRangesFailsTest() { | ||
composeTestRule.setContent { | ||
var caught = false | ||
|
||
BulletGraphs { | ||
bullet( | ||
IntLinearAxisModel(0..100) | ||
) { | ||
try { | ||
ranges(0, 10, 20, 30, 40, 50, 60) | ||
} catch (_: IllegalArgumentException) { | ||
caught = true | ||
} | ||
} | ||
} | ||
|
||
assert(caught) | ||
} | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
@OptIn(ExperimentalKoalaPlotApi::class) | ||
@Suppress("MagicNumber") | ||
@Test | ||
fun moreThanFiveCustomRangesTest() { | ||
composeTestRule.setContent { | ||
BulletGraphs { | ||
bullet( | ||
IntLinearAxisModel(0..100) | ||
) { | ||
|
||
ranges(0) { | ||
range(10) | ||
range(20) | ||
range(30) | ||
range(40) | ||
range(50) | ||
range(60) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |