/[ascend]/trunk/ascend/general/test/test_pairlist.c
ViewVC logotype

Annotation of /trunk/ascend/general/test/test_pairlist.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3205 - (hide annotations) (download) (as text)
Tue Jul 11 13:59:34 2017 UTC (5 years, 6 months ago) by jpye
Original Path: branches/relerrorlist/ascend/general/test/test_pairlist.c
File MIME type: text/x-csrc
File size: 2391 byte(s)
expand test coverage in 'general' module.
rename ltmatrix routines for better uniformity.

1 jpye 3205 /* ASCEND modelling environment
2     Copyright (C) 2017 John Pye
3    
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2, or (at your option)
7     any later version.
8    
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12     GNU General Public License for more details.
13    
14     You should have received a copy of the GNU General Public License
15     along with this program. If not, see <http://www.gnu.org/licenses/>.
16     *//**
17     @file
18     Test functions for general/pairlist.c
19     by John Pye.
20     */
21    
22     #include <stdlib.h>
23     #include <stdio.h>
24     #include <stdarg.h>
25     #include <ascend/general/pairlist.h>
26     #include <ascend/general/list.h>
27    
28     #include "test/common.h"
29     #include "test/assertimpl.h"
30    
31     #ifndef MEMUSED
32     # define MEMUSED(N) CU_TEST(ascmeminuse()==(N))
33     #endif
34     #ifndef LISTUSESPOOL
35     # error "LISTUSESPOOL must be defined!"
36     #endif
37    
38     static void setup(void){
39     #if LISTUSESPOOL
40     gl_init_pool();
41     #endif
42     gl_init();
43     }
44    
45     static void teardown(void){
46     #if LISTUSESPOOL
47     gl_destroy_pool();
48     #endif
49     }
50    
51     static void test_createdestroy(void){
52     setup();
53     struct pairlist_t *pl1 = pairlist_create(10);
54     pairlist_destroy(pl1);
55     teardown();
56     MEMUSED(0);
57     }
58     //------------------------
59    
60     static void test_setappend(void){
61     setup();
62     struct pairlist_t *pl1 = pairlist_create(10);
63     pairlist_append(pl1,"A","value1");
64     pairlist_append(pl1,"B","value2");
65     pairlist_append(pl1,"C","value3");
66     int l = pairlist_length(pl1);
67     CU_TEST(l==3);
68     CU_TEST(3==pairlist_append_unique(pl1,"C","value4"));
69     void *old;
70     old = pairlist_set(pl1,"C","value5");
71     CU_TEST(strcmp(old,"value3")==0);
72     old = pairlist_set(pl1,"D","value6");
73     CU_TEST(old==NULL);
74     unsigned long i;
75     i = pairlist_contains(pl1,"B");
76     CU_TEST(i==2);
77     CU_TEST(strcmp(pairlist_keyAt(pl1,i),"B")==0);
78     CU_TEST(strcmp(pairlist_valueAt(pl1,i),"value2")==0);
79     CU_TEST(strcmp(pairlist_valueAt(pl1,pairlist_contains(pl1,"C")),"value5")==0);
80     pairlist_destroy(pl1);
81     teardown();
82     MEMUSED(0);
83     }
84     //------------------------
85    
86     /*===========================================================================*/
87     /* Registration information */
88    
89    
90     #define TESTS(T) \
91     T(createdestroy) \
92     T(setappend)
93    
94     REGISTER_TESTS_SIMPLE(general_pairlist, TESTS);
95    

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22