summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorchick2019-12-12 12:06:15 -0800
committerchick2019-12-12 12:06:15 -0800
commit6043ede715a44992975e60990fd2924b1ea6896a (patch)
tree0ab3451f52daa4f6de817e5a51aee1b6f9d98115 /src/test
parent954cc41e1349d0df6d2250d6270590340cd36e82 (diff)
Fixed problem creating Interval literals with full ranges
- boundary testing was not taking binary point into account correctly - add tests to show where things work and where they are supposed to fail
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(