summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorJim Lawson2020-01-07 14:35:18 -0800
committerGitHub2020-01-07 14:35:18 -0800
commitc4aa70f64ad5ecd8a5557ad0e4777f245768d865 (patch)
treea447f56b55065bdc2f4e05e0195f050e2cb431db /src/test
parent2224274cc5a42caa1e74b45573b4c7c09c85d227 (diff)
parentd4300b9deae6dde7ce0f314ea73a9ca4a1c3868c (diff)
Merge branch 'master' into add-asbool-to-clock
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/chiselTests/IntervalSpec.scala44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/test/scala/chiselTests/IntervalSpec.scala b/src/test/scala/chiselTests/IntervalSpec.scala
index 863771a3..1e56d8a3 100644
--- a/src/test/scala/chiselTests/IntervalSpec.scala
+++ b/src/test/scala/chiselTests/IntervalSpec.scala
@@ -456,12 +456,54 @@ class IntervalSpec extends FreeSpec with Matchers with ChiselRunners {
() =>
new BasicTester {
val x = 5.I(range"[0,4]")
- }
+ }
).elaborate
}
}
}
+ "Interval literals creation handles edge cases" - {
+ "value at closed boundaries works" in {
+ val inputRange = range"[-6, 6].2"
+ val in1 = (-6.0).I(inputRange)
+ val in2 = 6.0.I(inputRange)
+ BigDecimal(in1.litValue()) / (1 << inputRange.binaryPoint.get) should be (-6)
+ BigDecimal(in2.litValue()) / (1 << inputRange.binaryPoint.get) should be (6)
+ intercept[ChiselException] {
+ (-6.25).I(inputRange)
+ }
+ intercept[ChiselException] {
+ (6.25).I(inputRange)
+ }
+ }
+ "value at open boundaries works" in {
+ val inputRange = range"(-6, 6).2"
+ val in1 = (-5.75).I(inputRange)
+ val in2 = 5.75.I(inputRange)
+ BigDecimal(in1.litValue()) / (1 << inputRange.binaryPoint.get) should be (-5.75)
+ BigDecimal(in2.litValue()) / (1 << inputRange.binaryPoint.get) should be (5.75)
+ intercept[ChiselException] {
+ (-6.0).I(inputRange)
+ }
+ intercept[ChiselException] {
+ (6.0).I(inputRange)
+ }
+ }
+ "values not precisely at open boundaries works but are converted to nearest match" in {
+ val inputRange = range"(-6, 6).2"
+ val in1 = (-5.95).I(inputRange)
+ val in2 = 5.95.I(inputRange)
+ BigDecimal(in1.litValue()) / (1 << inputRange.binaryPoint.get) should be (-5.75)
+ BigDecimal(in2.litValue()) / (1 << inputRange.binaryPoint.get) should be (5.75)
+ intercept[ChiselException] {
+ (-6.1).I(inputRange)
+ }
+ intercept[ChiselException] {
+ (6.1).I(inputRange)
+ }
+ }
+ }
+
"Let's take a look at the results of squeeze over small range" in {
assertTesterPasses {
new ClipSqueezeWrapDemo(