Coverage for tsfpga/test/unit/test_math_utils.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v6.4, created at 2022-05-28 04:01 +0000

1# -------------------------------------------------------------------------------------------------- 

2# Copyright (c) Lukas Vik. All rights reserved. 

3# 

4# This file is part of the tsfpga project. 

5# https://tsfpga.com 

6# https://gitlab.com/tsfpga/tsfpga 

7# -------------------------------------------------------------------------------------------------- 

8 

9import pytest 

10 

11from tsfpga.math_utils import to_binary_string 

12 

13 

14def test_to_binary_string(): 

15 assert to_binary_string(int_value=2, result_width=3) == "010" 

16 assert to_binary_string(int_value=15, result_width=4) == "1111" 

17 assert to_binary_string(int_value=0, result_width=5) == "00000" 

18 

19 with pytest.raises(ValueError) as exception_info: 

20 to_binary_string(int_value=15, result_width=3) 

21 assert str(exception_info.value) == "Value 15 does not fit in 3 bits" 

22 

23 with pytest.raises(ValueError) as exception_info: 

24 to_binary_string(int_value=-7, result_width=10) 

25 assert str(exception_info.value) == "Negative value -7 not supported"