diff options
| author | Henry Cook | 2015-08-14 01:51:39 -0700 |
|---|---|---|
| committer | Henry Cook | 2015-08-14 01:51:39 -0700 |
| commit | c23943b41de55de9af249a3b231558ad23fc8087 (patch) | |
| tree | 0d042d64c6b3e794bbdcae7241c79f83c721b917 /src/test/scala/chiselTests/Vec.scala | |
| parent | 5e9be183f98d32164332fa0548fe80686f50c851 (diff) | |
Add Vec tests. Do a better job of generating widths.
Diffstat (limited to 'src/test/scala/chiselTests/Vec.scala')
| -rw-r--r-- | src/test/scala/chiselTests/Vec.scala | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/Vec.scala b/src/test/scala/chiselTests/Vec.scala new file mode 100644 index 00000000..47e4af2c --- /dev/null +++ b/src/test/scala/chiselTests/Vec.scala @@ -0,0 +1,39 @@ +package chiselTests + +import Chisel._ +import org.scalatest._ +import org.scalatest.prop._ +import Chisel.testers.BasicTester + +class VecSpec extends ChiselPropSpec { + + class ValueTester(w: Int, values: List[Int]) extends BasicTester { + io.done := Bool(true) + val v = Vec(values.map(UInt(_, width = w))) + io.error := v.zip(values).map { case(a,b) => + a != UInt(b) + }.foldLeft(UInt(0))(_##_) + } + + property("Vecs should be assignable") { + forAll(safeUIntN(8)) { case(w: Int, v: List[Int]) => + assert(execute{ new ValueTester(w, v) }) + } + } + + class TabulateTester(w: Int, n: Int) extends BasicTester { + io.done := Bool(true) + val v = Vec(Range(0, n).map(i => UInt(i * 2))) + val x = Vec(Array.tabulate(n){ i => UInt(i * 2) }) + val u = Vec.tabulate(n)(i => UInt(i*2)) + when(v.toBits != x.toBits) { io.error := UInt(1) } + when(v.toBits != u.toBits) { io.error := UInt(2) } + when(x.toBits != u.toBits) { io.error := UInt(3) } + } + + property("Vecs should tabulate correctly") { + forAll(smallPosInts) { (n: Int) => + assert(execute{ new TabulateTester(n) }) + } + } +} |
