Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. #=========================================================================
  2. # IntMulFL_test
  3. #=========================================================================
  4.  
  5. import pytest
  6.  
  7. from pymtl3 import *
  8. from pymtl3.stdlib.test import mk_test_case_table
  9. from lab1_imul.IntMulFL import imul_fl
  10.  
  11. #----------------------------------------------------------------------
  12. # Test Case: small positive * positive
  13. #----------------------------------------------------------------------
  14.  
  15. small_pos_pos_msgs = [
  16. ( 2, 3, 6 ),
  17. ( 4, 5, 20 ),
  18. ( 3, 4, 12 ),
  19. ( 10, 13, 130 ),
  20. ( 8, 7, 56 ),
  21. ]
  22.  
  23. #----------------------------------------------------------------------
  24. # Test Case: small negative * positive
  25. #----------------------------------------------------------------------
  26.  
  27. small_neg_pos_msgs = [
  28. ( -2, 3, -6 ),
  29. ( -4, 5, -20 ),
  30. ( -3, 4, -12 ),
  31. ( -10, 13, -130 ),
  32. ( -8, 7, -56 ),
  33. ]
  34.  
  35. #----------------------------------------------------------------------
  36. # Test Case: small positive * negative
  37. #----------------------------------------------------------------------
  38.  
  39. small_pos_neg_msgs = [
  40. ( 2, -3, -6 ),
  41. ( 4, -5, -20 ),
  42. ( 3, -4, -12 ),
  43. ( 10, -13, -130 ),
  44. ( 8, -7, -56 ),
  45. ]
  46.  
  47. #----------------------------------------------------------------------
  48. # Test Case: small negative * negative
  49. #----------------------------------------------------------------------
  50.  
  51. small_neg_neg_msgs = [
  52. ( -2, -3, 6 ),
  53. ( -4, -5, 20 ),
  54. ( -3, -4, 12 ),
  55. ( -10, -13, 130 ),
  56. ( -8, -7, 56 ),
  57. ]
  58.  
  59. #----------------------------------------------------------------------
  60. # Test Case: large positive * positive
  61. #----------------------------------------------------------------------
  62.  
  63. large_pos_pos_msgs = [
  64. ( 0x0bcd0000, 0x0000abcd, 0x62290000 ),
  65. ( 0x0fff0000, 0x0000ffff, 0xf0010000 ),
  66. ( 0x0fff0000, 0x0fff0000, 0x00000000 ),
  67. ( 0x04e5f14d, 0x7839d4fc, 0x10524bcc ),
  68. ]
  69.  
  70. #----------------------------------------------------------------------
  71. # Test Case: large negative * negative
  72. #----------------------------------------------------------------------
  73.  
  74. large_neg_neg_msgs = [
  75. ( 0x80000001, 0x80000001, 0x00000001 ),
  76. ( 0x8000abcd, 0x8000ef00, 0x20646300 ),
  77. ( 0x80340580, 0x8aadefc0, 0x6fa6a000 ),
  78. ]
  79.  
  80. #----------------------------------------------------------------------
  81. # Test Case: zeros
  82. #----------------------------------------------------------------------
  83.  
  84. zeros_msgs = [
  85. ( 0, 0, 0 ),
  86. ( 0, 1, 0 ),
  87. ( 1, 0, 0 ),
  88. ( 0, -1, 0 ),
  89. ( -1, 0, 0 ),
  90. ]
  91.  
  92. #-------------------------------------------------------------------------
  93. # Test Case Table
  94. #-------------------------------------------------------------------------
  95.  
  96. test_case_table = mk_test_case_table([
  97. ( "msgs "),
  98. [ "small_pos_pos", small_pos_pos_msgs ],
  99. [ "small_neg_pos", small_neg_pos_msgs ],
  100. [ "small_pos_neg", small_pos_neg_msgs ],
  101. [ "small_neg_neg", small_neg_neg_msgs ],
  102. [ "large_pos_pos", large_pos_pos_msgs ],
  103. [ "large_neg_neg", large_neg_neg_msgs ],
  104. [ "zeros", zeros_msgs, ],
  105. ])
  106.  
  107. #-------------------------------------------------------------------------
  108. # Test cases
  109. #-------------------------------------------------------------------------
  110.  
  111. @pytest.mark.parametrize( **test_case_table )
  112. def test( test_params ):
  113. for a, b, result in test_params.msgs:
  114. assert imul_fl( a, b ) == b32( result )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement