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.

154 lines
2.7 KiB

  1. #include "unity.h"
  2. #include "conversionOfNumbers.h"
  3. #include <stdlib.h>
  4. void setUp(){}
  5. void tearDown(){}
  6. void test_convert2ToBinaryStr10(){
  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_convert10ToBinaryStr1010(){
  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_convertNegative12ToBinaryStrNegative1100(){
  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_convert3ToHexStr3(){
  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_convert12ToHexStrC(){
  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. }