summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/Counter.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/scala/chiselTests/Counter.scala')
-rw-r--r--src/test/scala/chiselTests/Counter.scala19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/Counter.scala b/src/test/scala/chiselTests/Counter.scala
index 34fdec8e..31bfe7eb 100644
--- a/src/test/scala/chiselTests/Counter.scala
+++ b/src/test/scala/chiselTests/Counter.scala
@@ -35,6 +35,19 @@ class WrapTester(max: Int) extends BasicTester {
}
}
+class RangeTester(r: Range) extends BasicTester {
+ val (cnt, wrap) = Counter(r)
+ val checkWrap = RegInit(false.B)
+
+ when(checkWrap) {
+ assert(cnt === r.head.U)
+ stop()
+ }.elsewhen(wrap) {
+ assert(cnt === r.last.U)
+ checkWrap := true.B
+ }
+}
+
class CounterSpec extends ChiselPropSpec {
property("Counter should count up") {
forAll(smallPosInts) { (max: Int) => assertTesterPasses{ new CountTester(max) } }
@@ -47,4 +60,10 @@ class CounterSpec extends ChiselPropSpec {
property("Counter should wrap") {
forAll(smallPosInts) { (max: Int) => assertTesterPasses{ new WrapTester(max) } }
}
+
+ property("Counter should handle a range") {
+ forAll(posRange) { (r: Range) =>
+ assertTesterPasses{ new RangeTester(r) }
+ }
+ }
}