You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
3.7 KiB

  1. #include "unity.h"
  2. #include "conversionOfNumbers.h"
  3. #include <stdlib.h>
  4. void setUp(){}
  5. void tearDown(){}
  6. void test_convertNum2ToBinaryStr10(){
  7. //arrange
  8. char* result;
  9. char expected[] = "10";
  10. //act
  11. result = convertIntToBinaryStr(2);
  12. //assert
  13. TEST_ASSERT_EQUAL_STRING(expected, result);
  14. free(result);
  15. }
  16. void test_binaryStringLengthOfInput5is3(){
  17. //arrange
  18. int result;
  19. int expected = 3;
  20. //act
  21. result = binaryStrLen(5);
  22. //assert
  23. TEST_ASSERT_EQUAL_INT(expected, result);
  24. }
  25. void test_binaryStringLengthOfInput0is1(){
  26. //arrange
  27. int result;
  28. int expected = 1;
  29. //act
  30. result = binaryStrLen(0);
  31. //assert
  32. TEST_ASSERT_EQUAL_INT(expected, result);
  33. }
  34. void test_convertNum10ToBinaryStr1010(){
  35. //arrange
  36. char* result;
  37. char expected[] = "1010";
  38. //act
  39. result = convertIntToBinaryStr(10);
  40. //assert
  41. TEST_ASSERT_EQUAL_STRING(expected, result);
  42. free(result);
  43. }
  44. void test_binaryStringLengthOfInputNegative10is5(){
  45. //arrange
  46. int result;
  47. int expected = 5;
  48. //act
  49. result = binaryStrLen(-10);
  50. //assert
  51. TEST_ASSERT_EQUAL_INT(expected, result);
  52. }
  53. void test_convertNegativeNum12ToBinaryStrNegative1100(){
  54. //arrange
  55. char* result;
  56. char expected[] = "-1100";
  57. //act
  58. result = convertIntToBinaryStr(-12);
  59. //assert
  60. TEST_ASSERT_EQUAL_STRING(expected, result);
  61. free(result);
  62. }
  63. void test_convertBinaryStr11ToInt3(){
  64. //arrange
  65. unsigned int result;
  66. unsigned int expected = 3;
  67. //act
  68. result = convertBinaryStrToInt("11");
  69. //assert
  70. TEST_ASSERT_EQUAL_UINT(expected, result);
  71. }
  72. void test_convertBinaryStr1111ToInt15(){
  73. //arrange
  74. unsigned int result;
  75. unsigned int expected = 15;
  76. //act
  77. result = convertBinaryStrToInt("1111");
  78. //assert
  79. TEST_ASSERT_EQUAL_UINT(expected, result);
  80. }
  81. void test_convertBinaryStr1001ToInt9(){
  82. //arrange
  83. unsigned int result;
  84. unsigned int expected = 9;
  85. //act
  86. result = convertBinaryStrToInt("1001");
  87. //assert
  88. TEST_ASSERT_EQUAL_UINT(expected, result);
  89. }
  90. void test_convertNum3ToHexStr3(){
  91. //arrange
  92. char* result;
  93. char expected[] = "3";
  94. //act
  95. result = convertIntToHex(3);
  96. //assert
  97. TEST_ASSERT_EQUAL_STRING(expected, result);
  98. free(result);
  99. }
  100. void test_convertNum12ToHexStrC(){
  101. //arrange
  102. char* result;
  103. char expected[] = "C";
  104. //act
  105. result = convertIntToHex(12);
  106. //assert
  107. TEST_ASSERT_EQUAL_STRING(expected, result);
  108. free(result);
  109. }
  110. void test_hexStringLengthOfInput256is3(){
  111. //arrange
  112. int result;
  113. int expected = 3;
  114. //act
  115. result = hexStrLen(256);
  116. //assert
  117. TEST_ASSERT_EQUAL_INT(expected, result);
  118. }
  119. void test_hexStringLengthOfInput255is2(){
  120. //arrange
  121. int result;
  122. int expected = 2;
  123. //act
  124. result = hexStrLen(255);
  125. //assert
  126. TEST_ASSERT_EQUAL_INT(expected, result);
  127. }
  128. void test_hexStringLengthOfInput0is1(){
  129. //arrange
  130. int result;
  131. int expected = 1;
  132. //act
  133. result = hexStrLen(0);
  134. //assert
  135. TEST_ASSERT_EQUAL_INT(expected, result);
  136. }
  137. void test_convertNum234ToHexStrEA(){
  138. //arrange
  139. char* result;
  140. char expected[] = "EA";
  141. //act
  142. result = convertIntToHex(234);
  143. //assert
  144. TEST_ASSERT_EQUAL_STRING(expected, result);
  145. free(result);
  146. }
  147. void test_convertBinaryStr10110ToInt22(){
  148. //arrange
  149. unsigned int result;
  150. unsigned int expected = 22;
  151. //act
  152. result = convertBinaryStrToInt("10110");
  153. //assert
  154. TEST_ASSERT_EQUAL_UINT(expected, result);
  155. }
  156. void test_convertHexStr2A3ToInt675(){
  157. //arrange
  158. unsigned int result;
  159. unsigned int expected = 675;
  160. //act
  161. result = convertHexStrToInt("2A3");
  162. //assert
  163. TEST_ASSERT_EQUAL_UINT(expected, result);
  164. }