summaryrefslogtreecommitdiff
path: root/libmisc/tests/test_hash.c
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-15 15:12:08 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-15 21:40:37 -0700
commit5704de985cff1d40359ecd15211cece0fbe79067 (patch)
tree5c172a6ea91716f4f8023e58d580e4b08fbd7fc1 /libmisc/tests/test_hash.c
parentf753128b22b61d4f85a74ba2694b8f9a576fc238 (diff)
Add tests to libmisc
Diffstat (limited to 'libmisc/tests/test_hash.c')
-rw-r--r--libmisc/tests/test_hash.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/libmisc/tests/test_hash.c b/libmisc/tests/test_hash.c
new file mode 100644
index 0000000..c1af385
--- /dev/null
+++ b/libmisc/tests/test_hash.c
@@ -0,0 +1,30 @@
+/* libmisc/tests/test_hash.c - Tests for <libmisc/hash.h>
+ *
+ * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include <libmisc/hash.h>
+
+#include "test.h"
+
+int main() {
+ test_assert(hash("hello", sizeof("hello")) == hash("hello", sizeof("hello")));
+ test_assert(hash("hello", sizeof("hello")) != hash("Hello", sizeof("Hello")));
+ int one = 1;
+ int two = 2;
+ test_assert(hash(&one, sizeof(int)) != hash("hello", sizeof("hello")));
+ test_assert(hash(&one, sizeof(int)) == hash(&one, sizeof(int)));
+ test_assert(hash(&one, sizeof(int)) != hash(&two, sizeof(int)));
+
+ hash_t myhash;
+ hash_init(&myhash);
+ hash_write(&myhash, "hello", 5);
+ test_assert(myhash == hash("hello", 5));
+ hash_t myhash_a = myhash;
+ hash_write(&myhash, "world", 5);
+ test_assert(myhash != myhash_a);
+ test_assert(myhash == hash("helloworld", 10));
+
+ return 0;
+}