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.

136 lines
3.8 KiB

  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "addition.h"
  4. num carry[1];
  5. void setUp(void)
  6. {
  7. }
  8. void tearDown(void)
  9. {
  10. }
  11. void test_addition_full_adder_nullplusnullgleichnull(void)
  12. {
  13. num result[1];
  14. num expected = 0;
  15. full_adder(result, carry, 0, 0, 0);
  16. TEST_ASSERT_EQUAL_UINT(expected, result[0]);
  17. }
  18. void test_addition_full_adder_nullplusnullgleichnullmituebertrag(void)
  19. {
  20. num result[1];
  21. num expected = 1;
  22. full_adder(result, carry, 0, 0, 1);
  23. TEST_ASSERT_EQUAL_UINT(expected, result[0]);
  24. }
  25. void test_addition_full_adder_zahlpluszahlgleichsummeohneuebertrag(void)
  26. {
  27. num result[5];
  28. num expected[5] = { 0, 1, 1, 1, 1};
  29. full_adder((result+0), carry, 1, 0, 1);
  30. full_adder((result+1), carry, 0, 1, 0);
  31. full_adder((result+2), carry, 1, 0, 0);
  32. full_adder((result+3), carry, 0, 0, 1);
  33. full_adder((result+4), carry, 1, 1, 1);
  34. TEST_ASSERT_EQUAL_UINT(expected[0], result[0]);
  35. TEST_ASSERT_EQUAL_UINT(expected[1], result[1]);
  36. TEST_ASSERT_EQUAL_UINT(expected[2], result[2]);
  37. TEST_ASSERT_EQUAL_UINT(expected[3], result[3]);
  38. TEST_ASSERT_EQUAL_UINT(expected[4], result[4]);
  39. }
  40. void test_addition_full_adder_completesumwithcarry(void)
  41. {
  42. num result[5], carryresult[5];
  43. num expected[5] = { 0, 0, 1, 1, 0}, expectedcarry[5] = { 1, 1, 1, 0, 0};
  44. full_adder(result+0, carryresult+0, 0, 1, 1);
  45. full_adder(result+1, carryresult+1, 1, 1, 0);
  46. full_adder(result+2, carryresult+2, 1, 1, 1);
  47. full_adder(result+3, carryresult+3, 0, 1, 0);
  48. full_adder(result+4, carryresult+4, 0, 0, 0);
  49. TEST_ASSERT_EQUAL_UINT(expected[0], result[0]);
  50. TEST_ASSERT_EQUAL_UINT(expected[1], result[1]);
  51. TEST_ASSERT_EQUAL_UINT(expected[2], result[2]);
  52. TEST_ASSERT_EQUAL_UINT(expected[3], result[3]);
  53. TEST_ASSERT_EQUAL_UINT(expected[4], result[4]);
  54. TEST_ASSERT_EQUAL_UINT(expectedcarry[0], carryresult[0]);
  55. TEST_ASSERT_EQUAL_UINT(expectedcarry[1], carryresult[1]);
  56. TEST_ASSERT_EQUAL_UINT(expectedcarry[2], carryresult[2]);
  57. TEST_ASSERT_EQUAL_UINT(expectedcarry[3], carryresult[3]);
  58. TEST_ASSERT_EQUAL_UINT(expectedcarry[4], carryresult[4]);
  59. }
  60. void test_addition_addition_basecasezeropluszeroequalzero(void)
  61. {
  62. unsigned int result;
  63. unsigned int expected = 0;
  64. result = addition(0, 0);
  65. TEST_ASSERT_EQUAL_UINT(expected, result);
  66. }
  67. void test_addition_addition_basecaseonescolumns(void)
  68. {
  69. unsigned int result[2];
  70. unsigned int expected[2] = { 1, 1 };
  71. result[0] = addition(1, 0);
  72. result[1] = addition(0, 1);
  73. TEST_ASSERT_EQUAL_UINT(expected[0], result[0]);
  74. TEST_ASSERT_EQUAL_UINT(expected[1], result[1]);
  75. }
  76. void test_addition_addition_basecasetotenscolumns(void)
  77. {
  78. unsigned int result[5];
  79. unsigned int expected[5] = { 3, 3, 2, 3, 3 };
  80. result[0] = addition(0, 3);
  81. result[1] = addition(1, 2);
  82. result[2] = addition(1, 1);
  83. result[3] = addition(2, 1);
  84. result[4] = addition(3, 0);
  85. TEST_ASSERT_EQUAL_UINT(expected[0], result[0]);
  86. TEST_ASSERT_EQUAL_UINT(expected[1], result[1]);
  87. TEST_ASSERT_EQUAL_UINT(expected[2], result[2]);
  88. TEST_ASSERT_EQUAL_UINT(expected[3], result[3]);
  89. TEST_ASSERT_EQUAL_UINT(expected[4], result[4]);
  90. }
  91. void test_addition_addition_allunsignedinteger(void)
  92. {
  93. unsigned int result[5];
  94. unsigned int expected[5] = { 88879736, __UINT32_MAX__, 66558, __UINT32_MAX__, 477905879 };
  95. result[0] = addition(13456275, 75423461);
  96. result[1] = addition(4294967294, 1);
  97. result[2] = addition(1023, 65535);
  98. result[3] = addition(0, 4294967295);
  99. result[4] = addition(54321567,423584312);
  100. TEST_ASSERT_EQUAL_UINT(expected[0], result[0]);
  101. TEST_ASSERT_EQUAL_UINT(expected[1], result[1]);
  102. TEST_ASSERT_EQUAL_UINT(expected[2], result[2]);
  103. TEST_ASSERT_EQUAL_UINT(expected[3], result[3]);
  104. TEST_ASSERT_EQUAL_UINT(expected[4], result[4]);
  105. }
  106. #endif // TEST