Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Chris Müller
crystal
Commits
508d6336
Commit
508d6336
authored
Oct 28, 2012
by
Chris Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: add test code for usual lists.
parent
867d49d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
0 deletions
+124
-0
test/CMakeLists.txt
test/CMakeLists.txt
+1
-0
test/list.c
test/list.c
+123
-0
No files found.
test/CMakeLists.txt
View file @
508d6336
...
...
@@ -4,6 +4,7 @@ set(SOURCES
main.c
array.c
map.c
list.c
structures.c
)
...
...
test/list.c
0 → 100644
View file @
508d6336
#include "unittest.h"
#include "structures/list.h"
#include <assert.h>
static
void
test_list_prepend_and_append
(
const_pointer
data
)
{
int
items
[]
=
{
1
,
2
,
3
,
4
,
5
};
struct
CryList
*
list
=
cry_list_new
();
assert
(
cry_list_size
(
list
)
==
0
);
assert
(
cry_list_head
(
list
)
==
0
);
assert
(
cry_list_tail
(
list
)
==
0
);
// fill linked-lists with items
cry_list_prepend
(
list
,
items
);
assert
(
cry_list_size
(
list
)
==
1
);
assert
(
cry_list_head
(
list
)
==
items
);
assert
(
cry_list_tail
(
list
)
==
items
);
cry_list_prepend
(
list
,
items
+
1
);
assert
(
cry_list_size
(
list
)
==
2
);
assert
(
cry_list_head
(
list
)
==
items
+
1
);
assert
(
cry_list_tail
(
list
)
==
items
);
cry_list_append
(
list
,
items
+
2
);
assert
(
cry_list_size
(
list
)
==
3
);
assert
(
cry_list_head
(
list
)
==
items
+
1
);
assert
(
cry_list_tail
(
list
)
==
items
+
2
);
cry_list_append
(
list
,
items
+
3
);
assert
(
cry_list_size
(
list
)
==
4
);
assert
(
cry_list_head
(
list
)
==
items
+
1
);
assert
(
cry_list_tail
(
list
)
==
items
+
3
);
cry_list_free
(
list
,
0
);
}
static
void
test_list_iterator
(
data
)
{
int
items
[]
=
{
1
,
2
,
3
,
4
,
5
};
struct
CryList
*
list
=
cry_list_new
();
cry_list_append
(
list
,
items
);
cry_list_append
(
list
,
items
+
1
);
cry_list_append
(
list
,
items
+
2
);
cry_list_append
(
list
,
items
+
3
);
cry_list_append
(
list
,
items
+
4
);
struct
CryIndex
*
pos
=
cry_list_begin
(
list
);
assert
(
cry_list_prev
(
pos
)
==
0
);
assert
(
cry_list_data
(
pos
)
==
items
);
pos
=
cry_list_next
(
pos
);
assert
(
cry_list_data
(
pos
)
==
items
+
1
);
pos
=
cry_list_next
(
pos
);
assert
(
cry_list_data
(
pos
)
==
items
+
2
);
pos
=
cry_list_next
(
pos
);
assert
(
cry_list_data
(
pos
)
==
items
+
3
);
pos
=
cry_list_next
(
pos
);
assert
(
cry_list_data
(
pos
)
==
items
+
4
);
assert
(
pos
==
cry_list_end
(
list
));
assert
(
cry_list_next
(
pos
)
==
0
);
cry_list_free
(
list
,
0
);
}
static
void
test_list_operation
(
data
)
{
int
items
[]
=
{
1
,
2
,
3
,
4
,
5
};
struct
CryList
*
list
=
cry_list_new
();
cry_list_append
(
list
,
items
);
cry_list_append
(
list
,
items
+
1
);
cry_list_append
(
list
,
items
+
2
);
cry_list_append
(
list
,
items
+
3
);
cry_list_append
(
list
,
items
+
4
);
assert
(
cry_list_size
(
list
)
==
5
);
struct
CryIndex
*
middle
=
cry_list_index
(
list
,
2
);
assert
(
cry_list_remove
(
list
,
middle
)
==
items
+
2
);
assert
(
cry_list_size
(
list
)
==
4
);
struct
CryIndex
*
begin
=
cry_list_begin
(
list
);
assert
(
cry_list_data
(
begin
)
==
items
);
assert
(
cry_list_data
(
cry_list_step
(
begin
,
1
))
==
items
+
1
);
assert
(
cry_list_data
(
cry_list_step
(
begin
,
2
))
==
items
+
3
);
assert
(
cry_list_data
(
cry_list_step
(
begin
,
3
))
==
items
+
4
);
assert
(
cry_list_remove
(
list
,
cry_list_begin
(
list
))
==
items
);
assert
(
cry_list_remove
(
list
,
cry_list_end
(
list
))
==
items
+
4
);
assert
(
cry_list_size
(
list
)
==
2
);
cry_list_free
(
list
,
0
);
}
void
cry_test_lists
(
void
)
{
cry_unittest_run
(
"structures.list.insertions"
,
test_list_prepend_and_append
,
0
,
10
);
cry_unittest_run
(
"structures.list.iterator"
,
test_list_iterator
,
0
,
10
);
cry_unittest_run
(
"structures.list.operations"
,
test_list_operation
,
0
,
10
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment