summaryrefslogtreecommitdiff
path: root/lab_6/unity/test/tests/Testfoo.c
blob: 433dc4e64675c3954bb446a9490d989bd66eb27a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "unity.h"
#include "foo.h"

void setUp(void)
{
}

void tearDown(void)
{
}

// Create one passing and one failing assertion using TEST_ASSERT_TRUE.
void testTEST_ASSERT_TRUE (void)
{
    TEST_ASSERT_TRUE (1 == 1); 
    //TEST_ASSERT_TRUE (1 == 2); //failing
}

// Create one passing and one failing assertion using TEST_ASSERT_FALSE.
void testTEST_ASSERT_FALSE (void)
{
	TEST_ASSERT_FALSE (1 == 2);
	//TEST_ASSERT_FALSE (1 == 1); //failing
}

// Create one passing and one failing assertion using TEST_ASSERT_EQUAL_INT8.
// Try it with negative decimal numbers, positive decimal numbers, and hexadecimal numbers.
void testTEST_ASSERT_EQUAL_INT8 (void)
{	
	TEST_ASSERT_EQUAL_INT8( 1, 1);
	TEST_ASSERT_EQUAL_INT8(-5, -5);
	TEST_ASSERT_EQUAL_INT8(0x7f, 127);
	//TEST_ASSERT_EQUAL_INT8(-1, 1); //failing
}

// Create one passing and one failing assertion using TEST_ASSERT_EQUAL_UINT8.
// Try it with negative decimal numbers, positive decimal numbers, and hexadecimal numbers.
void testTEST_ASSERT_EQUAL_UINT8 (void)
{	
	TEST_ASSERT_EQUAL_UINT8(1, 1);
	TEST_ASSERT_EQUAL_UINT8(255, 255);
	TEST_ASSERT_EQUAL_UINT8(0xa5, 165);
	//TEST_ASSERT_EQUAL_UINT8(1, -1); //failing
}

// Create one passing and one failing assertion using TEST_ASSERT_EQUAL_HEX8.
// Try it with negative decimal numbers, positive decimal numbers, and hexadecimal numbers.
void testTEST_ASSERT_EQUAL_HEX8 (void)
{
	TEST_ASSERT_EQUAL_HEX8( 0xff, 0xff );
	TEST_ASSERT_EQUAL_HEX8( 0x00, 0x00 );
	TEST_ASSERT_EQUAL_HEX8( 0x7f, 0x7f );
	//TEST_ASSERT_EQUAL_HEX8( 0x00, 0xff ); //failing
}

// Create one passing and one failing assertion using TEST_ASSERT_UINT_WITHIN.
void testTEST_ASSERT_UINT_WITHIN (void)
{
	TEST_ASSERT_UINT_WITHIN(50, 75, 50);
	//TEST_ASSERT_UINT_WITHIN(25, 75, 25);//failing
}

// Create one passing and one failing assertion using TEST_ASSERT_BITS.
void testTEST_ASSERT_BITS (void)
{
	TEST_ASSERT_BITS(0xa5, 0xe7, 0xa5 );
	//TEST_ASSERT_BITS(0xa5, 0xa4, 0xe7 );//failing
}

// Create one passing and one failing assertion using TEST_ASSERT_BITS_HIGH.
void testTEST_ASSERT_BITS_HIGH (void)
{
	TEST_ASSERT_BITS_HIGH(0xa5, 0xe7);
	//TEST_ASSERT_BITS_HIGH(0xe7, 0xa5);//failing
}

// Create one passing and one failing assertion using TEST_ASSERT_BIT_HIGH.
void testTEST_ASSERT_BIT_HIGH (void)
{
	TEST_ASSERT_BIT_HIGH(2, 4);
	//TEST_ASSERT_BIT_HIGH(3, 4);//failing
}

// Exhaustively test all 256 input values for the squareNumber function located in lab6\unity\src\foo.c.
// squareNumber takes an 8-bit unsigned integer as input, squares it, and then returns the squared value as a 16-bit
// unsigned integer.
void testsquareNumber (void)
{
	uint16_t input;
	uint16_t expected;
	uint16_t actual;
	
	for (input = 0; input <= 255; input++)
	{
		expected = input * input;
		actual = squareNumber((uint8_t) input);
		
		TEST_ASSERT_EQUAL_UINT16(expected, actual);
	}
}