summaryrefslogtreecommitdiff
path: root/vere/pkg/noun/equality_tests.c
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-10-05 21:56:51 +0700
committerpolwex <polwex@sortug.com>2025-10-05 21:56:51 +0700
commitfcedfddf00b3f994e4f4e40332ac7fc192c63244 (patch)
tree51d38e62c7bdfcc5f9a5e9435fe820c93cfc9a3d /vere/pkg/noun/equality_tests.c
claude is gud
Diffstat (limited to 'vere/pkg/noun/equality_tests.c')
-rw-r--r--vere/pkg/noun/equality_tests.c164
1 files changed, 164 insertions, 0 deletions
diff --git a/vere/pkg/noun/equality_tests.c b/vere/pkg/noun/equality_tests.c
new file mode 100644
index 0000000..83a5026
--- /dev/null
+++ b/vere/pkg/noun/equality_tests.c
@@ -0,0 +1,164 @@
+/// @file
+
+#include "noun.h"
+
+/* _setup(): prepare for tests.
+*/
+static void
+_setup(void)
+{
+ u3m_boot_lite(1 << 24);
+}
+
+static c3_i
+_test_unify_home(void)
+{
+ c3_i ret_i = 1;
+
+ u3_noun a = u3nt(0, 0, 0);
+ u3_noun b = u3nt(0, 0, 0);
+ c3_w kep_w;
+
+ u3_assert( u3t(a) < u3t(b) );
+ kep_w = u3t(a);
+
+ (void)u3r_sing(a, b);
+
+ if ( u3t(a) != u3t(b) ) {
+ fprintf(stderr, "test: unify home: failed\r\n");
+ ret_i = 0;
+ }
+ else if ( kep_w != u3t(b) ) {
+ fprintf(stderr, "test: unify home: deeper failed\r\n");
+ ret_i = 0;
+ }
+
+ u3z(a); u3z(b);
+
+ return ret_i;
+}
+
+static c3_i
+_test_unify_inner(void)
+{
+ c3_i ret_i = 1;
+ c3_w kep_w;
+ u3_noun a, b;
+
+ a = u3nt(0, 0, 0);
+ kep_w = u3t(a);
+
+ u3m_hate(0);
+
+ b = u3nt(0, 0, 0);
+
+ (void)u3r_sing(a, b);
+
+ if ( u3t(a) != u3t(b) ) {
+ fprintf(stderr, "test: unify inner 1: failed\r\n");
+ ret_i = 0;
+ }
+ else if ( kep_w != u3t(b) ) {
+ fprintf(stderr, "test: unify inner 1: deeper failed\r\n");
+ ret_i = 0;
+ }
+
+ b = u3m_love(0);
+
+ u3z(a); u3z(b);
+
+ // --------
+
+ b = u3nt(0, 0, 0);
+ kep_w = u3t(b);
+
+ u3m_hate(0);
+
+ a = u3nt(0, 0, 0);
+
+ u3m_hate(0);
+
+ (void)u3r_sing(a, b);
+
+ if ( u3t(a) != u3t(b) ) {
+ fprintf(stderr, "test: unify inner 2: failed\r\n");
+ ret_i = 0;
+ }
+ else if ( kep_w != u3t(a) ) {
+ fprintf(stderr, "test: unify inner 2: deeper failed\r\n");
+ ret_i = 0;
+ }
+
+ a = u3m_love(u3m_love(0));
+
+ u3z(a); u3z(b);
+
+ return ret_i;
+}
+
+static c3_i
+_test_unify_inner_home(void)
+{
+ c3_i ret_i = 1;
+
+ u3_noun a = u3nt(0, 0, 0);
+ u3_noun b = u3nt(0, 0, 0);
+
+ u3m_hate(0);
+
+ (void)u3r_sing(a, b);
+
+ if ( u3t(a) == u3t(b) ) {
+ fprintf(stderr, "test: unify inner-home: succeeded?\r\n");
+ ret_i = 0;
+ }
+
+ u3m_love(0);
+
+ u3z(a); u3z(b);
+
+ return ret_i;
+}
+
+static c3_i
+_test_equality(void)
+{
+ c3_i ret_i = 1;
+
+ if ( !_test_unify_home() ) {
+ fprintf(stderr, "test: equality: unify home: failed\r\n");
+ ret_i = 0;
+ }
+
+ if ( !_test_unify_inner() ) {
+ fprintf(stderr, "test: equality: unify inner: failed\r\n");
+ ret_i = 0;
+ }
+
+ if ( !_test_unify_inner_home() ) {
+ fprintf(stderr, "test: equality: unify inner-home: failed\r\n");
+ ret_i = 0;
+ }
+
+ return ret_i;
+}
+
+/* main(): run all test cases.
+*/
+int
+main(int argc, char* argv[])
+{
+ _setup();
+
+ if ( !_test_equality() ) {
+ fprintf(stderr, "test equality: failed\r\n");
+ exit(1);
+ }
+
+ // GC
+ //
+ u3m_grab(u3_none);
+
+ fprintf(stderr, "test equality: ok\r\n");
+ return 0;
+}