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
ff39d2be
Commit
ff39d2be
authored
Oct 27, 2012
by
Chris Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: add testcode for maps.
parent
d9216f73
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
0 deletions
+61
-0
test/CMakeLists.txt
test/CMakeLists.txt
+1
-0
test/main.c
test/main.c
+2
-0
test/map.c
test/map.c
+58
-0
No files found.
test/CMakeLists.txt
View file @
ff39d2be
...
...
@@ -3,6 +3,7 @@ set(TEST crystal_unittests)
set
(
SOURCES
main.c
array.c
map.c
structures.c
)
...
...
test/main.c
View file @
ff39d2be
...
...
@@ -3,6 +3,7 @@
void
cry_test_structures
();
void
cry_test_arrays
();
void
cry_test_maps
();
int
main
(
int
argc
,
char
**
argv
)
...
...
@@ -11,6 +12,7 @@ main(int argc, char** argv)
cry_test_structures
();
cry_test_arrays
();
cry_test_maps
();
cry_unittest_finalize
();
...
...
test/map.c
0 → 100644
View file @
ff39d2be
#include "unittest.h"
#include "structures/map.h"
#include <assert.h>
#include <string.h>
static
void
test_map_initialization
(
const_pointer
data
)
{
struct
CryMap
*
map
=
cry_map_new
(
cry_cast
(
cry_ordering_funptr
,
strcmp
));
assert
(
cry_map_size
(
map
)
==
0
);
assert
(
cry_map_lookup
(
map
,
"unknown_key"
)
==
0
);
cry_map_free
(
map
,
0
,
0
);
}
static
void
test_map_insertion
(
const_pointer
data
)
{
struct
CryMap
*
map
=
cry_map_new
(
cry_cast
(
cry_ordering_funptr
,
strcmp
));
const
char
**
keys
=
cry_cast
(
const
char
**
,
data
);
assert
(
cry_map_size
(
map
)
==
0
);
while
(
*
keys
!=
0
)
{
assert
(
cry_map_insert
(
map
,
*
keys
,
*
keys
)
==
CRY_OKAY
);
++
keys
;
}
assert
(
cry_map_size
(
map
)
==
7
);
assert
(
cry_map_lookup
(
map
,
"A"
)
!=
0
);
assert
(
strcmp
(
cry_cast
(
const
char
*
,
cry_map_lookup
(
map
,
"A"
)),
"A"
)
==
0
);
assert
(
cry_map_lookup
(
map
,
"B"
)
!=
0
);
assert
(
strcmp
(
cry_cast
(
const
char
*
,
cry_map_lookup
(
map
,
"B"
)),
"B"
)
==
0
);
assert
(
cry_map_lookup
(
map
,
"S"
)
!=
0
);
assert
(
strcmp
(
cry_cast
(
const
char
*
,
cry_map_lookup
(
map
,
"S"
)),
"S"
)
==
0
);
assert
(
cry_map_lookup
(
map
,
"F"
)
==
0
);
cry_map_free
(
map
,
0
,
0
);
}
void
cry_test_maps
(
void
)
{
const
char
*
keys
[]
=
{
"A"
,
"B"
,
"C"
,
"Z"
,
"D"
,
"S"
,
"E"
,
0
};
cry_unittest_run
(
"structures.map.initialization"
,
test_map_initialization
,
0
,
10
);
cry_unittest_run
(
"structures.map.insertion"
,
test_map_insertion
,
keys
,
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