Hash :
ee55121b
Author :
Thomas de Grivel
Date :
2022-11-10T16:51:49
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
/* c3
* Copyright 2022 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted
* the above copyright notice and this permission paragraph
* are included in all copies and substantial portions of this
* software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#include "../libc3/facts.h"
#include "../libc3/facts_cursor.h"
#include "../libc3/facts_with.h"
#include "../libc3/facts_with_cursor.h"
#include "fact_test.h"
#include "tag_test.h"
#include "test.h"
void facts_with_test ();
void facts_with_test_ ();
void facts_with_test_tags ();
void facts_with_test ()
{
facts_with_test_tags();
facts_with_test_();
}
void facts_with_test_ ()
{
s_facts_with_cursor cursor;
s_fact fact;
s_facts facts;
sw i = 0;
s_tag object;
const s8 *p[9] = { "A", "B", "C", "D", "E", "F", "G", "H", NULL };
s_tag predicate;
s_tag subject;
s_tag tag[8];
while (p[i]) {
tag_init_1(tag + i, p[i]);
i++;
}
facts_init(&facts, NULL);
facts_add_tags(&facts, tag, tag + 1, tag + 2);
facts_add_tags(&facts, tag, tag + 1, tag + 3);
facts_add_tags(&facts, tag, tag + 4, tag + 3);
facts_add_tags(&facts, tag + 5, tag + 1, tag + 2);
facts_add_tags(&facts, tag + 6, tag + 7, tag + 2);
i = 0;
facts_with(&facts, &cursor, (s_tag *[])
{ tag_init_var(&subject),
tag_init_var(&predicate),
tag_init_var(&object),
NULL, NULL });
fact_init(&fact, tag, tag + 1, tag + 2);
FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
fact_init(&fact, tag, tag + 1, tag + 3);
FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
fact_init(&fact, tag, tag + 4, tag + 3);
FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
fact_init(&fact, tag + 5, tag + 1, tag + 2);
FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
fact_init(&fact, tag + 6, tag + 7, tag + 2);
FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
TEST_EQ(facts_with_cursor_next(&cursor), NULL);
TEST_EQ(facts_with_cursor_next(&cursor), NULL);
facts_with_cursor_clean(&cursor);
facts_with(&facts, &cursor, (s_tag *[]) { tag,
tag_init_var(&predicate),
tag_init_var(&object),
NULL, NULL });
fact_init(&fact, tag, tag + 1, tag + 2);
FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
fact_init(&fact, tag, tag + 1, tag + 3);
FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
fact_init(&fact, tag, tag + 4, tag + 3);
FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
TEST_EQ(facts_with_cursor_next(&cursor), NULL);
TEST_EQ(facts_with_cursor_next(&cursor), NULL);
facts_with_cursor_clean(&cursor);
facts_with(&facts, &cursor, (s_tag *[]) { tag,
tag + 1,
tag_init_var(&object),
NULL, NULL });
fact_init(&fact, tag, tag + 1, tag + 2);
FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
fact_init(&fact, tag, tag + 1, tag + 3);
FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
TEST_EQ(facts_with_cursor_next(&cursor), NULL);
TEST_EQ(facts_with_cursor_next(&cursor), NULL);
facts_with_cursor_clean(&cursor);
facts_with(&facts, &cursor, (s_tag *[]) { tag, tag + 1, tag + 2,
NULL, NULL });
fact_init(&fact, tag, tag + 1, tag + 2);
FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
TEST_EQ(facts_with_cursor_next(&cursor), NULL);
TEST_EQ(facts_with_cursor_next(&cursor), NULL);
facts_with_cursor_clean(&cursor);
facts_with(&facts, &cursor, (s_tag *[]) { tag_init_var(&subject),
tag_init_var(&predicate),
tag_init_var(&object),
NULL,
&subject,
tag + 1,
&object,
NULL, NULL });
TEST_ASSERT(facts_with_cursor_next(&cursor));
TAG_TEST_EQ(subject.data.var, tag);
TAG_TEST_EQ(predicate.data.var, tag + 1);
TAG_TEST_EQ(object.data.var, tag + 2);
TEST_ASSERT(facts_with_cursor_next(&cursor));
TAG_TEST_EQ(subject.data.var, tag);
TAG_TEST_EQ(predicate.data.var, tag + 1);
TAG_TEST_EQ(object.data.var, tag + 3);
TEST_ASSERT(facts_with_cursor_next(&cursor));
TAG_TEST_EQ(subject.data.var, tag + 5);
TAG_TEST_EQ(predicate.data.var, tag + 1);
TAG_TEST_EQ(object.data.var, tag + 2);
TEST_ASSERT(facts_with_cursor_next(&cursor));
TAG_TEST_EQ(subject.data.var, tag);
TAG_TEST_EQ(predicate.data.var, tag + 1);
TAG_TEST_EQ(object.data.var, tag + 3);
TEST_ASSERT(facts_with_cursor_next(&cursor));
TAG_TEST_EQ(subject.data.var, tag);
TAG_TEST_EQ(predicate.data.var, tag + 4);
TAG_TEST_EQ(object.data.var, tag + 3);
TEST_EQ(facts_with_cursor_next(&cursor), NULL);
TEST_EQ(facts_with_cursor_next(&cursor), NULL);
facts_with_cursor_clean(&cursor);
facts_with(&facts, &cursor, (s_tag *[]) { tag + 3, tag, tag + 1,
tag, tag + 2,
NULL,
tag + 4, tag + 1, tag + 2,
NULL, NULL });
TEST_EQ(facts_with_cursor_next(&cursor), NULL);
TEST_EQ(facts_with_cursor_next(&cursor), NULL);
facts_with_cursor_clean(&cursor);
facts_with(&facts, &cursor, (s_tag *[]) { tag_init_var(&subject),
tag_init_var(&predicate),
tag_init_var(&object),
NULL,
tag + 3, tag, tag + 1,
tag, tag + 2,
NULL,
tag + 4, tag + 1, tag + 2,
NULL, NULL });
TEST_EQ(facts_with_cursor_next(&cursor), NULL);
TEST_EQ(facts_with_cursor_next(&cursor), NULL);
facts_with_cursor_clean(&cursor);
facts_with(&facts, &cursor, (s_tag *[]) { tag_init_var(&subject),
tag_init_var(&predicate),
tag_init_var(&object),
NULL,
tag, tag + 1, tag + 2,
tag, tag + 2,
NULL,
tag + 4, tag + 1, tag + 2,
NULL, NULL });
TEST_EQ(facts_with_cursor_next(&cursor), NULL);
TEST_EQ(facts_with_cursor_next(&cursor), NULL);
facts_with_cursor_clean(&cursor);
facts_clean(&facts);
}
void facts_with_test_tags ()
{
s_facts_cursor cursor;
s_fact fact;
s_facts facts;
sw i = 0;
s_tag object;
const s8 *p[9] = { "A", "B", "C", "D", "E", "F", "G", "H", NULL };
s_tag predicate;
s_tag subject;
s_tag tag[8];
while (p[i]) {
tag_init_1(tag + i, p[i]);
i++;
}
facts_init(&facts, NULL);
facts_add_tags(&facts, tag, tag + 1, tag + 2);
facts_add_tags(&facts, tag, tag + 1, tag + 3);
facts_add_tags(&facts, tag, tag + 4, tag + 3);
facts_add_tags(&facts, tag + 5, tag + 1, tag + 2);
facts_add_tags(&facts, tag + 6, tag + 7, tag + 2);
i = 0;
facts_with_tags(&facts, &cursor,
tag_init_var(&subject),
tag_init_var(&predicate),
tag_init_var(&object));
fact_init(&fact, tag, tag + 1, tag + 2);
FACT_TEST_EQ(&fact, facts_cursor_next(&cursor));
fact_init(&fact, tag, tag + 1, tag + 3);
FACT_TEST_EQ(&fact, facts_cursor_next(&cursor));
fact_init(&fact, tag, tag + 4, tag + 3);
FACT_TEST_EQ(&fact, facts_cursor_next(&cursor));
fact_init(&fact, tag + 5, tag + 1, tag + 2);
FACT_TEST_EQ(&fact, facts_cursor_next(&cursor));
fact_init(&fact, tag + 6, tag + 7, tag + 2);
FACT_TEST_EQ(&fact, facts_cursor_next(&cursor));
FACT_TEST_EQ(NULL, facts_cursor_next(&cursor));
facts_with_tags(&facts, &cursor,
tag,
tag_init_var(&predicate),
tag_init_var(&object));
fact_init(&fact, tag, tag + 1, tag + 2);
FACT_TEST_EQ(&fact, facts_cursor_next(&cursor));
fact_init(&fact, tag, tag + 1, tag + 3);
FACT_TEST_EQ(&fact, facts_cursor_next(&cursor));
fact_init(&fact, tag, tag + 4, tag + 3);
FACT_TEST_EQ(&fact, facts_cursor_next(&cursor));
FACT_TEST_EQ(NULL, facts_cursor_next(&cursor));
facts_with_tags(&facts, &cursor,
tag,
tag + 1,
tag_init_var(&object));
fact_init(&fact, tag, tag + 1, tag + 2);
FACT_TEST_EQ(&fact, facts_cursor_next(&cursor));
fact_init(&fact, tag, tag + 1, tag + 3);
FACT_TEST_EQ(&fact, facts_cursor_next(&cursor));
FACT_TEST_EQ(NULL, facts_cursor_next(&cursor));
facts_with_tags(&facts, &cursor, tag, tag + 1, tag + 2);
fact_init(&fact, tag, tag + 1, tag + 2);
FACT_TEST_EQ(&fact, facts_cursor_next(&cursor));
FACT_TEST_EQ(NULL, facts_cursor_next(&cursor));
facts_clean(&facts);
}