diff options
Diffstat (limited to 'src/test/scala')
| -rw-r--r-- | src/test/scala/chiselTests/FixedPointSpec.scala | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/test/scala/chiselTests/FixedPointSpec.scala b/src/test/scala/chiselTests/FixedPointSpec.scala index 69015e42..a08de073 100644 --- a/src/test/scala/chiselTests/FixedPointSpec.scala +++ b/src/test/scala/chiselTests/FixedPointSpec.scala @@ -7,7 +7,7 @@ import chisel3.testers.BasicTester import org.scalatest._ //scalastyle:off magic.number -class FixedPointSpec extends FlatSpec with Matchers { +class FixedPointLiteralSpec extends FlatSpec with Matchers { behavior of "fixed point utilities" they should "allow conversion between doubles and the bigints needed to represent them" in { @@ -19,6 +19,22 @@ class FixedPointSpec extends FlatSpec with Matchers { } } +class FixedPointFromBitsTester extends BasicTester { + val uint = 3.U(4.W) + val sint = -3.S + val fp_tpe = FixedPoint(4.W, 1.BP) + val uint_result = FixedPoint.fromDouble(1.5, width = 4, binaryPoint = 1) + val sint_result = FixedPoint.fromDouble(-1.5, width = 4, binaryPoint = 1) + + val uint2fp = fp_tpe.fromBits(uint) + val sint2fp = fp_tpe.fromBits(sint) + + assert(uint2fp === uint_result) + assert(sint2fp === sint_result) + + stop() +} + class SBP extends Module { val io = IO(new Bundle { val in = Input(FixedPoint(6, 2)) @@ -34,8 +50,12 @@ class SBPTester extends BasicTester { stop() } -class SBPSpec extends ChiselPropSpec { + +class FixedPointSpec extends ChiselPropSpec { property("should allow set binary point") { assertTesterPasses { new SBPTester } } + property("should allow fromBits") { + assertTesterPasses { new FixedPointFromBitsTester } + } } |
