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.
 
 

118 lines
3.1 KiB

#ifdef TEST
#include "unity.h"
#include "addition.h"
int carry[1];
void setUp(void)
{
}
void tearDown(void)
{
}
void test_addition_full_adder_nullplusnullgleichnull(void)
{
int result[1];
int expected = 0;
full_adder(result, carry, 0, 0, 0);
TEST_ASSERT_EQUAL_INT(expected, result[0]);
}
void test_addition_full_adder_nullplusnullgleichnullmituebertrag(void)
{
int result[1];
int expected = 1;
full_adder(result, carry, 0, 0, 1);
TEST_ASSERT_EQUAL_INT(expected, result[0]);
}
void test_addition_full_adder_zahlpluszahlgleichsummeohneuebertrag(void)
{
int result[5];
int expected[5] = { 0, 1, 1, 1, 1};
full_adder((result+0), carry, 1, 0, 1);
full_adder((result+1), carry, 0, 1, 0);
full_adder((result+2), carry, 1, 0, 0);
full_adder((result+3), carry, 0, 0, 1);
full_adder((result+4), carry, 1, 1, 1);
TEST_ASSERT_EQUAL_INT(expected[0], result[0]);
TEST_ASSERT_EQUAL_INT(expected[1], result[1]);
TEST_ASSERT_EQUAL_INT(expected[2], result[2]);
TEST_ASSERT_EQUAL_INT(expected[3], result[3]);
TEST_ASSERT_EQUAL_INT(expected[4], result[4]);
}
void test_addition_full_adder_completesumwithcarry(void)
{
int result[5], carryresult[5];
int expected[5] = { 0, 0, 1, 1, 0}, expectedcarry[5] = { 1, 1, 1, 0, 0};
full_adder(result+0, carryresult+0, 0, 1, 1);
full_adder(result+1, carryresult+1, 1, 1, 0);
full_adder(result+2, carryresult+2, 1, 1, 1);
full_adder(result+3, carryresult+3, 0, 1, 0);
full_adder(result+4, carryresult+4, 0, 0, 0);
TEST_ASSERT_EQUAL_INT(expected[0], result[0]);
TEST_ASSERT_EQUAL_INT(expected[1], result[1]);
TEST_ASSERT_EQUAL_INT(expected[2], result[2]);
TEST_ASSERT_EQUAL_INT(expected[3], result[3]);
TEST_ASSERT_EQUAL_INT(expected[4], result[4]);
TEST_ASSERT_EQUAL_INT(expectedcarry[0], carryresult[0]);
TEST_ASSERT_EQUAL_INT(expectedcarry[1], carryresult[1]);
TEST_ASSERT_EQUAL_INT(expectedcarry[2], carryresult[2]);
TEST_ASSERT_EQUAL_INT(expectedcarry[3], carryresult[3]);
TEST_ASSERT_EQUAL_INT(expectedcarry[4], carryresult[4]);
}
void test_addition_addition_basecasezeropluszeroequalzero(void)
{
int result;
int expected = 0;
result = addition(0, 0);
TEST_ASSERT_EQUAL_INT(expected, result);
}
void test_addition_addition_basecaseonescolumns(void)
{
int result[2];
int expected[2] = { 1, 1 };
result[0] = addition(1, 0);
result[1] = addition(0, 1);
TEST_ASSERT_EQUAL_INT(expected[0], result[0]);
TEST_ASSERT_EQUAL_INT(expected[1], result[1]);
}
void test_addition_addition_basecasetotenscolumns(void)
{
int result[5];
int expected[5] = { 3, 3, 2, 3, 3 };
result[0] = addition(0, 3);
result[1] = addition(1, 2);
result[2] = addition(1, 1);
result[3] = addition(2, 1);
result[4] = addition(3, 0);
TEST_ASSERT_EQUAL_INT(expected[0], result[0]);
TEST_ASSERT_EQUAL_INT(expected[1], result[1]);
TEST_ASSERT_EQUAL_INT(expected[2], result[2]);
TEST_ASSERT_EQUAL_INT(expected[3], result[3]);
TEST_ASSERT_EQUAL_INT(expected[4], result[4]);
}
#endif // TEST