/* libmisc/tests/test_hash.c - Tests for * * Copyright (C) 2024 Luke T. Shumaker * SPDX-License-Identifier: AGPL-3.0-or-later */ #include #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; }