Fix -Wsign-conversion warnings in tests.
This commit is contained in:
1 parent
279b46b4e2
commit
4ab3a3605b
10 files changed
+38
-37
No files matched your search
+7
-7
@@ -153,7 +153,7 @@ static void test_list(void)
|
||||
assert(g_count == 101);
|
||||
assert(list_int_size(tmp) == 101);
|
||||
for(int i = 0; i < 100; i++) {
|
||||
assert(*list_int_get(tmp, i) == i * i);
|
||||
assert(*list_int_get(tmp, (size_t) i) == i * i);
|
||||
}
|
||||
assert(*list_int_get(tmp, 100) == 17 * 17);
|
||||
}
|
||||
@@ -282,8 +282,8 @@ static void test_array(void)
|
||||
assert(g_count == 101);
|
||||
assert(array_int_size(tmp) == 101);
|
||||
for(int i = 0; i < 100; i++) {
|
||||
assert(*array_int_get(l, i) == i);
|
||||
assert(*array_int_get(tmp, i) == i * i);
|
||||
assert(*array_int_get(l, (size_t) i) == i);
|
||||
assert(*array_int_get(tmp, (size_t) i) == i * i);
|
||||
}
|
||||
assert(*array_int_get(l, 100) == 17);
|
||||
assert(*array_int_get(tmp, 100) == 17 * 17);
|
||||
@@ -293,8 +293,8 @@ static void test_array(void)
|
||||
ALGO_TRANSFORM(tmp, array_int_t, l, array_int_t, FT);
|
||||
assert(array_int_size(tmp) == 101);
|
||||
for(int i = 0; i < 100; i++) {
|
||||
assert(*array_int_get(l, i) == i);
|
||||
assert(*array_int_get(tmp, i) == i + 1);
|
||||
assert(*array_int_get(l, (size_t) i) == i);
|
||||
assert(*array_int_get(tmp, (size_t) i) == i + 1);
|
||||
}
|
||||
|
||||
array_int_clean(tmp);
|
||||
@@ -302,8 +302,8 @@ static void test_array(void)
|
||||
ALGO_TRANSFORM(tmp, array_int_t, l, array_int_t, FT2, 17);
|
||||
assert(array_int_size(tmp) == 101);
|
||||
for(int i = 0; i < 100; i++) {
|
||||
assert(*array_int_get(l, i) == i);
|
||||
assert(*array_int_get(tmp, i) == i + 17);
|
||||
assert(*array_int_get(l, (size_t) i) == i);
|
||||
assert(*array_int_get(tmp, (size_t) i) == i + 17);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-5
@@ -221,7 +221,7 @@ static void test_mpz(void)
|
||||
|
||||
// Test non empty
|
||||
for(int n = 0; n < 1000; n++) {
|
||||
testobj_set_ui (z, n);
|
||||
testobj_set_ui (z, (unsigned int) n);
|
||||
array_mpz_push_back (array1, z);
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ static void test_d(void)
|
||||
array_uint_move(a1, a2);
|
||||
assert (array_uint_empty_p (a1));
|
||||
for(int i = 0; i < 10; i++)
|
||||
array_uint_push_back (a1, i);
|
||||
array_uint_push_back (a1, (unsigned int) i);
|
||||
array_uint_set_at (a1, 0, 17);
|
||||
assert (*array_uint_get (a1, 0) == 17);
|
||||
assert (*array_uint_back(a1) == 9);
|
||||
@@ -297,10 +297,10 @@ static void test_d(void)
|
||||
*p = 10;
|
||||
assert (*array_uint_back(a1) == 10);
|
||||
for(int i = 0; i < 10; i++)
|
||||
array_uint_push_at (a1, 9, i);
|
||||
array_uint_push_at (a1, 9, (unsigned int) i);
|
||||
assert (*array_uint_back(a1) == 10);
|
||||
for(int i = 9; i < 19; i++)
|
||||
assert (*array_uint_get (a1, i) == 18U-i);
|
||||
assert (*array_uint_get (a1, (size_t) i) == 18U -(unsigned int) i);
|
||||
|
||||
*array_uint_get_at(a1, 100) = 100;
|
||||
assert (*array_uint_back(a1) == 100);
|
||||
@@ -312,7 +312,7 @@ static void test_d(void)
|
||||
array_uint_insert_v (a1, 10, 200);
|
||||
assert (array_uint_size(a1) == 300);
|
||||
for(int i = 10; i < 210; i++) {
|
||||
assert (*array_uint_get (a1, i) == 0);
|
||||
assert (*array_uint_get (a1, (size_t)i) == 0);
|
||||
}
|
||||
array_uint_it_t it;
|
||||
array_uint_it(it, a1);
|
||||
|
||||
+11
-11
@@ -36,7 +36,7 @@ static void test1(void)
|
||||
assert (bitset_back(set) == M_ASSIGN_CAST(bool, i%2));
|
||||
}
|
||||
for(int i = 0; i < 100; i ++) {
|
||||
assert (bitset_get(set, i) == M_ASSIGN_CAST(bool, i%2));
|
||||
assert (bitset_get(set, (size_t) i) == M_ASSIGN_CAST(bool, i%2));
|
||||
}
|
||||
assert(bitset_size(set) == 100);
|
||||
assert(bitset_empty_p(set) == false);
|
||||
@@ -56,7 +56,7 @@ static void test1(void)
|
||||
assert(bitset_size(set2) == 50);
|
||||
assert(bitset_empty_p(set2) == false);
|
||||
for(int i = 0; i < 50; i ++) {
|
||||
assert (bitset_get(set2, i) == M_ASSIGN_CAST(bool, i%2));
|
||||
assert (bitset_get(set2, (size_t) i) == M_ASSIGN_CAST(bool, i%2));
|
||||
}
|
||||
bitset_reserve(set2, 100);
|
||||
assert(bitset_capacity(set2) >= 100); // rounded
|
||||
@@ -64,10 +64,10 @@ static void test1(void)
|
||||
assert(bitset_capacity(set2) >= 50 && bitset_capacity(set2) < 100); // rounded
|
||||
bitset_resize(set2, 100);
|
||||
for(int i = 0; i < 50; i ++) {
|
||||
assert (bitset_get(set2, i) == M_ASSIGN_CAST(bool, i%2));
|
||||
assert (bitset_get(set2, (size_t) i) == M_ASSIGN_CAST(bool, i%2));
|
||||
}
|
||||
for(int i = 50; i < 100; i ++) {
|
||||
assert (bitset_get(set2, i) == false);
|
||||
assert (bitset_get(set2, (size_t) i) == false);
|
||||
}
|
||||
bitset_resize(set2, 50);
|
||||
|
||||
@@ -75,16 +75,16 @@ static void test1(void)
|
||||
bitset_push_at(set2, 0, 1);
|
||||
assert (bitset_get(set2, 0) == 1);
|
||||
for(int i = 1; i < 51; i ++) {
|
||||
assert (bitset_get(set2, i) == M_ASSIGN_CAST(bool, (i-1)%2));
|
||||
assert (bitset_get(set2, (size_t) i) == M_ASSIGN_CAST(bool, (i-1)%2));
|
||||
}
|
||||
// Push from not aligned bit
|
||||
bitset_push_at(set2, 9, 1);
|
||||
for(int i = 1; i < 9; i ++) {
|
||||
assert (bitset_get(set2, i) == M_ASSIGN_CAST(bool, (i-1)%2));
|
||||
assert (bitset_get(set2, (size_t) i) == M_ASSIGN_CAST(bool, (i-1)%2));
|
||||
}
|
||||
assert (bitset_get(set2, 9) == 1);
|
||||
for(int i = 10; i < 52; i ++) {
|
||||
assert (bitset_get(set2, i) == M_ASSIGN_CAST(bool, i%2));
|
||||
assert (bitset_get(set2, (size_t) i) == M_ASSIGN_CAST(bool, i%2));
|
||||
}
|
||||
|
||||
bool b;
|
||||
@@ -123,11 +123,11 @@ static void test1(void)
|
||||
|
||||
bitset_clean(set);
|
||||
for(int i = 0; i < 200; i++)
|
||||
bitset_push_back(set, (i*17547854547UL)&1) ;
|
||||
bitset_push_back(set, ((size_t) i*17547854547UL)&1) ;
|
||||
bitset_it_t it;
|
||||
int n = 0;
|
||||
for(bitset_it(it, set); ! bitset_end_p(it); bitset_next(it)) {
|
||||
bool v = (n*17547854547UL)&1;
|
||||
bool v = ((size_t) n*17547854547UL)&1;
|
||||
bool c = *bitset_cref(it);
|
||||
assert (v == c);
|
||||
n++;
|
||||
@@ -135,7 +135,7 @@ static void test1(void)
|
||||
|
||||
n = 0;
|
||||
for M_EACH (item, set, BITSET_OPLIST) {
|
||||
bool v = (n*17547854547UL)&1;
|
||||
bool v = ((size_t) n*17547854547UL)&1;
|
||||
bool c = *item;
|
||||
assert (v == c);
|
||||
n++;
|
||||
@@ -229,7 +229,7 @@ static void test_str(void)
|
||||
bitset_init(set2);
|
||||
|
||||
for(int i = 0; i < 200; i++)
|
||||
bitset_push_back(set1, (i*17547854547UL >> 4)&1) ;
|
||||
bitset_push_back(set1, ((size_t) i*17547854547UL >> 4)&1) ;
|
||||
|
||||
FILE *f = fopen ("a-mbitset.dat", "wt");
|
||||
if (!f) abort();
|
||||
|
||||
@@ -388,7 +388,7 @@ static void test_queue(size_t n, int cpu_count, unsigned long long ref)
|
||||
for(int i = 0; i < conso_count; i++) {
|
||||
m_thread_create (idx_c[i], conso2, &n);
|
||||
}
|
||||
size_t n2 = conso_count;
|
||||
size_t n2 = (size_t) conso_count;
|
||||
m_thread_create(idx_final, final2, &n2);
|
||||
|
||||
// Wait for jobs to be done.
|
||||
|
||||
+3
-3
@@ -52,7 +52,7 @@ static void test_ti1(int n)
|
||||
assert(*deque_front(d) == i);
|
||||
}
|
||||
assert (!deque_empty_p(d));
|
||||
assert (deque_size(d) == (size_t)2*n);
|
||||
assert (deque_size(d) == (size_t)(2*n));
|
||||
int s = 0;
|
||||
for(int i =0; i < 2*n ;i++) {
|
||||
int z;
|
||||
@@ -102,7 +102,7 @@ static void test1(void)
|
||||
}
|
||||
assert (deque_size(d) == 99*2);
|
||||
for(int i = 0; i < 99*2; i++)
|
||||
assert (*deque_get(d, i) == (i < 99) ? i - 99 : i - 98);
|
||||
assert (*deque_get(d, (size_t) i) == (i < 99) ? i - 99 : i - 98);
|
||||
for(int i = 0; i < 98; i++) {
|
||||
deque_pop_back(NULL, d);
|
||||
assert (*deque_back(d) == i - 98);
|
||||
@@ -290,7 +290,7 @@ static void test_io(void)
|
||||
|
||||
// Test non empty
|
||||
for(int n = 0; n < 1000; n++) {
|
||||
testobj_set_ui (z, n);
|
||||
testobj_set_ui (z, (unsigned int) n);
|
||||
deque_mpz_push_back (d1, z);
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -1,3 +1,4 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017-2020, Patrick Pelissier
|
||||
* All rights reserved.
|
||||
@@ -58,7 +59,7 @@ static void init_data(int data_size)
|
||||
string_init (s);
|
||||
array_string_init(v_str);
|
||||
for (int i = 0; i < data_size; ++i) {
|
||||
int j = (unsigned)(data_size * ((double)x / UINT_MAX) / 4) * 271828183u;
|
||||
unsigned int j = (unsigned int)(data_size * ((double)x / UINT_MAX) / 4) * 271828183u;
|
||||
string_printf(s, "%x", j);
|
||||
array_string_push_back (v_str, s);
|
||||
x = 1664525L * x + 1013904223L;
|
||||
@@ -79,7 +80,7 @@ static void test_data(void)
|
||||
dict_str_init (dict);
|
||||
assert(dict_str_empty_p(dict));
|
||||
for (int i = 0; i < data_size; ++i) {
|
||||
dict_str_set_at(dict, *array_string_cget(v_str, i), *array_string_cget(v_str, (i+1) % data_size));
|
||||
dict_str_set_at(dict, *array_string_cget(v_str, (size_t) i), *array_string_cget(v_str, (size_t) ((i+1) % data_size)));
|
||||
assert(!dict_str_empty_p(dict));
|
||||
}
|
||||
assert(dict_str_size(dict) == 1227176);
|
||||
|
||||
@@ -44,7 +44,7 @@ static void test(size_t n)
|
||||
assert (genint_pop(s) == GENINT_ERROR);
|
||||
|
||||
for(size_t j = 0; j< n ; j++) {
|
||||
genint_push(s, (j+k) % n );
|
||||
genint_push(s, ((j + (size_t) k) % n ));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -176,8 +176,8 @@ static void test_uint_permut(void)
|
||||
for(unsigned int i = 0; i < num; i++)
|
||||
tab[i] = i;
|
||||
for(unsigned int i = 0; i < 2 * num; i++) {
|
||||
int j = rand() % num;
|
||||
int k = rand() % num;
|
||||
unsigned int j = (unsigned int) rand() % num;
|
||||
unsigned int k = (unsigned int) rand() % num;
|
||||
M_SWAP(unsigned int, tab[j], tab[k]);
|
||||
}
|
||||
for(unsigned int i = 0; i < num; i++)
|
||||
|
||||
@@ -139,13 +139,13 @@ static void test_ressource(int n)
|
||||
shared_ressource_it_t copy[MAX_RESSOURCE];
|
||||
shared_ressource_it_t onemore;
|
||||
|
||||
shared_ressource_init (ressource, n);
|
||||
shared_ressource_init (ressource, (size_t) n);
|
||||
for(int i = 0; i < n ; i++) {
|
||||
shared_ressource_it (it[i], ressource);
|
||||
assert (!shared_ressource_end_p(it[i]));
|
||||
testobj_t *z = shared_ressource_ref(it[i]);
|
||||
assert (z != NULL);
|
||||
testobj_set_ui(*z, i);
|
||||
testobj_set_ui(*z, (unsigned int) i);
|
||||
}
|
||||
shared_ressource_it (onemore, ressource);
|
||||
assert (shared_ressource_end_p(onemore));
|
||||
@@ -154,7 +154,7 @@ static void test_ressource(int n)
|
||||
assert (!shared_ressource_end_p(copy[i]));
|
||||
const testobj_t *z = shared_ressource_cref(copy[i]);
|
||||
assert (z != NULL);
|
||||
assert (testobj_cmp_ui(*z, i) == 0);
|
||||
assert (testobj_cmp_ui(*z, (unsigned int) i) == 0);
|
||||
}
|
||||
shared_ressource_it (onemore, ressource);
|
||||
assert (shared_ressource_end_p(onemore));
|
||||
|
||||
@@ -250,7 +250,7 @@ static void test_mrsw_global(int reader)
|
||||
m_thread_t idx_w;
|
||||
m_thread_t idx[MAX_READER];
|
||||
|
||||
snapshot_mrsw_data_init(global_mrsw, reader);
|
||||
snapshot_mrsw_data_init(global_mrsw, (size_t) reader);
|
||||
data_t *p = snapshot_mrsw_data_write(global_mrsw);
|
||||
assert (p != NULL);
|
||||
p->n = 42;
|
||||
@@ -305,7 +305,7 @@ static void test_mrmw_global(int reader, int writer)
|
||||
m_thread_t idx_w[MAX_WRITER];
|
||||
m_thread_t idx[MAX_READER];
|
||||
|
||||
snapshot_mrmw_data_init(global_mrmw, reader, writer);
|
||||
snapshot_mrmw_data_init(global_mrmw, (size_t) reader, (size_t) writer);
|
||||
data_t *p = snapshot_mrmw_data_write_start(global_mrmw);
|
||||
assert (p != NULL);
|
||||
p->n = 42;
|
||||
|
||||
Reference in new issue
Block a user