1/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc. See LICENSE. */ 2#include <assert.h> 3#include <stdio.h> 4#include <stdlib.h> 5#include <string.h> 6 7#include "lsquic_set.h" 8 9static void 10test_lsquic_set32 (void) 11{ 12 lsquic_set32_t set; 13 int i, s; 14 15 lsquic_set32_init(&set); 16 17 for (i = 2; i < 100; ++i) 18 { 19 assert(("Value is not yet in the set", !lsquic_set32_has(&set, i))); 20 s = lsquic_set32_add(&set, i); 21 assert(0 == s); 22 } 23 24 assert(("Value is not yet in the set", !lsquic_set32_has(&set, 0))); 25 s = lsquic_set32_add(&set, 0); 26 assert(0 == s); 27 assert(("Value is not yet in the set", !lsquic_set32_has(&set, 1))); 28 s = lsquic_set32_add(&set, 1); 29 assert(0 == s); 30 31 for (i = 0; i < 100; ++i) 32 assert(("Value is in the set", lsquic_set32_has(&set, i))); 33 34 for (i = 300; i > 200; --i) 35 { 36 assert(("Value is not yet in the set", !lsquic_set32_has(&set, i))); 37 s = lsquic_set32_add(&set, i); 38 assert(0 == s); 39 } 40 41 for (i = 300; i > 200; --i) 42 assert(("Value is in the set", lsquic_set32_has(&set, i))); 43 44 for (i = 100; i <= 200; ++i) 45 assert(("Value is not in the set", !lsquic_set32_has(&set, i))); 46 47 for (i = 1000; i < 2000; i += 4) 48 { 49 assert(("Value is not yet in the set", !lsquic_set32_has(&set, i))); 50 lsquic_set32_add(&set, i); 51 } 52 53 for (i = 1000; i < 2000; i += 4) 54 assert(("Value is in the set", lsquic_set32_has(&set, i))); 55 56 for (i = 1000; i < 2000; i += 4) 57 { 58 assert(("Value is not yet in the set", !lsquic_set32_has(&set, i + 1))); 59 lsquic_set32_add(&set, i + 1); 60 assert(("Value is not yet in the set", !lsquic_set32_has(&set, i + 3))); 61 lsquic_set32_add(&set, i + 3); 62 assert(("Value is not yet in the set", !lsquic_set32_has(&set, i + 2))); 63 lsquic_set32_add(&set, i + 2); 64 } 65 66 for (i = 0; i < 100; ++i) 67 assert(("Value is in the set", lsquic_set32_has(&set, i))); 68 for (i = 100; i <= 200; ++i) 69 assert(("Value is not in the set", !lsquic_set32_has(&set, i))); 70 for (i = 201; i <= 300; ++i) 71 assert(("Value is in the set", lsquic_set32_has(&set, i))); 72 for (i = 1000; i < 2000; ++i) 73 assert(("Value is in the set", lsquic_set32_has(&set, i))); 74 75 lsquic_set32_cleanup(&set); 76} 77 78 79static void 80test_lsquic_set64 (void) 81{ 82 lsquic_set64_t set; 83 int i; 84 85 lsquic_set64_init(&set); 86 87 for (i = 2; i < 100; ++i) 88 { 89 assert(("Value is not yet in the set", !lsquic_set64_has(&set, i))); 90 lsquic_set64_add(&set, i); 91 } 92 93 assert(("Value is not yet in the set", !lsquic_set64_has(&set, 0))); 94 lsquic_set64_add(&set, 0); 95 assert(("Value is not yet in the set", !lsquic_set64_has(&set, 1))); 96 lsquic_set64_add(&set, 1); 97 98 for (i = 0; i < 100; ++i) 99 assert(("Value is in the set", lsquic_set64_has(&set, i))); 100 101 for (i = 300; i > 200; --i) 102 { 103 assert(("Value is not yet in the set", !lsquic_set64_has(&set, i))); 104 lsquic_set64_add(&set, i); 105 } 106 107 for (i = 300; i > 200; --i) 108 assert(("Value is in the set", lsquic_set64_has(&set, i))); 109 110 for (i = 100; i <= 200; ++i) 111 assert(("Value is not in the set", !lsquic_set64_has(&set, i))); 112 113 for (i = 1000; i < 2000; i += 4) 114 { 115 assert(("Value is not yet in the set", !lsquic_set64_has(&set, i))); 116 lsquic_set64_add(&set, i); 117 } 118 119 for (i = 1000; i < 2000; i += 4) 120 assert(("Value is in the set", lsquic_set64_has(&set, i))); 121 122 for (i = 1000; i < 2000; i += 4) 123 { 124 assert(("Value is not yet in the set", !lsquic_set64_has(&set, i + 1))); 125 lsquic_set64_add(&set, i + 1); 126 assert(("Value is not yet in the set", !lsquic_set64_has(&set, i + 3))); 127 lsquic_set64_add(&set, i + 3); 128 assert(("Value is not yet in the set", !lsquic_set64_has(&set, i + 2))); 129 lsquic_set64_add(&set, i + 2); 130 } 131 132 for (i = 0; i < 100; ++i) 133 assert(("Value is in the set", lsquic_set64_has(&set, i))); 134 for (i = 100; i <= 200; ++i) 135 assert(("Value is not in the set", !lsquic_set64_has(&set, i))); 136 for (i = 201; i <= 300; ++i) 137 assert(("Value is in the set", lsquic_set64_has(&set, i))); 138 for (i = 1000; i < 2000; ++i) 139 assert(("Value is in the set", lsquic_set64_has(&set, i))); 140 141 lsquic_set64_cleanup(&set); 142} 143 144 145int 146main (void) 147{ 148 test_lsquic_set32(); 149 test_lsquic_set64(); 150 return 0; 151} 152