test/array_tests.c

branch
feature/array
changeset 337
f695ae118460
parent 336
6d7aa8a1a3b3
child 342
8f0a3c00d1d2
--- a/test/array_tests.c	Thu Jul 04 22:23:15 2019 +0200
+++ b/test/array_tests.c	Thu Jul 04 22:32:03 2019 +0200
@@ -118,6 +118,34 @@
     ucx_array_free(&array);
 }
 
+UCX_TEST(test_ucx_array_set) {
+    UcxArray array = ucx_array_new(16, sizeof(int));
+    
+    int x = 42;
+
+    UCX_TEST_BEGIN
+
+    ucx_array_set(&array, 7, &x);
+    UCX_TEST_ASSERT(ucx_array_at_int(array, 7) == 42, "failed");
+    UCX_TEST_ASSERT(array.size >= 8, "array not resized on set");
+    UCX_TEST_ASSERT(array.capacity == 16, "capacity changed unnecessarily");
+    
+    x = 13;
+    ucx_array_set(&array, 27, &x);
+    
+    UCX_TEST_ASSERT(ucx_array_at_int(array, 27) == 13, "failed");
+    UCX_TEST_ASSERT(array.size == 28, "array not resized on set");
+    UCX_TEST_ASSERT(array.capacity == 28, "capacity not grown");
+    
+    ucx_array_set(&array, 7, NULL);
+    
+    UCX_TEST_ASSERT(ucx_array_at_int(array, 7) == 0, "not zeroed on NULL set");
+    
+    UCX_TEST_END
+    
+    ucx_array_free(&array);
+}
+
 UCX_TEST(test_ucx_array_equals) {
     UcxArray a1 = ucx_array_new(16, sizeof(int));
     UcxArray a2 = ucx_array_new(16, sizeof(int));

mercurial