summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorAndrew Waterman2016-01-28 12:15:53 -0800
committerAndrew Waterman2016-01-28 12:15:53 -0800
commit7eff2b0a16e1ca982c227bd498720981c883686b (patch)
tree767a04718b16750b33dd4e2d629d3e836bb7f637 /src/test
parent6d37cc8b9d731fa4c844f097b11057c46771961b (diff)
parent41674d5e130f64d7489fdb8583b8f4ad88b64aeb (diff)
Merge branch 'master' into scalastyle
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/chiselTests/When.scala60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/When.scala b/src/test/scala/chiselTests/When.scala
new file mode 100644
index 00000000..b78e1c5a
--- /dev/null
+++ b/src/test/scala/chiselTests/When.scala
@@ -0,0 +1,60 @@
+// See LICENSE for license details.
+
+package chiselTests
+
+import org.scalatest._
+import Chisel._
+import Chisel.testers.BasicTester
+
+class WhenTester() extends BasicTester {
+ val cnt = Counter(4)
+ when(Bool(true)) { cnt.inc() }
+
+ val out = Wire(UInt(width=3))
+ when(cnt.value === UInt(0)) {
+ out := UInt(1)
+ } .elsewhen (cnt.value === UInt(1)) {
+ out := UInt(2)
+ } .elsewhen (cnt.value === UInt(2)) {
+ out := UInt(3)
+ } .otherwise {
+ out := UInt(0)
+ }
+
+ assert(out === cnt.value + UInt(1))
+
+ when(cnt.value === UInt(3)) {
+ stop()
+ }
+}
+
+class OverlappedWhenTester() extends BasicTester {
+ val cnt = Counter(4)
+ when(Bool(true)) { cnt.inc() }
+
+ val out = Wire(UInt(width=3))
+ when(cnt.value <= UInt(0)) {
+ out := UInt(1)
+ } .elsewhen (cnt.value <= UInt(1)) {
+ out := UInt(2)
+ } .elsewhen (cnt.value <= UInt(2)) {
+ out := UInt(3)
+ } .otherwise {
+ out := UInt(0)
+ }
+
+ assert(out === cnt.value + UInt(1))
+
+ when(cnt.value === UInt(3)) {
+ stop()
+ }
+}
+
+class WhenSpec extends ChiselFlatSpec {
+ "When, elsewhen, and otherwise with orthogonal conditions" should "work" in {
+ assert(execute{ new WhenTester })
+ }
+ "When, elsewhen, and otherwise with overlapped conditions" should "work" in {
+ assert(execute{ new OverlappedWhenTester })
+ }
+}