summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChick Markley2020-01-02 15:16:46 -0800
committerGitHub2020-01-02 15:16:46 -0800
commit4ad624265e2b8aef5771af71006431705bdb19df (patch)
tree9ab760060a01227a74d54caaf61d842ba84d50c8 /src
parent98a6710cc0447d79cbd12271ea450c70e619b6f8 (diff)
parent9417b3a4f743446f978cc8268660878f4af87534 (diff)
Merge pull request #1275 from freechipsproject/interval-fix-2
Fixed problem creating Interval literals with full ranges
Diffstat (limited to 'src')
-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(