Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MicroCART
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Distributed Autonomous Networked Control Lab
MicroCART
Commits
c4c6f79b
Commit
c4c6f79b
authored
7 years ago
by
Peter Thedens
Browse files
Options
Downloads
Patches
Plain Diff
Add unity test equivalent
parent
340f6dbb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
quad/src/queue/test/Unity_test_queue.c
+158
-0
158 additions, 0 deletions
quad/src/queue/test/Unity_test_queue.c
with
158 additions
and
0 deletions
quad/src/queue/test/Unity_test_queue.c
0 → 100644
+
158
−
0
View file @
c4c6f79b
#include
"test.h"
#include
"queue.h"
#include
"unity.h"
void
test_free
()
{
struct
Queue
*
q
=
queue_malloc
(
4
);
queue_free
(
q
);
TEST_ASSERT_NULL
(
q
);
}
void
test_add
()
{
struct
Queue
*
q
=
queue_malloc
(
4
);
unsigned
char
c
;
TEST_ASSERT_EQUAL
(
0
,
queue_add
(
q
,
'a'
));
TEST_ASSERT_EQUAL
(
0
,
queue_add
(
q
,
'b'
));
TEST_ASSERT_EQUAL
(
0
,
queue_add
(
q
,
'c'
));
TEST_ASSERT_EQUAL
(
0
,
queue_add
(
q
,
'd'
));
TEST_ASSERT_EQUAL
(
-
1
,
queue_add
(
q
,
'x'
));
queue_print
(
q
);
queue_remove
(
q
,
&
c
);
queue_remove
(
q
,
&
c
);
TEST_ASSERT_EQUAL
(
0
,
queue_add
(
q
,
'e'
));
TEST_ASSERT_EQUAL
(
0
,
queue_add
(
q
,
'f'
));
TEST_ASSERT_EQUAL
(
-
1
,
queue_add
(
q
,
'x'
));
queue_print
(
q
);
}
void
test_remove
()
{
struct
Queue
*
q
=
queue_malloc
(
4
);
unsigned
char
c
;
queue_add
(
q
,
'x'
);
queue_add
(
q
,
'x'
);
TEST_ASSERT_EQUAL
(
0
,
queue_remove
(
q
,
&
c
));
TEST_ASSERT_EQUAL
(
'x'
,
c
);
TEST_ASSERT_EQUAL
(
0
,
queue_remove
(
q
,
&
c
));
TEST_ASSERT_EQUAL
(
'x'
,
c
);
TEST_ASSERT_EQUAL
(
-
1
,
queue_remove
(
q
,
&
c
));
queue_print
(
q
);
queue_add
(
q
,
'a'
);
queue_add
(
q
,
'b'
);
queue_add
(
q
,
'c'
);
queue_add
(
q
,
'd'
);
queue_add
(
q
,
'x'
);
TEST_ASSERT_EQUAL
(
0
,
queue_remove
(
q
,
&
c
));
TEST_ASSERT_EQUAL
(
'a'
,
c
);
TEST_ASSERT_EQUAL
(
0
,
queue_remove
(
q
,
&
c
));
TEST_ASSERT_EQUAL
(
'b'
,
c
);
TEST_ASSERT_EQUAL
(
0
,
queue_remove
(
q
,
&
c
));
TEST_ASSERT_EQUAL
(
'c'
,
c
);
TEST_ASSERT_EQUAL
(
0
,
queue_remove
(
q
,
&
c
));
TEST_ASSERT_EQUAL
(
'd'
,
c
);
TEST_ASSERT_EQUAL
(
-
1
,
queue_remove
(
q
,
&
c
));
}
void
test_size
()
{
struct
Queue
*
q
=
queue_malloc
(
4
);
unsigned
char
c
;
TEST_ASSERT_EQUAL
(
0
,
queue_size
(
q
));
queue_print
(
q
);
queue_add
(
q
,
'a'
);
TEST_ASSERT_EQUAL
(
1
,
queue_size
(
q
));
queue_print
(
q
);
queue_add
(
q
,
'b'
);
TEST_ASSERT_EQUAL
(
2
,
queue_size
(
q
));
queue_print
(
q
);
queue_add
(
q
,
'c'
);
TEST_ASSERT_EQUAL
(
3
,
queue_size
(
q
));
queue_print
(
q
);
queue_add
(
q
,
'd'
);
TEST_ASSERT_EQUAL
(
4
,
queue_size
(
q
));
queue_print
(
q
);
queue_remove
(
q
,
&
c
);
queue_remove
(
q
,
&
c
);
TEST_ASSERT_EQUAL
(
2
,
queue_size
(
q
));
queue_print
(
q
);
queue_add
(
q
,
'e'
);
TEST_ASSERT_EQUAL
(
3
,
queue_size
(
q
));
queue_print
(
q
);
}
void
test_full
()
{
struct
Queue
*
q
=
queue_malloc
(
4
);
unsigned
char
c
;
TEST_ASSERT_FALSE
(
queue_full
(
q
));
queue_print
(
q
);
queue_add
(
q
,
'a'
);
queue_add
(
q
,
'b'
);
queue_add
(
q
,
'c'
);
TEST_ASSERT_FALSE
(
queue_full
(
q
));
queue_print
(
q
);
queue_add
(
q
,
'd'
);
TEST_ASSERT_TRUE
(
queue_full
(
q
));
queue_print
(
q
);
queue_remove
(
q
,
&
c
);
TEST_ASSERT_FALSE
(
queue_full
(
q
));
queue_print
(
q
);
queue_remove
(
q
,
&
c
);
queue_add
(
q
,
'x'
);
queue_add
(
q
,
'x'
);
TEST_ASSERT_TRUE
(
queue_full
(
q
));
queue_print
(
q
);
}
void
test_empty
()
{
struct
Queue
*
q
=
queue_malloc
(
4
);
unsigned
char
c
;
TEST_ASSERT_TRUE
(
queue_empty
(
q
));
queue_print
(
q
);
queue_add
(
q
,
'a'
);
queue_add
(
q
,
'b'
);
queue_add
(
q
,
'c'
);
TEST_ASSERT_FALSE
(
queue_empty
(
q
));
queue_print
(
q
);
queue_add
(
q
,
'd'
);
TEST_ASSERT_FALSE
(
queue_empty
(
q
));
queue_print
(
q
);
queue_remove
(
q
,
&
c
);
TEST_ASSERT_FALSE
(
queue_empty
(
q
));
queue_print
(
q
);
queue_remove
(
q
,
&
c
);
queue_remove
(
q
,
&
c
);
TEST_ASSERT_FALSE
(
queue_empty
(
q
));
queue_remove
(
q
,
&
c
);
TEST_ASSERT_TRUE
(
queue_empty
(
q
));
}
int
main
()
{
UNITY_BEGIN
();
RUN_TEST
(
test_free
);
RUN_TEST
(
test_add
);
RUN_TEST
(
test_remove
);
RUN_TEST
(
test_size
);
RUN_TEST
(
test_full
);
RUN_TEST
(
test_empty
);
return
UNITY_END
();
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment