diff options
| author | Chick Markley | 2017-02-07 21:54:24 -0800 |
|---|---|---|
| committer | GitHub | 2017-02-07 21:54:24 -0800 |
| commit | 32885ac312c25e8f056ef7bddecbd00720548b96 (patch) | |
| tree | fb6bd7fd5224a535bf654e94a96890b2679a76e2 /src/test/scala/chiselTests/IntegerMathSpec.scala | |
| parent | c9beeeb1408f760309524f44a2dbd1c4f6d116b6 (diff) | |
Fix up Absolute value #abs (#491)
* Fix up Absolute value #abs
Defines #abs in Num
Implement #abs in UInt
Change #abs in SInt to return an SInt
Change #abs in FixedPoint to return a FixedPoint
Added a couple of tests
Add some scala style suppression to Bits so I can read code in IntelliJ
* Per review
Add tests that abs works for positive values
Added SInt and UInt tests for abs to new underpopulated IntegerMathSpec
Used fixed point literals in fixed points abs definition
Diffstat (limited to 'src/test/scala/chiselTests/IntegerMathSpec.scala')
| -rw-r--r-- | src/test/scala/chiselTests/IntegerMathSpec.scala | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/IntegerMathSpec.scala b/src/test/scala/chiselTests/IntegerMathSpec.scala new file mode 100644 index 00000000..3ccade8e --- /dev/null +++ b/src/test/scala/chiselTests/IntegerMathSpec.scala @@ -0,0 +1,33 @@ +// See LICENSE for license details. + +package chiselTests + +import chisel3._ +import chisel3.testers.BasicTester + +//scalastyle:off magic.number +class IntegerMathTester extends BasicTester { + + //TODO: Add more operators + + /* absolute values tests */ + + val uint = 3.U(4.W) + val sint = (-3).S() + val sintpos = 3.S() + val wrongSIntPos = 4.S() + + assert(uint.abs() === uint) + assert(sint.abs() === sintpos) + assert(sintpos.abs() === sintpos) + + assert(sint.abs() =/= wrongSIntPos) + + stop() +} + +class IntegerMathSpec extends ChiselPropSpec { + property("All integer ops should return the correct result") { + assertTesterPasses{ new IntegerMathTester } + } +} |
