From d76fc668100fa175b0ce9285758895b2de9af638 Mon Sep 17 00:00:00 2001
From: Yaman Umuroglu <maltanar@gmail.com>
Date: Wed, 20 Nov 2019 17:55:00 +0000
Subject: [PATCH] [Test] add test_numpy_to_hls_code

---
 tests/test_npy2hls.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/tests/test_npy2hls.py b/tests/test_npy2hls.py
index e205c06f3..ea54d900a 100644
--- a/tests/test_npy2hls.py
+++ b/tests/test_npy2hls.py
@@ -1,5 +1,6 @@
 import numpy as np
 
+from finn.backend.fpgadataflow.utils import numpy_to_hls_code
 from finn.core.datatype import DataType
 from finn.core.utils import array2hexstring, pack_innermost_dim_as_hex_string
 
@@ -23,3 +24,20 @@ def test_pack_innermost_dim_as_hex_string():
     B = [[[3, 3], [3, 3]], [[1, 3], [3, 1]]]
     eB = np.asarray([["0f", "0f"], ["07", "0d"]])
     assert (pack_innermost_dim_as_hex_string(B, DataType.UINT2, 8) == eB).all()
+
+
+def test_numpy_to_hls_code():
+    def remove_all_whitespace(s):
+        return "".join(s.split())
+
+    A = [[1, 1, 1, 0], [0, 1, 1, 0]]
+    ret = numpy_to_hls_code(A, DataType.BINARY, "test", True)
+    eA = """ap_uint<4> test[2] =
+    {ap_uint<4>("e", 16), ap_uint<4>("6", 16)};"""
+    assert remove_all_whitespace(ret) == remove_all_whitespace(eA)
+    B = [[[3, 3], [3, 3]], [[1, 3], [3, 1]]]
+    ret = numpy_to_hls_code(B, DataType.UINT2, "test", True)
+    eB = """ap_uint<4> test[2][2] =
+    {{ap_uint<4>("f", 16), ap_uint<4>("f", 16)},
+     {ap_uint<4>("7", 16), ap_uint<4>("d", 16)}};"""
+    assert remove_all_whitespace(ret) == remove_all_whitespace(eB)
-- 
GitLab