diff options
| author | Jim Lawson | 2020-01-07 14:31:42 -0800 |
|---|---|---|
| committer | GitHub | 2020-01-07 14:31:42 -0800 |
| commit | ce82ffaaeb2301af756b032c01e879e700299ea1 (patch) | |
| tree | 4e10201d02d43c560a8f22aae3263e6edfd63d0e /src/test | |
| parent | c720c99a75f565c8b4fbc7147d7b9daee9123d10 (diff) | |
| parent | d4300b9deae6dde7ce0f314ea73a9ca4a1c3868c (diff) | |
Merge branch 'master' into fix-bitpat-whitespace
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/scala/chiselTests/IntervalSpec.scala | 44 |
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( |
