diff --git a/libc3/bool.h b/libc3/bool.h
index c82a494..db00baa 100644
--- a/libc3/bool.h
+++ b/libc3/bool.h
@@ -23,7 +23,6 @@
#include "types.h"
/* Observers */
-s8 bool_compare (e_bool a, e_bool b);
s_str * bool_inspect (e_bool b, s_str *dest);
#endif /* SYM_H */
diff --git a/libc3/character.h b/libc3/character.h
index 615653a..db9ed19 100644
--- a/libc3/character.h
+++ b/libc3/character.h
@@ -18,7 +18,6 @@
#include "types.h"
character character_1 (const s8 *p);
-s8 character_compare (character a, character b);
void character_hash_update (character c, t_hash *hash);
e_bool character_is_digit (character c);
e_bool character_is_lowercase (character c);
diff --git a/libc3/compare.c b/libc3/compare.c
index f697a86..ba6c23f 100644
--- a/libc3/compare.c
+++ b/libc3/compare.c
@@ -11,7 +11,10 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
+#include <assert.h>
+#include <err.h>
#include "compare.h"
+#include "tag.h"
#define COMPARE_DEF(type) \
s8 compare_##type (type a, type b) \
@@ -37,13 +40,167 @@ s8 compare_call (const s_call *a, const s_call *b)
return compare_list(a->arguments, b->arguments);
}
-COMPARE_DEF(f32);
-COMPARE_DEF(f64);
-COMPARE_DEF(s8);
-COMPARE_DEF(s16);
-COMPARE_DEF(s32);
-COMPARE_DEF(s64);
-COMPARE_DEF(u8);
-COMPARE_DEF(u16);
-COMPARE_DEF(u32);
-COMPARE_DEF(u64);
+
+COMPARE_DEF(f32)
+
+COMPARE_DEF(f64)
+
+s8 compare_fact (const s_fact *a, const s_fact *b)
+{
+ s8 r;
+ if (a == b)
+ return 0;
+ if (!a)
+ return -1;
+ if (!b)
+ return 1;
+ if ((r = compare_tag(a->subject, b->subject)))
+ return r;
+ if ((r = compare_tag(a->predicate, b->predicate)))
+ return r;
+ r = compare_tag(a->object, b->object);
+ return r;
+}
+
+s8 fact_compare_unbound_var_count (const s_fact *a,
+ const s_fact *b)
+{
+ u8 a_count;
+ u8 b_count;
+ if (a == b)
+ return 0;
+ if (!a)
+ return -1;
+ if (!b)
+ return 1;
+ a_count = 0;
+ b_count = 0;
+ if (tag_is_unbound_var(a->subject))
+ a_count++;
+ if (tag_is_unbound_var(a->predicate))
+ a_count++;
+ if (tag_is_unbound_var(a->object))
+ a_count++;
+ if (tag_is_unbound_var(b->subject))
+ b_count++;
+ if (tag_is_unbound_var(b->predicate))
+ b_count++;
+ if (tag_is_unbound_var(b->object))
+ b_count++;
+ return compare_u8(a_count, b_count);
+}
+
+s8 compare_fact_pos (const s_fact *a, const s_fact *b)
+{
+ s8 r;
+ if (a == b)
+ return 0;
+ if (!a)
+ return -1;
+ if (!b)
+ return 1;
+ if ((r = compare_tag(a->predicate, b->predicate)))
+ return r;
+ if ((r = compare_tag(a->object, b->object)))
+ return r;
+ r = compare_tag(a->subject, b->subject);
+ return r;
+}
+
+s8 compare_fact_osp (const s_fact *a, const s_fact *b)
+{
+ s8 r;
+ if (a == b)
+ return 0;
+ if (!a)
+ return -1;
+ if (!b)
+ return 1;
+ if ((r = compare_tag(a->object, b->object)))
+ return r;
+ if ((r = compare_tag(a->subject, b->subject)))
+ return r;
+ r = compare_tag(a->predicate, b->predicate);
+ return r;
+}
+
+s8 compare_ptr (const void *a, const void *b)
+{
+ if (a < b)
+ return -1;
+ if (a == b)
+ return 0;
+ return 1;
+}
+
+COMPARE_DEF(s8)
+
+COMPARE_DEF(s16)
+
+COMPARE_DEF(s32)
+
+COMPARE_DEF(s64)
+
+s8 compare_tag (const s_tag *a, const s_tag *b) {
+ if (tag_is_bound_var(a))
+ a = a->data.var;
+ if (tag_is_bound_var(b))
+ b = b->data.var;
+ if (a == b)
+ return 0;
+ if (!a ||
+ a == TAG_FIRST ||
+ b == TAG_LAST)
+ return -1;
+ if (!b ||
+ a == TAG_LAST ||
+ b == TAG_FIRST)
+ return 1;
+ if (a->type.type < b->type.type)
+ return -1;
+ if (a->type.type > b->type.type)
+ return 1;
+ switch (a->type.type) {
+ case TAG_VOID: return 0;
+ case TAG_BOOL: return compare_bool(a->data.bool, b->data.bool);
+ case TAG_CALL:
+ case TAG_CALL_FN:
+ case TAG_CALL_MACRO:
+ return compare_call(&a->data.call, &b->data.call);
+ case TAG_CHARACTER: return compare_character(a->data.character,
+ b->data.character);
+ case TAG_F32: return compare_f32(a->data.f32, b->data.f32);
+ case TAG_F64: return compare_f64(a->data.f64, b->data.f64);
+ case TAG_FN: return compare_ptr(a, b);
+ case TAG_IDENT: return compare_ident(&a->data.ident, &b->data.ident);
+ case TAG_INTEGER: return compare_integer(&a->data.integer,
+ &b->data.integer);
+ case TAG_LIST: return compare_list(a->data.list, b->data.list);
+ case TAG_PTAG: return compare_ptag(a->data.ptag, b->data.ptag);
+ case TAG_QUOTE: return compare_quote(a->data.quote, b->data.quote);
+ case TAG_S8: return compare_s8(a->data.s8, b->data.s8);
+ case TAG_S16: return compare_s16(a->data.s16, b->data.s16);
+ case TAG_S32: return compare_s32(a->data.s32, b->data.s32);
+ case TAG_S64: return compare_s64(a->data.s64, b->data.s64);
+ case TAG_STR: return compare_str(&a->data.str, &b->data.str);
+ case TAG_SYM: return compare_str(&a->data.sym->str,
+ &b->data.sym->str);
+ case TAG_TUPLE: return compare_tuple(&a->data.tuple, &b->data.tuple);
+ case TAG_U8: return compare_u8(a->data.u8, b->data.u8);
+ case TAG_U16: return compare_u16(a->data.u16, b->data.u16);
+ case TAG_U32: return compare_u32(a->data.u32, b->data.u32);
+ case TAG_U64: return compare_u64(a->data.u64, b->data.u64);
+ case TAG_VAR: return compare_ptr(a->data.var, b->data.var);
+ }
+ assert(! "compare_tag: error");
+ errx(1, "compare_tag");
+ return 0;
+}
+
+COMPARE_DEF(u8)
+
+COMPARE_DEF(u16)
+
+COMPARE_DEF(u32)
+
+COMPARE_DEF(u64)
diff --git a/libc3/compare.h b/libc3/compare.h
index 1d8f6e0..233e06f 100644
--- a/libc3/compare.h
+++ b/libc3/compare.h
@@ -19,7 +19,9 @@
#define COMPARE_PROTOTYPE(type) \
s8 compare_##type (type a, type b)
+s8 compare_bool (e_bool a, e_bool b);
s8 compare_call (const s_call *a, const s_call *b);
+s8 compare_character (character a, character b);
COMPARE_PROTOTYPE(f32);
COMPARE_PROTOTYPE(f64);
s8 compare_fact (const s_fact *a, const s_fact *b);
@@ -31,12 +33,15 @@ s8 compare_ident (const s_ident *a, const s_ident *b);
s8 compare_integer (const s_integer *a, const s_integer *b);
s8 compare_integer_s64 (const s_integer *a, s64 b);
s8 compare_integer_u64 (const s_integer *a, u64 b);
+s8 compare_list (const s_list *a, const s_list *b);
s8 compare_ptag (const p_tag a, const p_tag b);
s8 compare_quote (const p_quote a, const p_quote b);
COMPARE_PROTOTYPE(s8);
COMPARE_PROTOTYPE(s16);
COMPARE_PROTOTYPE(s32);
COMPARE_PROTOTYPE(s64);
+s8 compare_str (const s_str *a, const s_str *b);
+s8 compare_tag (const s_tag *a, const s_tag *b);
s8 compare_tuple (const s_tuple *a, const s_tuple *b);
COMPARE_PROTOTYPE(u8);
COMPARE_PROTOTYPE(u16);
diff --git a/libc3/fact.c b/libc3/fact.c
index 7c4b594..ede4bd4 100644
--- a/libc3/fact.c
+++ b/libc3/fact.c
@@ -19,85 +19,6 @@
#include "fact.h"
#include "tag.h"
-s8 fact_compare (const s_fact *a, const s_fact *b)
-{
- s8 r;
- if (a == b)
- return 0;
- if (!a)
- return -1;
- if (!b)
- return 1;
- if ((r = tag_compare(a->subject, b->subject)))
- return r;
- if ((r = tag_compare(a->predicate, b->predicate)))
- return r;
- r = tag_compare(a->object, b->object);
- return r;
-}
-
-s8 fact_compare_unbound_var_count (const s_fact *a,
- const s_fact *b)
-{
- u8 ca;
- u8 cb;
- if (a == b)
- return 0;
- if (!a)
- return -1;
- if (!b)
- return 1;
- ca = 0;
- cb = 0;
- if (tag_is_unbound_var(a->subject))
- ca++;
- if (tag_is_unbound_var(a->predicate))
- ca++;
- if (tag_is_unbound_var(a->object))
- ca++;
- if (tag_is_unbound_var(b->subject))
- cb++;
- if (tag_is_unbound_var(b->predicate))
- cb++;
- if (tag_is_unbound_var(b->object))
- cb++;
- return u8_compare(ca, cb);
-}
-
-s8 fact_compare_pos (const s_fact *a, const s_fact *b)
-{
- s8 r;
- if (a == b)
- return 0;
- if (!a)
- return -1;
- if (!b)
- return 1;
- if ((r = tag_compare(a->predicate, b->predicate)))
- return r;
- if ((r = tag_compare(a->object, b->object)))
- return r;
- r = tag_compare(a->subject, b->subject);
- return r;
-}
-
-s8 fact_compare_osp (const s_fact *a, const s_fact *b)
-{
- s8 r;
- if (a == b)
- return 0;
- if (!a)
- return -1;
- if (!b)
- return 1;
- if ((r = tag_compare(a->object, b->object)))
- return r;
- if ((r = tag_compare(a->subject, b->subject)))
- return r;
- r = tag_compare(a->predicate, b->predicate);
- return r;
-}
-
s_fact * fact_copy (const s_fact *src, s_fact *dest)
{
assert(src);
@@ -111,7 +32,7 @@ uw fact_hash_uw (const s_fact *fact)
t_hash hash;
assert(fact);
hash_init(&hash);
- fact_hash_update(&hash, fact);
+ hash_update_fact(&hash, fact);
return hash_to_uw(&hash);
}
diff --git a/libc3/facts.c b/libc3/facts.c
index 1f083fb..559ee73 100644
--- a/libc3/facts.c
+++ b/libc3/facts.c
@@ -19,6 +19,7 @@
#include "buf_file.h"
#include "buf_inspect.h"
#include "buf_parse.h"
+#include "compare.h"
#include "fact.h"
#include "facts.h"
#include "facts_cursor.h"
@@ -100,12 +101,6 @@ sw facts_dump (const s_facts *facts, s_buf *buf)
if ((r = buf_inspect_u64_hex(buf, facts_count(facts))) < 0)
return r;
result += r;
- if ((r = buf_write_1(buf, ",\n digest: 0x")) < 0)
- return r;
- result += r;
- if ((r = buf_inspect_u64_hex(buf, digest)) < 0)
- return r;
- result += r;
if ((r = buf_write_1(buf, "}\n")) < 0)
return r;
result += r;
@@ -115,6 +110,17 @@ sw facts_dump (const s_facts *facts, s_buf *buf)
return r;
result += r;
}
+ /*
+ if ((r = buf_write_1(buf, "\n%{hash: 0x")) < 0)
+ return r;
+ result += r;
+ if ((r = buf_inspect_u64_hex(buf, hash_u64)) < 0)
+ return r;
+ result += r;
+ if ((r = buf_write_1(buf, "}\n")) < 0)
+ return r;
+ result += r;
+ */
return result;
}
@@ -170,25 +176,38 @@ s_facts * facts_init (s_facts *facts, s_buf *log)
set_init__fact(&facts->facts, 1024);
facts->index_spo = skiplist_new__fact(max_height, spacing);
assert(facts->index_spo);
- facts->index_spo->compare = fact_compare;
+ facts->index_spo->compare = compare_fact;
facts->index_pos = skiplist_new__fact(max_height, spacing);
assert(facts->index_pos);
- facts->index_pos->compare = fact_compare_pos;
+ facts->index_pos->compare = compare_fact_pos;
facts->index_osp = skiplist_new__fact(max_height, spacing);
assert(facts->index_osp);
- facts->index_osp->compare = fact_compare_osp;
+ facts->index_osp->compare = compare_fact_osp;
facts->log = log;
return facts;
}
sw facts_load (s_facts *facts, s_buf *buf)
{
+ u64 count;
s_fact fact;
+ u64 i;
sw r;
sw result = 0;
assert(facts);
assert(buf);
- while (1) {
+ if ((r = buf_read_1(buf,
+ "%{module: C3.Facts,\n"
+ " version: 0x0000000000000001,\n"
+ " count: 0x")) < 0)
+ return r;
+ result += r;
+ if ((r = buf_parse_u64_hex(buf, &count)) < 0)
+ return r;
+ if ((r = buf_write_1(buf, "}\n")) < 0)
+ return r;
+ result += r;
+ for (i = 0; i < count; i++) {
if ((r = buf_read_1(buf, "add ")) < 0)
break;
result += r;
@@ -276,29 +295,9 @@ sw facts_open_buf (s_facts *facts, s_buf *buf)
u64 log_pos;
sw r;
if ((r = buf_read_1(buf,
- "%{module: C3.Facts,\n"
- " version: 0x0000000000000001,\n"
- " count: 0x")) < 0)
- return r;
- if ((r = buf_parse_u64_hex(buf, &count)) < 0)
- return r;
- if ((r = buf_read_1(buf, ",\n digest: 0x")) < 0)
- return r;
- if ((r = buf_parse_u64_hex(buf, &digest)) < 0)
- return r;
- if ((r = buf_read_1(buf, ",\n dump: 0x")) < 0)
- return r;
- if ((r = buf_parse_u64_hex(buf, &dump_pos)) < 0)
- return r;
- if ((r = buf_read_1(buf, ",\n log: 0x")) < 0)
- return r;
- if ((r = buf_parse_u64_hex(buf, &log_pos)) < 0)
- return r;
- if ((r = buf_read_1(buf, "}\n")) < 0)
- return r;
- if ((r = buf_seek(buf, dump_pos, SEEK_SET)) < 0)
- return r;
- if ((r = facts_open_buf_read_dump(facts, buf, count, digest)) < 0)
+ "%{module: C3.Facts.Open,\n"
+ " version: 0x0000000000000001}"
+ if ((r = facts_load(facts, buf)) < 0)
return r;
if ((r = buf_seek(buf, log_pos, SEEK_SET)) < 0)
return r;
diff --git a/libc3/hash.h b/libc3/hash.h
index 412f551..c2e16dd 100644
--- a/libc3/hash.h
+++ b/libc3/hash.h
@@ -37,6 +37,7 @@ HASH_UPDATE_PROTOTYPE(s8);
HASH_UPDATE_PROTOTYPE(s16);
HASH_UPDATE_PROTOTYPE(s32);
HASH_UPDATE_PROTOTYPE(s64);
+void hash_update_str (t_hash *hash, const s_str *src);
void hash_update_tag (t_hash *hash, const s_tag *tag);
void hash_update_tuple (t_hash *hash, const s_tuple *tuple);
HASH_UPDATE_PROTOTYPE(u8);
diff --git a/libc3/list.h b/libc3/list.h
index cca17be..097b650 100644
--- a/libc3/list.h
+++ b/libc3/list.h
@@ -38,7 +38,6 @@ s_list * list_delete (s_list *list);
void list_delete_all (s_list *list);
/* Observers */
-s8 list_compare (const s_list *a, const s_list *b);
s_list * list_copy (const s_list *src, s_list **dest);
sw list_length (const s_list *list);
s_list * list_next (const s_list *list);
diff --git a/libc3/str.h b/libc3/str.h
index b5f4b34..27133a3 100644
--- a/libc3/str.h
+++ b/libc3/str.h
@@ -54,10 +54,8 @@ void str_delete (s_str *str);
/* Observers */
character str_character_escape (character c);
e_bool str_character_is_reserved (character c);
-sw str_compare (const s_str *a, const s_str *b);
s_str * str_copy (const s_str *src, s_str *dest);
e_bool str_has_reserved_characters (const s_str *str);
-void str_hash_update (const s_str *src, t_hash *hash);
s_str * str_inspect (const s_str *x, s_str *dest);
sw str_peek_bool (const s_str *src, bool *p);
sw str_peek_character (const s_str *src, character *p);
diff --git a/libc3/tag.c b/libc3/tag.c
index ed08a51..3579ccb 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -128,62 +128,6 @@ void tag_clean (s_tag *tag)
}
}
-s8 tag_compare (const s_tag *a, const s_tag *b) {
- if (tag_is_bound_var(a))
- a = a->data.var;
- if (tag_is_bound_var(b))
- b = b->data.var;
- if (a == b)
- return 0;
- if (!a ||
- a == TAG_FIRST ||
- b == TAG_LAST)
- return -1;
- if (!b ||
- a == TAG_LAST ||
- b == TAG_FIRST)
- return 1;
- if (a->type.type < b->type.type)
- return -1;
- if (a->type.type > b->type.type)
- return 1;
- switch (a->type.type) {
- case TAG_VOID: return 0;
- case TAG_BOOL: return bool_compare(a->data.bool, b->data.bool);
- case TAG_CALL:
- case TAG_CALL_FN:
- case TAG_CALL_MACRO:
- return call_compare(&a->data.call, &b->data.call);
- case TAG_CHARACTER: return character_compare(a->data.character,
- b->data.character);
- case TAG_F32: return f32_compare(a->data.f32, b->data.f32);
- case TAG_F64: return f64_compare(a->data.f64, b->data.f64);
- case TAG_FN: return ptr_compare(a, b);
- case TAG_IDENT: return ident_compare(&a->data.ident, &b->data.ident);
- case TAG_INTEGER: return integer_compare(&a->data.integer,
- &b->data.integer);
- case TAG_LIST: return list_compare(a->data.list, b->data.list);
- case TAG_PTAG: return ptag_compare(a->data.ptag, b->data.ptag);
- case TAG_QUOTE: return quote_compare(a->data.quote, b->data.quote);
- case TAG_S8: return s8_compare(a->data.s8, b->data.s8);
- case TAG_S16: return s16_compare(a->data.s16, b->data.s16);
- case TAG_S32: return s32_compare(a->data.s32, b->data.s32);
- case TAG_S64: return s64_compare(a->data.s64, b->data.s64);
- case TAG_STR: return str_compare(&a->data.str, &b->data.str);
- case TAG_SYM: return str_compare(&a->data.sym->str,
- &b->data.sym->str);
- case TAG_TUPLE: return tuple_compare(&a->data.tuple, &b->data.tuple);
- case TAG_U8: return u8_compare(a->data.u8, b->data.u8);
- case TAG_U16: return u16_compare(a->data.u16, b->data.u16);
- case TAG_U32: return u32_compare(a->data.u32, b->data.u32);
- case TAG_U64: return u64_compare(a->data.u64, b->data.u64);
- case TAG_VAR: return ptr_compare(a->data.var, b->data.var);
- }
- assert(! "tag_compare: error");
- errx(1, "tag_compare");
- return 0;
-}
-
s_tag * tag_copy (const s_tag *src, s_tag *dest)
{
assert(src);
diff --git a/libc3/tag.h b/libc3/tag.h
index 5ef2733..facef48 100644
--- a/libc3/tag.h
+++ b/libc3/tag.h
@@ -87,7 +87,6 @@ s_tag * tag_new_var ();
void tag_delete (s_tag *tag);
/* Observers */
-s8 tag_compare (const s_tag *a, const s_tag *b);
u64 tag_hash_u64 (const s_tag *tag);
uw tag_hash_uw (const s_tag *tag);
s_str * tag_inspect (const s_tag *tag, s_str *dest);
diff --git a/test/compare_test.c b/test/compare_test.c
new file mode 100644
index 0000000..d550d44
--- /dev/null
+++ b/test/compare_test.c
@@ -0,0 +1,272 @@
+/* c3
+ * Copyright 2022 kmx.io <contact@kmx.io>
+ *
+ * Permission is hereby granted to use this software excepted
+ * on Apple computers 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 "test.h"
+#include "../libc3/compare.h"
+#include "../libc3/tag.h"
+
+#define COMPARE_TEST_TAG(a, b, expected) \
+ do { \
+ TEST_EQ(compare_tag((a), (b)), (expected)); \
+ } while (0)
+
+void compare_test_f32 ();
+void compare_test_f64 ();
+
+void compare_test ()
+{
+ compare_test_f32();
+ compare_test_f64();
+}
+
+void compare_test_f32 ()
+{
+ TEST_EQ(compare_f32('0', '0'), 0);
+ TEST_EQ(compare_f32('0', '1'), -1);
+ TEST_EQ(compare_f32('1', '0'), 1);
+ TEST_EQ(compare_f32(1.0, 1.0), 0);
+ TEST_EQ(compare_f32(1.0, 2.0), -1);
+ TEST_EQ(compare_f32(1.0, 0.0), 1);
+ TEST_EQ(compare_f32(10000000000000000000000.0,
+ 10000000000000000000000.0),
+ 0);
+ TEST_EQ(compare_f32(3.40282346638528859811704183484516925440e+38,
+ 3.40282346638528859811704183484516925440e+38),
+ 0);
+ TEST_EQ(compare_f32(1.797693134862315708145274237317043567981e+38,
+ 1.797693134862315708145274237317043567981e+38),
+ 0);
+ TEST_EQ(compare_f32(1.797693134862315708145274237317043567981e+38,
+ 1.797693134862315708145274237317043567981e+38),
+ 0);
+ TEST_EQ(compare_f32(1.597693134862315708145274237317043567981e+38,
+ 1.797693134862315708145274237317043567980e+38),
+ -1);
+ TEST_EQ(compare_f32(1.797693134862315708145274237317043567980e+38,
+ 1.597693134862315708145274237317043567981e+38),
+ 1);
+}
+
+void compare_test_f64 ()
+{
+ TEST_EQ(compare_f64(0.0, 0.0), 0);
+ TEST_EQ(compare_f64(0.0, 1.0), -1);
+ TEST_EQ(compare_f64(1.0, 0.0), 1);
+ TEST_EQ(compare_f64(1.0, 1.0), 0);
+ TEST_EQ(compare_f64(10000000000000000000000.0,
+ 10000000000000000000000.0),
+ 0);
+ TEST_EQ(compare_f64(3.40282346638528859811704183484516925440e+38,
+ 3.40282346638528859811704183484516925440e+38),
+ 0);
+ TEST_EQ(compare_f64(1.797693134862315708145274237317043567981e+308,
+ 1.797693134862315708145274237317043567981e+308),
+ 0);
+ TEST_EQ(compare_f64(1.597693134862315708145274237317043567981e+308,
+ 1.797693134862315708145274237317043567980e+308),
+ -1);
+ TEST_EQ(compare_f64(1.797693134862315708145274237317043567980e+308,
+ 1.597693134862315708145274237317043567981e+308),
+ 1);
+}
+
+void compare_test_tag ()
+{
+ s_tag a;
+ s_tag b;
+ /* tuple */
+ COMPARE_TEST_TAG(tag_init_1(&a, "{a, b}"), &a, 0);
+ COMPARE_TEST_TAG(tag_1(&a, "{a, b}"), tag_init_1(&b, "{a, b}"), 0);
+ COMPARE_TEST_TAG(tag_1(&a, "{{a, b}, {c, d}}"),
+ tag_1(&b, "{{a, b}, {c, d}}"), 0);
+ /* integer <> s8 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x10000000000000000"),
+ tag_1(&b, "-0x7F"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x7F"),
+ tag_1(&b, "-0x10000000000000000"), 1);
+ /* integer <> s16 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x10000000000000000"),
+ tag_1(&b, "-0x7FFF"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x7FFF"),
+ tag_1(&b, "-0x10000000000000000"), 1);
+ /* integer <> s32 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x10000000000000000"),
+ tag_1(&b, "-0x7FFFFFFF"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x7FFFFFFF"),
+ tag_1(&b, "-0x10000000000000000"), 1);
+ /* integer <> s64 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x10000000000000000"),
+ tag_1(&b, "-0x7FFFFFFFFFFFFFFF"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x7FFFFFFFFFFFFFFF"),
+ tag_1(&b, "-0x10000000000000000"), 1);
+ /* integer <> u8 */
+ COMPARE_TEST_TAG(tag_1(&a, "0xFF"),
+ tag_1(&b, "0x10000000000000000"), 1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x10000000000000000"),
+ tag_1(&b, "0xFF"), -1);
+ /* integer <> u16 */
+ COMPARE_TEST_TAG(tag_1(&a, "0xFFFF"),
+ tag_1(&b, "0x10000000000000000"), 1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x10000000000000000"),
+ tag_1(&b, "0xFFFF"), -1);
+ /* integer <> u32 */
+ COMPARE_TEST_TAG(tag_1(&a, "0xFFFFFFFF"),
+ tag_1(&b, "0x10000000000000000"), 1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x10000000000000000"),
+ tag_1(&b, "0xFFFFFFFF"), -1);
+ /* integer <> u64 */
+ COMPARE_TEST_TAG(tag_1(&a, "0xFFFFFFFFFFFFFFFF"),
+ tag_1(&b, "0x10000000000000000"), 1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x10000000000000000"),
+ tag_1(&b, "0xFFFFFFFFFFFFFFFF"), -1);
+ /* s8 <> s8 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x7F"), tag_1(&b, "-0x7F"), 0);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x7F"), tag_1(&b, "-1"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "-1"), tag_1(&b, "-0x7F"), 1);
+ COMPARE_TEST_TAG(tag_1(&a, "-1"), tag_1(&b, "-1"), 0);
+ /* s8 <> s16 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "-0x7F"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x7F"), tag_1(&b, "-0x100"), 1);
+ /* s8 <> s32 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x10000"), tag_1(&b, "-0x7F"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x7F"), tag_1(&b, "-0x10000"), 1);
+ /* s8 <> s64 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"), tag_1(&b, "-0x7F"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x7F"), tag_1(&b, "-0x100000000"), 1);
+ /* s8 <> u8 */
+ COMPARE_TEST_TAG(tag_1(&a, "-1"), tag_1(&b, "0"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "-1"), 1);
+ /* s8 <> u16 */
+ COMPARE_TEST_TAG(tag_1(&a, "-1"), tag_1(&b, "0x100"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "-1"), 1);
+ /* s8 <> u32 */
+ COMPARE_TEST_TAG(tag_1(&a, "-1"), tag_1(&b, "0x10000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x10000"), tag_1(&b, "-1"), 1);
+ /* s8 <> u64 */
+ COMPARE_TEST_TAG(tag_1(&a, "-1"), tag_1(&b, "0x100000000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x100000000"), tag_1(&b, "-1"), 1);
+ /* s16 <> s16 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "-0x100"), 0);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x200"), tag_1(&b, "-0x100"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "-0x200"), 1);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x200"), tag_1(&b, "-0x200"), 0);
+ /* s16 <> s32 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x10000"), tag_1(&b, "-0x100"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "-0x10000"), 1);
+ /* s16 <> s64 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"), tag_1(&b, "-0x100"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "-0x100000000"), 1);
+ /* s16 <> u8 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "0"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "-0x100"), 1);
+ /* s16 <> u16 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "0x100"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "-0x100"), 1);
+ /* s16 <> u32 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "0x10000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x10000"), tag_1(&b, "-0x100"), 1);
+ /* s16 <> u64 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "0x100000000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x100000000"), tag_1(&b, "-0x100"), 1);
+ /* s32 <> s32 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x10000"), tag_1(&b, "-0x10000"), 0);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x20000"), tag_1(&b, "-0x10000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x10000"), tag_1(&b, "-0x20000"), 1);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x20000"), tag_1(&b, "-0x20000"), 0);
+ /* s32 <> s64 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"), tag_1(&b, "-0x10000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x10000"), tag_1(&b, "-0x100000000"), 1);
+ /* s32 <> u8 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x10000"), tag_1(&b, "0"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "-0x10000"), 1);
+ /* s32 <> u16 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x10000"), tag_1(&b, "0x100"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "-0x10000"), 1);
+ /* s32 <> u32 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x10000"), tag_1(&b, "0x10000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x10000"), tag_1(&b, "-0x10000"), 1);
+ /* s32 <> u64 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x10000"),
+ tag_1(&b, "0x100000000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x100000000"),
+ tag_1(&b, "-0x10000"), 1);
+ /* s64 <> s64 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"),
+ tag_1(&b, "-0x100000000"), 0);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x200000000"),
+ tag_1(&b, "-0x100000000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"),
+ tag_1(&b, "-0x200000000"), 1);
+ COMPARE_TEST_TAG(tag_1(&a, "-0x200000000"),
+ tag_1(&b, "-0x200000000"), 0);
+ /* s64 <> u8 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"), tag_1(&b, "0"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "-0x100000000"), 1);
+ /* s64 <> u16 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"), tag_1(&b, "0x100"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "-0x100000000"), 1);
+ /* s64 <> u32 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"),
+ tag_1(&b, "0x10000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x10000"),
+ tag_1(&b, "-0x100000000"), 1);
+ /* s64 <> u64 */
+ COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"),
+ tag_1(&b, "0x100000000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x100000000"),
+ tag_1(&b, "-0x100000000"), 1);
+ /* u8 <> u8 */
+ COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "0"), 0);
+ COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "1"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "1"), tag_1(&b, "0"), 1);
+ COMPARE_TEST_TAG(tag_1(&a, "1"), tag_1(&b, "1"), 0);
+ /* u8 <> u16 */
+ COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "0x100"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "0"), 1);
+ /* u8 <> u32 */
+ COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "0x10000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x10000"), tag_1(&b, "0"), 1);
+ /* u8 <> u64 */
+ COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "0x100000000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x100000000"), tag_1(&b, "0"), 1);
+ /* u16 <> u16 */
+ COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "0x100"), 0);
+ COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "0x200"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x200"), tag_1(&b, "0x100"), 1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x200"), tag_1(&b, "0x200"), 0);
+ /* u16 <> u32 */
+ COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "0x10000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x10000"), tag_1(&b, "0x100"), 1);
+ /* u16 <> u64 */
+ COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "0x100000000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x100000000"), tag_1(&b, "0x100"), 1);
+ /* u32 <> u32 */
+ COMPARE_TEST_TAG(tag_1(&a, "0x10000"), tag_1(&b, "0x10000"), 0);
+ COMPARE_TEST_TAG(tag_1(&a, "0x10000"), tag_1(&b, "0x20000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x20000"), tag_1(&b, "0x10000"), 1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x20000"), tag_1(&b, "0x20000"), 0);
+ /* u32 <> u64 */
+ COMPARE_TEST_TAG(tag_1(&a, "0x10000"), tag_1(&b, "0x100000000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x100000000"), tag_1(&b, "0x10000"), 1);
+ /* u64 <> u64 */
+ COMPARE_TEST_TAG(tag_1(&a, "0x100000000"),
+ tag_1(&b, "0x100000000"), 0);
+ COMPARE_TEST_TAG(tag_1(&a, "0x100000000"),
+ tag_1(&b, "0x200000000"), -1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x200000000"),
+ tag_1(&b, "0x100000000"), 1);
+ COMPARE_TEST_TAG(tag_1(&a, "0x200000000"),
+ tag_1(&b, "0x200000000"), 0);
+ tag_clean(&a);
+ tag_clean(&b);
+}
diff --git a/test/f32_test.c b/test/f32_test.c
deleted file mode 100644
index 040400a..0000000
--- a/test/f32_test.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/* c3
- * Copyright 2022 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software excepted
- * on Apple computers 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 <float.h>
-#include <math.h>
-#include <string.h>
-#include "test.h"
-#include "../libc3/f32.h"
-
-void f32_test_compare ();
-
-void f32_test ()
-{
- f32_test_compare();
-}
-
-void f32_test_compare ()
-{
- TEST_EQ(f32_compare('0', '0'), 0);
- TEST_EQ(f32_compare('0', '1'), -1);
- TEST_EQ(f32_compare('1', '0'), 1);
- TEST_EQ(f32_compare(1.0, 1.0), 0);
- TEST_EQ(f32_compare(1.0, 2.0), -1);
- TEST_EQ(f32_compare(1.0, 0.0), 1);
- TEST_EQ(f32_compare(10000000000000000000000.0,
- 10000000000000000000000.0), 0);
- TEST_EQ(f32_compare(3.40282346638528859811704183484516925440e+38,
- 3.40282346638528859811704183484516925440e+38), 0);
- TEST_EQ(f32_compare(1.797693134862315708145274237317043567981e+38,
- 1.797693134862315708145274237317043567981e+38), 0);
- TEST_EQ(f32_compare(1.797693134862315708145274237317043567981e+38,
- 1.797693134862315708145274237317043567981e+38), 0);
- TEST_EQ(f32_compare(1.597693134862315708145274237317043567981e+38,
- 1.797693134862315708145274237317043567980e+38), -1);
- TEST_EQ(f32_compare(1.797693134862315708145274237317043567980e+38,
- 1.597693134862315708145274237317043567981e+38), 1);
-}
diff --git a/test/f64_test.c b/test/f64_test.c
deleted file mode 100644
index 39739f2..0000000
--- a/test/f64_test.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/* c3
- * Copyright 2022 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software excepted
- * on Apple computers 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/f64.h"
-#include "test.h"
-
-void f64_test_compare ();
-
-void f64_test()
-{
- f64_test_compare();
-}
-
-void f64_test_compare ()
-{
- TEST_EQ(f64_compare(0.0, 0.0), 0);
- TEST_EQ(f64_compare(0.0, 1.0), -1);
- TEST_EQ(f64_compare(1.0, 0.0), 1);
- TEST_EQ(f64_compare(1.0, 1.0), 0);
- TEST_EQ(f64_compare(10000000000000000000000.0,
- 10000000000000000000000.0), 0);
- TEST_EQ(f64_compare(3.40282346638528859811704183484516925440e+38,
- 3.40282346638528859811704183484516925440e+38), 0);
- TEST_EQ(f64_compare(1.797693134862315708145274237317043567981e+308,
- 1.797693134862315708145274237317043567981e+308), 0);
- TEST_EQ(f64_compare(1.597693134862315708145274237317043567981e+308,
- 1.797693134862315708145274237317043567980e+308), -1);
- TEST_EQ(f64_compare(1.797693134862315708145274237317043567980e+308,
- 1.597693134862315708145274237317043567981e+308), 1);
-
- }
-
diff --git a/test/hash_test.c b/test/hash_test.c
new file mode 100644
index 0000000..8bb6d59
--- /dev/null
+++ b/test/hash_test.c
@@ -0,0 +1,15 @@
+/* c3
+ * Copyright 2022 kmx.io <contact@kmx.io>
+ *
+ * Permission is hereby granted to use this software excepted
+ * on Apple computers 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 <string.h>
+#include "test.h"
diff --git a/test/sources.mk b/test/sources.mk
index 52143f5..a84910e 100644
--- a/test/sources.mk
+++ b/test/sources.mk
@@ -1,2 +1,2 @@
# sources.mk generated by update_sources
-SOURCES = bool_test.c buf_file_test.c buf_inspect_test.c buf_parse_test.c buf_test.c call_test.c character_test.c f32_test.c f64_test.c fact_test.c facts_cursor_test.c facts_test.c facts_with_test.c ident_test.c libc3_test.c list_test.c set__fact_test.c set__tag_test.c skiplist__fact_test.c str_test.c sym_test.c tag_test.c test.c tuple_test.c types_test.c
+SOURCES = bool_test.c buf_file_test.c buf_inspect_test.c buf_parse_test.c buf_test.c call_test.c character_test.c compare_test.c fact_test.c facts_cursor_test.c facts_test.c facts_with_test.c hash_test.c ident_test.c libc3_test.c list_test.c set__fact_test.c set__tag_test.c skiplist__fact_test.c str_test.c sym_test.c tag_test.c test.c tuple_test.c types_test.c
diff --git a/test/sources.sh b/test/sources.sh
index 6c531df..565d8be 100644
--- a/test/sources.sh
+++ b/test/sources.sh
@@ -1,2 +1,2 @@
# sources.sh generated by update_sources
-SOURCES='bool_test.c buf_file_test.c buf_inspect_test.c buf_parse_test.c buf_test.c call_test.c character_test.c f32_test.c f64_test.c fact_test.c facts_cursor_test.c facts_test.c facts_with_test.c ident_test.c libc3_test.c list_test.c set__fact_test.c set__tag_test.c skiplist__fact_test.c str_test.c sym_test.c tag_test.c test.c tuple_test.c types_test.c '
+SOURCES='bool_test.c buf_file_test.c buf_inspect_test.c buf_parse_test.c buf_test.c call_test.c character_test.c compare_test.c fact_test.c facts_cursor_test.c facts_test.c facts_with_test.c hash_test.c ident_test.c libc3_test.c list_test.c set__fact_test.c set__tag_test.c skiplist__fact_test.c str_test.c sym_test.c tag_test.c test.c tuple_test.c types_test.c '
diff --git a/test/tag_test.c b/test/tag_test.c
index 421f89b..9b2ee1c 100644
--- a/test/tag_test.c
+++ b/test/tag_test.c
@@ -14,222 +14,23 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
-#include "../libc3/u64.h"
#include "../libc3/tag.h"
#include "test.h"
-#define TAG_TEST_COMPARE(a, b, expected) \
+#define TAG_TEST_HASH_U64_COMPARE(a, b, expected) \
do { \
- TEST_EQ(tag_compare((a), (b)), (expected)); \
- } while (0)
-
-#define TAG_TEST_HASH_COMPARE(a, b, expected) \
- do { \
- TEST_EQ(u64_compare(tag_hash(a), tag_hash(b)), (expected)); \
+ TEST_EQ(compare_u64(tag_hash_u64(a), tag_hash_u64(b)), \
+ (expected)); \
} while (0)
void tag_test ();
-void tag_test_compare ();
void tag_test_hash ();
-void tag_to_ffi_type_test ();
void tag_test ()
{
- tag_test_compare();
tag_test_hash();
}
-void tag_test_compare ()
-{
- s_tag a;
- s_tag b;
- /* tuple */
- TAG_TEST_COMPARE(tag_init_1(&a, "{a, b}"), &a, 0);
- TAG_TEST_COMPARE(tag_1(&a, "{a, b}"), tag_init_1(&b, "{a, b}"), 0);
- TAG_TEST_COMPARE(tag_1(&a, "{{a, b}, {c, d}}"),
- tag_1(&b, "{{a, b}, {c, d}}"), 0);
- /* integer <> s8 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x10000000000000000"),
- tag_1(&b, "-0x7F"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "-0x7F"),
- tag_1(&b, "-0x10000000000000000"), 1);
- /* integer <> s16 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x10000000000000000"),
- tag_1(&b, "-0x7FFF"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "-0x7FFF"),
- tag_1(&b, "-0x10000000000000000"), 1);
- /* integer <> s32 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x10000000000000000"),
- tag_1(&b, "-0x7FFFFFFF"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "-0x7FFFFFFF"),
- tag_1(&b, "-0x10000000000000000"), 1);
- /* integer <> s64 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x10000000000000000"),
- tag_1(&b, "-0x7FFFFFFFFFFFFFFF"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "-0x7FFFFFFFFFFFFFFF"),
- tag_1(&b, "-0x10000000000000000"), 1);
- /* integer <> u8 */
- TAG_TEST_COMPARE(tag_1(&a, "0xFF"),
- tag_1(&b, "0x10000000000000000"), 1);
- TAG_TEST_COMPARE(tag_1(&a, "0x10000000000000000"),
- tag_1(&b, "0xFF"), -1);
- /* integer <> u16 */
- TAG_TEST_COMPARE(tag_1(&a, "0xFFFF"),
- tag_1(&b, "0x10000000000000000"), 1);
- TAG_TEST_COMPARE(tag_1(&a, "0x10000000000000000"),
- tag_1(&b, "0xFFFF"), -1);
- /* integer <> u32 */
- TAG_TEST_COMPARE(tag_1(&a, "0xFFFFFFFF"),
- tag_1(&b, "0x10000000000000000"), 1);
- TAG_TEST_COMPARE(tag_1(&a, "0x10000000000000000"),
- tag_1(&b, "0xFFFFFFFF"), -1);
- /* integer <> u64 */
- TAG_TEST_COMPARE(tag_1(&a, "0xFFFFFFFFFFFFFFFF"),
- tag_1(&b, "0x10000000000000000"), 1);
- TAG_TEST_COMPARE(tag_1(&a, "0x10000000000000000"),
- tag_1(&b, "0xFFFFFFFFFFFFFFFF"), -1);
- /* s8 <> s8 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x7F"), tag_1(&b, "-0x7F"), 0);
- TAG_TEST_COMPARE(tag_1(&a, "-0x7F"), tag_1(&b, "-1"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "-1"), tag_1(&b, "-0x7F"), 1);
- TAG_TEST_COMPARE(tag_1(&a, "-1"), tag_1(&b, "-1"), 0);
- /* s8 <> s16 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "-0x7F"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "-0x7F"), tag_1(&b, "-0x100"), 1);
- /* s8 <> s32 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x10000"), tag_1(&b, "-0x7F"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "-0x7F"), tag_1(&b, "-0x10000"), 1);
- /* s8 <> s64 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"), tag_1(&b, "-0x7F"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "-0x7F"), tag_1(&b, "-0x100000000"), 1);
- /* s8 <> u8 */
- TAG_TEST_COMPARE(tag_1(&a, "-1"), tag_1(&b, "0"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "-1"), 1);
- /* s8 <> u16 */
- TAG_TEST_COMPARE(tag_1(&a, "-1"), tag_1(&b, "0x100"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "-1"), 1);
- /* s8 <> u32 */
- TAG_TEST_COMPARE(tag_1(&a, "-1"), tag_1(&b, "0x10000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x10000"), tag_1(&b, "-1"), 1);
- /* s8 <> u64 */
- TAG_TEST_COMPARE(tag_1(&a, "-1"), tag_1(&b, "0x100000000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x100000000"), tag_1(&b, "-1"), 1);
- /* s16 <> s16 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "-0x100"), 0);
- TAG_TEST_COMPARE(tag_1(&a, "-0x200"), tag_1(&b, "-0x100"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "-0x200"), 1);
- TAG_TEST_COMPARE(tag_1(&a, "-0x200"), tag_1(&b, "-0x200"), 0);
- /* s16 <> s32 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x10000"), tag_1(&b, "-0x100"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "-0x10000"), 1);
- /* s16 <> s64 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"), tag_1(&b, "-0x100"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "-0x100000000"), 1);
- /* s16 <> u8 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "0"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "-0x100"), 1);
- /* s16 <> u16 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "0x100"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "-0x100"), 1);
- /* s16 <> u32 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "0x10000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x10000"), tag_1(&b, "-0x100"), 1);
- /* s16 <> u64 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "0x100000000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x100000000"), tag_1(&b, "-0x100"), 1);
- /* s32 <> s32 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x10000"), tag_1(&b, "-0x10000"), 0);
- TAG_TEST_COMPARE(tag_1(&a, "-0x20000"), tag_1(&b, "-0x10000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "-0x10000"), tag_1(&b, "-0x20000"), 1);
- TAG_TEST_COMPARE(tag_1(&a, "-0x20000"), tag_1(&b, "-0x20000"), 0);
- /* s32 <> s64 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"), tag_1(&b, "-0x10000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "-0x10000"), tag_1(&b, "-0x100000000"), 1);
- /* s32 <> u8 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x10000"), tag_1(&b, "0"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "-0x10000"), 1);
- /* s32 <> u16 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x10000"), tag_1(&b, "0x100"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "-0x10000"), 1);
- /* s32 <> u32 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x10000"), tag_1(&b, "0x10000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x10000"), tag_1(&b, "-0x10000"), 1);
- /* s32 <> u64 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x10000"),
- tag_1(&b, "0x100000000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x100000000"),
- tag_1(&b, "-0x10000"), 1);
- /* s64 <> s64 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"),
- tag_1(&b, "-0x100000000"), 0);
- TAG_TEST_COMPARE(tag_1(&a, "-0x200000000"),
- tag_1(&b, "-0x100000000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"),
- tag_1(&b, "-0x200000000"), 1);
- TAG_TEST_COMPARE(tag_1(&a, "-0x200000000"),
- tag_1(&b, "-0x200000000"), 0);
- /* s64 <> u8 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"), tag_1(&b, "0"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "-0x100000000"), 1);
- /* s64 <> u16 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"), tag_1(&b, "0x100"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "-0x100000000"), 1);
- /* s64 <> u32 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"),
- tag_1(&b, "0x10000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x10000"),
- tag_1(&b, "-0x100000000"), 1);
- /* s64 <> u64 */
- TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"),
- tag_1(&b, "0x100000000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x100000000"),
- tag_1(&b, "-0x100000000"), 1);
- /* u8 <> u8 */
- TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "0"), 0);
- TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "1"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "1"), tag_1(&b, "0"), 1);
- TAG_TEST_COMPARE(tag_1(&a, "1"), tag_1(&b, "1"), 0);
- /* u8 <> u16 */
- TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "0x100"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "0"), 1);
- /* u8 <> u32 */
- TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "0x10000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x10000"), tag_1(&b, "0"), 1);
- /* u8 <> u64 */
- TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "0x100000000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x100000000"), tag_1(&b, "0"), 1);
- /* u16 <> u16 */
- TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "0x100"), 0);
- TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "0x200"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x200"), tag_1(&b, "0x100"), 1);
- TAG_TEST_COMPARE(tag_1(&a, "0x200"), tag_1(&b, "0x200"), 0);
- /* u16 <> u32 */
- TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "0x10000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x10000"), tag_1(&b, "0x100"), 1);
- /* u16 <> u64 */
- TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "0x100000000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x100000000"), tag_1(&b, "0x100"), 1);
- /* u32 <> u32 */
- TAG_TEST_COMPARE(tag_1(&a, "0x10000"), tag_1(&b, "0x10000"), 0);
- TAG_TEST_COMPARE(tag_1(&a, "0x10000"), tag_1(&b, "0x20000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x20000"), tag_1(&b, "0x10000"), 1);
- TAG_TEST_COMPARE(tag_1(&a, "0x20000"), tag_1(&b, "0x20000"), 0);
- /* u32 <> u64 */
- TAG_TEST_COMPARE(tag_1(&a, "0x10000"), tag_1(&b, "0x100000000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x100000000"), tag_1(&b, "0x10000"), 1);
- /* u64 <> u64 */
- TAG_TEST_COMPARE(tag_1(&a, "0x100000000"),
- tag_1(&b, "0x100000000"), 0);
- TAG_TEST_COMPARE(tag_1(&a, "0x100000000"),
- tag_1(&b, "0x200000000"), -1);
- TAG_TEST_COMPARE(tag_1(&a, "0x200000000"),
- tag_1(&b, "0x100000000"), 1);
- TAG_TEST_COMPARE(tag_1(&a, "0x200000000"),
- tag_1(&b, "0x200000000"), 0);
- tag_clean(&a);
- tag_clean(&b);
-}
-
void tag_test_hash ()
{
s_tag a;