tests/test_iterator.c

changeset 951
8f6d6556380a
parent 853
d4baf4dd55c3
equal deleted inserted replaced
950:37e7f92de46b 951:8f6d6556380a
29 #include "cx/test.h" 29 #include "cx/test.h"
30 30
31 #include "cx/iterator.h" 31 #include "cx/iterator.h"
32 32
33 CX_TEST(test_iterator_create) { 33 CX_TEST(test_iterator_create) {
34 size_t size = 20; 34 unsigned array[20];
35 unsigned array[size]; 35 size_t size = cx_nmemb(array);
36 for (unsigned i = 0 ; i < size ; i++) array[i] = i; 36 for (unsigned i = 0 ; i < size ; i++) array[i] = i;
37 37
38 CxIterator iter = cxIterator(array, sizeof(unsigned), size); 38 CxIterator iter = cxIterator(array, sizeof(unsigned), size);
39 CX_TEST_DO { 39 CX_TEST_DO {
40 CX_TEST_ASSERT(iter.index == 0); 40 CX_TEST_ASSERT(iter.index == 0);
57 CX_TEST_ASSERT(!cxIteratorValid(iter)); 57 CX_TEST_ASSERT(!cxIteratorValid(iter));
58 } 58 }
59 } 59 }
60 60
61 CX_TEST(test_iterator_iterate) { 61 CX_TEST(test_iterator_iterate) {
62 size_t size = 20; 62 unsigned array[20];
63 unsigned array[size]; 63 size_t size = cx_nmemb(array);
64 for (unsigned i = 0 ; i < size ; i++) array[i] = i; 64 for (unsigned i = 0 ; i < size ; i++) array[i] = i;
65 65
66 CxIterator iter = cxIterator(array, sizeof(unsigned), size); 66 CxIterator iter = cxIterator(array, sizeof(unsigned), size);
67 CX_TEST_DO { 67 CX_TEST_DO {
68 unsigned expected = 0; 68 unsigned expected = 0;
78 CX_TEST_ASSERT(expected == size); 78 CX_TEST_ASSERT(expected == size);
79 } 79 }
80 } 80 }
81 81
82 CX_TEST(test_iterator_with_slow_remove) { 82 CX_TEST(test_iterator_with_slow_remove) {
83 size_t size = 20; 83 unsigned array[20];
84 unsigned array[size]; 84 size_t size = cx_nmemb(array);
85 for (unsigned i = 0 ; i < size ; i++) array[i] = i; 85 for (unsigned i = 0 ; i < size ; i++) array[i] = i;
86 86
87 size_t elem_counts[] = { 87 size_t elem_counts[] = {
88 20, 20, 19, 19, 18, 18, 17, 17, 16, 16, 88 20, 20, 19, 19, 18, 18, 17, 17, 16, 16,
89 15, 15, 14, 14, 13, 13, 12, 12, 11, 11 89 15, 15, 14, 14, 13, 13, 12, 12, 11, 11
119 } 119 }
120 } 120 }
121 } 121 }
122 122
123 CX_TEST(test_iterator_with_fast_remove) { 123 CX_TEST(test_iterator_with_fast_remove) {
124 size_t size = 20; 124 unsigned array[20];
125 unsigned array[size]; 125 size_t size = cx_nmemb(array);
126 for (unsigned i = 0 ; i < size ; i++) array[i] = i; 126 for (unsigned i = 0 ; i < size ; i++) array[i] = i;
127 127
128 size_t elem_counts[] = { 128 size_t elem_counts[] = {
129 20, 20, 19, 19, 18, 18, 17, 17, 16, 16, 129 20, 20, 19, 19, 18, 18, 17, 17, 16, 16,
130 15, 15, 14, 14, 13, 13, 12, 12, 11, 11 130 15, 15, 14, 14, 13, 13, 12, 12, 11, 11

mercurial