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.

104 lines
1.8 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. }