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

12 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-29 20:01 +0000

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

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

3# 

4# This file is part of the tsfpga project, a project platform for modern FPGA development. 

5# https://tsfpga.com 

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

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

8 

9# Third party libraries 

10import pytest 

11 

12# First party libraries 

13from tsfpga.math_utils import to_binary_string 

14 

15 

16def test_to_binary_string(): 

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

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

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

20 

21 with pytest.raises(ValueError) as exception_info: 

22 to_binary_string(int_value=15, result_width=3) 

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

24 

25 with pytest.raises(ValueError) as exception_info: 

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

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