forked from vieter-v/libvieter
				
			test: add some cat-heap tests
							parent
							
								
									c7d2db4e42
								
							
						
					
					
						commit
						ec6e217801
					
				
							
								
								
									
										6
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										6
									
								
								Makefile
								
								
								
								
							| 
						 | 
					@ -98,5 +98,11 @@ clean:
 | 
				
			||||||
	rm -rf $(BUILD_DIR)
 | 
						rm -rf $(BUILD_DIR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PHONY: bear
 | 
				
			||||||
 | 
					bear: clean
 | 
				
			||||||
 | 
						bear -- make
 | 
				
			||||||
 | 
						bear --append -- make build-test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Make make aware of the .d files
 | 
					# Make make aware of the .d files
 | 
				
			||||||
-include $(DEPS)
 | 
					-include $(DEPS)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,52 @@
 | 
				
			||||||
 | 
					#include "acutest.h"
 | 
				
			||||||
 | 
					#include "vieter_cat_heap_internal.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define TEST_SIZE(cheap, size) \
 | 
				
			||||||
 | 
					    TEST_CHECK(vieter_cat_heap_size(cheap) == size); \
 | 
				
			||||||
 | 
					    TEST_MSG("Size: %zu, expected: %lu", vieter_cat_heap_size(cheap), (uint64_t)size)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void test_init() {
 | 
				
			||||||
 | 
					    vieter_cat_heap *cheap = vieter_cat_heap_init();
 | 
				
			||||||
 | 
					    TEST_CHECK(cheap != NULL);
 | 
				
			||||||
 | 
					    TEST_SIZE(cheap, 0);
 | 
				
			||||||
 | 
					    vieter_cat_heap_free(cheap);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void test_insert() {
 | 
				
			||||||
 | 
					  vieter_cat_heap *cheap = vieter_cat_heap_init();
 | 
				
			||||||
 | 
					    TEST_SIZE(cheap, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void *data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (uint64_t i = 50; i > 0; i--) {
 | 
				
			||||||
 | 
					        vieter_cat_heap_insert(cheap, "cat1", i, (void *)i);
 | 
				
			||||||
 | 
					        TEST_SIZE(cheap, (uint64_t)51 - i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        data = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        TEST_CHECK(vieter_cat_heap_peek(&data, cheap, "cat1") == vieter_cat_heap_ok);
 | 
				
			||||||
 | 
					        TEST_CHECK_(data == (void *)i, "%lX == %lX", (uint64_t)data, i);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (uint64_t i = 50; i > 0; i--) {
 | 
				
			||||||
 | 
					        vieter_cat_heap_insert(cheap, "cat2", i, (void *)i);
 | 
				
			||||||
 | 
					        TEST_SIZE(cheap, (uint64_t)101 - i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        data = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        TEST_CHECK(vieter_cat_heap_peek(&data, cheap, "cat2") == vieter_cat_heap_ok);
 | 
				
			||||||
 | 
					        TEST_CHECK_(data == (void *)i, "%lX == %lX", (uint64_t)data, i);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    vieter_cat_heap_free(cheap);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST_LIST = {
 | 
				
			||||||
 | 
					    {"cat heap init", test_init},
 | 
				
			||||||
 | 
					    {"cat heap insert", test_insert},
 | 
				
			||||||
 | 
					    /* {"heap insert random", test_insert_random}, */
 | 
				
			||||||
 | 
					    /* {"heap pop", test_pop}, */
 | 
				
			||||||
 | 
					    /* {"heap pop random", test_pop_random}, */
 | 
				
			||||||
 | 
					    {NULL, NULL}
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
		Loading…
	
		Reference in New Issue