summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorAndrew Waterman2019-03-14 02:04:05 -0700
committerEdward Wang2019-03-15 11:49:17 -0700
commit5744ce6df80ba9ec153b07744eb8da7a01876f2c (patch)
tree36ffe3d1eb74ddb5fb60d4ae68684a3d65b10553 /src/test
parent9120df2fac77b2ba7f0372e2ff9ad7f321d66978 (diff)
Add PopCount test
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/chiselTests/PopCount.scala25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/PopCount.scala b/src/test/scala/chiselTests/PopCount.scala
new file mode 100644
index 00000000..2c144382
--- /dev/null
+++ b/src/test/scala/chiselTests/PopCount.scala
@@ -0,0 +1,25 @@
+// See LICENSE for license details.
+
+package chiselTests
+
+import chisel3._
+import chisel3.util.PopCount
+import org.scalatest._
+import org.scalatest.prop._
+import chisel3.testers.BasicTester
+
+class PopCountTester(n: Int) extends BasicTester {
+ val x = RegInit(0.U(n.W))
+ x := x + 1.U
+ when (RegNext(x === ~0.U(n.W))) { stop() }
+
+ val result = PopCount(x.asBools)
+ val expected = x.asBools.foldLeft(0.U)(_ +& _)
+ assert(result === expected)
+}
+
+class PopCountSpec extends ChiselPropSpec {
+ property("Mul lookup table should return the correct result") {
+ forAll(smallPosInts) { (n: Int) => assertTesterPasses { new PopCountTester(n) } }
+ }
+}