summaryrefslogtreecommitdiff
path: root/src/test/scala/cookbook/UInt2VecOfBool.scala
diff options
context:
space:
mode:
authorjackkoenig2016-09-20 16:12:59 -0700
committerjackkoenig2016-09-21 20:18:06 -0700
commit7e5aef460e089b3dfd53ddd181f9384cc25145d7 (patch)
treed4642495686b50476d6569ebbc522d2d10923a9e /src/test/scala/cookbook/UInt2VecOfBool.scala
parentb18e98ba2d058c7dd24f96f005486b70c856aeca (diff)
Add Cookbook tests
These tests are intended to be the examples in the Chisel3 Wiki Cookbook.
Diffstat (limited to 'src/test/scala/cookbook/UInt2VecOfBool.scala')
-rw-r--r--src/test/scala/cookbook/UInt2VecOfBool.scala29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/test/scala/cookbook/UInt2VecOfBool.scala b/src/test/scala/cookbook/UInt2VecOfBool.scala
new file mode 100644
index 00000000..ad4a0334
--- /dev/null
+++ b/src/test/scala/cookbook/UInt2VecOfBool.scala
@@ -0,0 +1,29 @@
+// See LICENSE for license details.
+
+package cookbook
+
+import chisel3._
+
+/* ### How do I create a Vec of Bools from a UInt?
+ *
+ * Use the builtin function [[chisel3.core.Bits.toBools]] to create a Scala Seq of Bool,
+ * then wrap the resulting Seq in Vec(...)
+ */
+class UInt2VecOfBool extends CookbookTester(0) {
+ // Example
+ val uint = UInt(0xc)
+ val vec = Vec(uint.toBools)
+ printf(p"$vec") // Vec(0, 0, 1, 1)
+
+ // Test
+ assert(vec(0) === Bool(false))
+ assert(vec(1) === Bool(false))
+ assert(vec(2) === Bool(true))
+ assert(vec(3) === Bool(true))
+}
+
+class UInt2VecOfBoolSpec extends CookbookSpec {
+ "UInt2VecOfBool" should "work" in {
+ assertTesterPasses { new UInt2VecOfBool }
+ }
+}