pelib  2.0.0
src/test_set.c
Go to the documentation of this file.
00001 /*
00002  * test_set.c
00003  *
00004  *      Created on: 13 Jan 2012
00005  *      Copyright 2012 Nicolas Melot
00006  *
00007  * This file is part of pelib.
00008  * 
00009  *               pelib is free software: you can redistribute it and/or modify
00010  *               it under the terms of the GNU General Public License as published by
00011  *               the Free Software Foundation, either version 3 of the License, or
00012  *               (at your option) any later version.
00013  * 
00014  *               pelib is distributed in the hope that it will be useful,
00015  *               but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *               MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
00017  *               GNU General Public License for more details.
00018  * 
00019  *               You should have received a copy of the GNU General Public License
00020  *               along with pelib. If not, see <http://www.gnu.org/licenses/>.
00021  * 
00022  */
00023 
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026 #include <string.h>
00027 
00028 #include <pelib/unit.h>
00029 #include <pelib/integer.h>
00030 
00031 #define LENGTH  8
00032 #define FILENAME_BINARY "set_binary.bin"
00033 #define VALUE   10
00034 #define SKIP    6
00035 
00036 #if 10
00037 #define debug(var) printf("[%s:%s:%d] %s = \"%s\"\n", __FILE__, __FUNCTION__, __LINE__, #var, var); fflush(NULL)
00038 #define debug_addr(var) printf("[%s:%s:%d] %s = \"%p\"\n", __FILE__, __FUNCTION__, __LINE__, #var, var); fflush(NULL)
00039 #define debug_int(var) printf("[%s:%s:%d] %s = \"%d\"\n", __FILE__, __FUNCTION__, __LINE__, #var, var); fflush(NULL)
00040 #define debug_size_t(var) printf("[%s:%s:%d] %s = \"%zu\"\n", __FILE__, __FUNCTION__, __LINE__, #var, var); fflush(NULL)
00041 #else
00042 #define debug(var)
00043 #define debug_addr(var)
00044 #define debug_int(var)
00045 #define debug_size_t(var)
00046 #endif
00047 
00048 set_t(pair_t(int, int)) set;
00049 int value;
00050 
00051 int insertion[] = {3, 6, 7, 5, 3, 5, 6, 2};
00052 
00053 void
00054 init()
00055 {
00056         unsigned int i;
00057         pelib_init(set_t(pair_t(int, int)))(&set);
00058         value = VALUE;
00059 
00060         for (i = 0; i < LENGTH; i++)
00061         {
00062                 pair_t(int, int) pair;
00063                 pair.key = insertion[i];
00064                 pair.value = i;
00065                 pelib_set_insert(pair_t(int, int))(&set, pair);
00066         }
00067 }
00068 
00069 void
00070 cleanup()
00071 {
00072         pelib_destroy(set_t(pair_t(int, int)))(set);
00073 }
00074 
00075 void setup() {};
00076 void teardown() {};
00077 
00078 static void
00079 test_string()
00080 {
00081         char *ref = "[(2,7):(3,0):(3,4):(5,3):(5,5):(6,1):(6,6):(7,2)]";
00082         char *str = pelib_string(set_t(pair_t(int, int)))(set);
00083         assert_equals_str(str, ref);
00084         free(str);
00085 }
00086 
00087 void
00088 run()
00089 {
00090         test(test_string);
00091 }
00092