From cf7db48c261ee9c896c813a38ff8c59da5b8fe07 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Sun, 26 Jan 2025 00:40:51 +0100 Subject: Fix line endings --- asl/tests/box_tests.cpp | 156 ++--- asl/tests/buffer_tests.cpp | 1206 +++++++++++++++++++------------------- asl/tests/float_tests.cpp | 46 +- asl/tests/format_tests.cpp | 220 +++---- asl/tests/functional_tests.cpp | 146 ++--- asl/tests/hash_map_tests.cpp | 96 +-- asl/tests/hash_set_tests.cpp | 370 ++++++------ asl/tests/hash_tests.cpp | 520 ++++++++-------- asl/tests/integers_tests.cpp | 30 +- asl/tests/maybe_uninit_tests.cpp | 44 +- asl/tests/meta_tests.cpp | 498 ++++++++-------- asl/tests/option_tests.cpp | 658 ++++++++++----------- asl/tests/status_or_tests.cpp | 168 +++--- asl/tests/status_tests.cpp | 4 +- asl/tests/string_view_tests.cpp | 8 +- asl/tests/test_types.hpp | 182 +++--- asl/tests/utility_tests.cpp | 2 +- 17 files changed, 2177 insertions(+), 2177 deletions(-) (limited to 'asl/tests') diff --git a/asl/tests/box_tests.cpp b/asl/tests/box_tests.cpp index 0395e5f..edb574c 100644 --- a/asl/tests/box_tests.cpp +++ b/asl/tests/box_tests.cpp @@ -1,78 +1,78 @@ -#include "asl/box.hpp" -#include "asl/option.hpp" - -#include "asl/testing/testing.hpp" -#include "asl/tests/test_types.hpp" - -static_assert(sizeof(asl::box) == sizeof(int*)); -static_assert(!asl::copyable>); -static_assert(asl::moveable>); -static_assert(asl::has_niche>); -static_assert(sizeof(asl::option>) == sizeof(int*)); - -ASL_TEST(destructor) -{ - bool d = false; - - { - auto box = asl::make_box(&d); - ASL_TEST_ASSERT(!d); - - - auto box3 = ASL_MOVE(box); - ASL_TEST_ASSERT(!d); - } - - ASL_TEST_ASSERT(d); -} - -ASL_TEST(value) -{ - auto b = asl::make_box(24); - ASL_TEST_EXPECT(*b == 24); - - auto b2 = ASL_MOVE(b); - ASL_TEST_EXPECT(*b2 == 24); -} - -ASL_TEST(ptr) -{ - auto b = asl::make_box(24); - auto* ptr1 = b.get(); - - auto b2 = ASL_MOVE(b); - auto* ptr2 = b2.get(); - ASL_TEST_EXPECT(ptr1 == ptr2); -} - -struct Struct { int a; }; - -ASL_TEST(arrow) -{ - auto b = asl::make_box(45); - ASL_TEST_EXPECT(b->a == 45); -} - -ASL_TEST(niche) -{ - static_assert(sizeof(asl::box) == sizeof(asl::option>)); - - asl::option> opt; - ASL_TEST_EXPECT(!opt.has_value()); - - opt = asl::make_box(66); - ASL_TEST_EXPECT(opt.has_value()); - ASL_TEST_EXPECT(*opt.value() == 66); - - opt = asl::nullopt; - ASL_TEST_EXPECT(!opt.has_value()); - - bool destroyed = false; - asl::option opt2 = asl::make_box(&destroyed); - ASL_TEST_EXPECT(opt2.has_value()); - ASL_TEST_EXPECT(!destroyed); - - opt2.reset(); - ASL_TEST_EXPECT(!opt2.has_value()); - ASL_TEST_EXPECT(destroyed); -} +#include "asl/box.hpp" +#include "asl/option.hpp" + +#include "asl/testing/testing.hpp" +#include "asl/tests/test_types.hpp" + +static_assert(sizeof(asl::box) == sizeof(int*)); +static_assert(!asl::copyable>); +static_assert(asl::moveable>); +static_assert(asl::has_niche>); +static_assert(sizeof(asl::option>) == sizeof(int*)); + +ASL_TEST(destructor) +{ + bool d = false; + + { + auto box = asl::make_box(&d); + ASL_TEST_ASSERT(!d); + + + auto box3 = ASL_MOVE(box); + ASL_TEST_ASSERT(!d); + } + + ASL_TEST_ASSERT(d); +} + +ASL_TEST(value) +{ + auto b = asl::make_box(24); + ASL_TEST_EXPECT(*b == 24); + + auto b2 = ASL_MOVE(b); + ASL_TEST_EXPECT(*b2 == 24); +} + +ASL_TEST(ptr) +{ + auto b = asl::make_box(24); + auto* ptr1 = b.get(); + + auto b2 = ASL_MOVE(b); + auto* ptr2 = b2.get(); + ASL_TEST_EXPECT(ptr1 == ptr2); +} + +struct Struct { int a; }; + +ASL_TEST(arrow) +{ + auto b = asl::make_box(45); + ASL_TEST_EXPECT(b->a == 45); +} + +ASL_TEST(niche) +{ + static_assert(sizeof(asl::box) == sizeof(asl::option>)); + + asl::option> opt; + ASL_TEST_EXPECT(!opt.has_value()); + + opt = asl::make_box(66); + ASL_TEST_EXPECT(opt.has_value()); + ASL_TEST_EXPECT(*opt.value() == 66); + + opt = asl::nullopt; + ASL_TEST_EXPECT(!opt.has_value()); + + bool destroyed = false; + asl::option opt2 = asl::make_box(&destroyed); + ASL_TEST_EXPECT(opt2.has_value()); + ASL_TEST_EXPECT(!destroyed); + + opt2.reset(); + ASL_TEST_EXPECT(!opt2.has_value()); + ASL_TEST_EXPECT(destroyed); +} diff --git a/asl/tests/buffer_tests.cpp b/asl/tests/buffer_tests.cpp index dfa0bcb..174b3bc 100644 --- a/asl/tests/buffer_tests.cpp +++ b/asl/tests/buffer_tests.cpp @@ -1,603 +1,603 @@ -#include "asl/buffer.hpp" - -#include "asl/testing/testing.hpp" -#include "asl/tests/test_types.hpp" - -struct Big -{ - uint64_t data[8]; -}; - -static_assert(asl::buffer::kInlineCapacity == 5); -static_assert(asl::buffer::kInlineCapacity == 2); -static_assert(asl::buffer::kInlineCapacity == 23); -static_assert(asl::buffer::kInlineCapacity == 0); - -ASL_TEST(default_size) -{ - asl::buffer b1; - ASL_TEST_EXPECT(b1.size() == 0); - ASL_TEST_EXPECT(b1.capacity() == 5); - ASL_TEST_EXPECT(static_cast(b1.data()) == &b1); - - asl::buffer b2; - ASL_TEST_EXPECT(b2.size() == 0); - ASL_TEST_EXPECT(b2.capacity() == 0); - ASL_TEST_EXPECT(b2.data() == nullptr); -} - -struct CounterAllocator -{ - isize_t* count; - - void* alloc(const asl::layout& layout) const - { - *count += 1; - return asl::GlobalHeap::alloc(layout); - } - - void* realloc(void* ptr, const asl::layout& old, const asl::layout& new_layout) const - { - *count += 1; - return asl::GlobalHeap::realloc(ptr, old, new_layout); - } - - static void dealloc(void* ptr, const asl::layout& layout) - { - asl::GlobalHeap::dealloc(ptr, layout); - } - - constexpr bool operator==(const CounterAllocator&) const { return true; } -}; -static_assert(asl::allocator); - -struct IncompatibleAllocator -{ - static void* alloc(const asl::layout& layout) - { - return asl::GlobalHeap::alloc(layout); - } - - static void* realloc(void* ptr, const asl::layout& old, const asl::layout& new_layout) - { - return asl::GlobalHeap::realloc(ptr, old, new_layout); - } - - static void dealloc(void* ptr, const asl::layout& layout) - { - asl::GlobalHeap::dealloc(ptr, layout); - } - - constexpr bool operator==(const IncompatibleAllocator&) const { return false; } -}; -static_assert(asl::allocator); - -ASL_TEST(reserve_capacity) -{ - isize_t count = 0; - asl::buffer b(CounterAllocator{&count}); - ASL_TEST_EXPECT(b.size() == 0); - ASL_TEST_EXPECT(b.capacity() == 5); - ASL_TEST_EXPECT(count == 0); - - b.reserve_capacity(4); - ASL_TEST_EXPECT(b.size() == 0); - ASL_TEST_EXPECT(b.capacity() == 5); - ASL_TEST_EXPECT(count == 0); - - b.reserve_capacity(12); - ASL_TEST_EXPECT(b.size() == 0); - ASL_TEST_EXPECT(b.capacity() >= 12); - ASL_TEST_EXPECT(count == 1); - - b.reserve_capacity(13); - ASL_TEST_EXPECT(b.size() == 0); - ASL_TEST_EXPECT(b.capacity() >= 13); - ASL_TEST_EXPECT(count == 1); - - b.reserve_capacity(130); - ASL_TEST_EXPECT(b.size() == 0); - ASL_TEST_EXPECT(b.capacity() >= 130); - ASL_TEST_EXPECT(count == 2); -} - -ASL_TEST(push) -{ - asl::buffer b; - ASL_TEST_EXPECT(b.size() == 0); - - b.push(1); - ASL_TEST_EXPECT(b.size() == 1); - ASL_TEST_EXPECT(b[0] == 1); - - b.push(2); - b.push(3); - ASL_TEST_EXPECT(b.size() == 3); - ASL_TEST_EXPECT(b[0] == 1); - ASL_TEST_EXPECT(b[1] == 2); - ASL_TEST_EXPECT(b[2] == 3); - - b.push(4); - b.push(5); - b.push(6); - b.push(7); - ASL_TEST_EXPECT(b.size() == 7); - ASL_TEST_EXPECT(b[0] == 1); - ASL_TEST_EXPECT(b[1] == 2); - ASL_TEST_EXPECT(b[2] == 3); - ASL_TEST_EXPECT(b[3] == 4); - ASL_TEST_EXPECT(b[4] == 5); - ASL_TEST_EXPECT(b[5] == 6); - ASL_TEST_EXPECT(b[6] == 7); -} - -ASL_TEST(from_span) -{ - int data[] = {1, 2, 4, 8}; - asl::buffer b{data}; - - ASL_TEST_EXPECT(b.size() == 4); - ASL_TEST_EXPECT(b[0] == 1); - ASL_TEST_EXPECT(b[1] == 2); - ASL_TEST_EXPECT(b[2] == 4); - ASL_TEST_EXPECT(b[3] == 8); -} - -struct MoveableType -{ - int moved{}; - int value; - - explicit MoveableType(int x) : value{x} {} - MoveableType(const MoveableType&) = delete; - MoveableType(MoveableType&& other) : moved{other.moved + 1}, value{other.value} {} - MoveableType& operator=(const MoveableType&) = delete; - MoveableType& operator=(MoveableType&&) = delete; -}; -static_assert(!asl::trivially_copy_constructible); -static_assert(!asl::trivially_move_constructible); -static_assert(!asl::copyable); -static_assert(asl::move_constructible); - -ASL_TEST(push_move) -{ - asl::buffer b; - - static_assert(asl::buffer::kInlineCapacity > 0); - - b.push(0); - ASL_TEST_EXPECT(b[0].value == 0); - ASL_TEST_EXPECT(b[0].moved == 0); - - b.push(1); - ASL_TEST_EXPECT(b[0].value == 0); - ASL_TEST_EXPECT(b[0].moved == 0); - ASL_TEST_EXPECT(b[1].value == 1); - ASL_TEST_EXPECT(b[1].moved == 0); - - b.push(2); - ASL_TEST_EXPECT(b[0].value == 0); - ASL_TEST_EXPECT(b[0].moved == 1); - ASL_TEST_EXPECT(b[1].value == 1); - ASL_TEST_EXPECT(b[1].moved == 1); - ASL_TEST_EXPECT(b[2].value == 2); - ASL_TEST_EXPECT(b[2].moved == 0); - - b.push(3); - ASL_TEST_EXPECT(b[0].value == 0); - ASL_TEST_EXPECT(b[0].moved == 1); - ASL_TEST_EXPECT(b[1].value == 1); - ASL_TEST_EXPECT(b[1].moved == 1); - ASL_TEST_EXPECT(b[2].value == 2); - ASL_TEST_EXPECT(b[2].moved == 0); - ASL_TEST_EXPECT(b[3].value == 3); - ASL_TEST_EXPECT(b[3].moved == 0); - - b.push(4); - ASL_TEST_EXPECT(b[0].value == 0); - ASL_TEST_EXPECT(b[0].moved == 2); - ASL_TEST_EXPECT(b[1].value == 1); - ASL_TEST_EXPECT(b[1].moved == 2); - ASL_TEST_EXPECT(b[2].value == 2); - ASL_TEST_EXPECT(b[2].moved == 1); - ASL_TEST_EXPECT(b[3].value == 3); - ASL_TEST_EXPECT(b[3].moved == 1); - ASL_TEST_EXPECT(b[4].value == 4); - ASL_TEST_EXPECT(b[4].moved == 0); -} - -ASL_TEST(clear) -{ - asl::buffer b; - ASL_TEST_EXPECT(b.size() == 0); - - b.push(1); - b.push(2); - b.push(3); - b.push(4); - b.push(5); - b.push(6); - b.push(7); - ASL_TEST_EXPECT(b.size() == 7); - - b.clear(); - ASL_TEST_EXPECT(b.size() == 0); -} - -static_assert(asl::buffer::kInlineCapacity == 2); - -ASL_TEST(clear_destructor_small) -{ - bool d0 = false; - bool d1 = false; - - asl::buffer buf; - - buf.push(&d0); - buf.push(&d1); - - buf.clear(); - ASL_TEST_EXPECT(d0 == true); - ASL_TEST_EXPECT(d1 == true); -} - -ASL_TEST(clear_destructor_heap) -{ - bool d0 = false; - bool d1 = false; - bool d2 = false; - - asl::buffer buf; - - buf.push(&d0); - buf.push(&d1); - buf.push(&d2); - ASL_TEST_EXPECT(d0 == false); - ASL_TEST_EXPECT(d1 == false); - ASL_TEST_EXPECT(d2 == false); - - buf.clear(); - ASL_TEST_EXPECT(d0 == true); - ASL_TEST_EXPECT(d1 == true); - ASL_TEST_EXPECT(d2 == true); -} - -ASL_TEST(move_construct_from_heap) -{ - bool d[3]{}; - asl::buffer buf; - buf.push(&d[0]); - buf.push(&d[1]); - buf.push(&d[2]); - - { - asl::buffer buf2(ASL_MOVE(buf)); - ASL_TEST_EXPECT(buf2.size() == 3); - ASL_TEST_EXPECT(d[0] == false); - ASL_TEST_EXPECT(d[1] == false); - ASL_TEST_EXPECT(d[2] == false); - } - - ASL_TEST_EXPECT(buf.size() == 0); - ASL_TEST_EXPECT(d[0] == true); - ASL_TEST_EXPECT(d[1] == true); - ASL_TEST_EXPECT(d[2] == true); -} - -ASL_TEST(move_construct_inline_trivial) -{ - asl::buffer buf; - buf.push(1U); - buf.push(2U); - - asl::buffer buf2(ASL_MOVE(buf)); - ASL_TEST_EXPECT(buf2[0] == 1U); - ASL_TEST_EXPECT(buf2[1] == 2U); - - ASL_TEST_EXPECT(buf2.size() == 2); - ASL_TEST_EXPECT(buf.size() == 0); -} - -ASL_TEST(move_construct_from_inline_non_trivial) -{ - bool d[2]{}; - asl::buffer buf; - buf.push(&d[0]); - buf.push(&d[1]); - - { - asl::buffer buf2(ASL_MOVE(buf)); - ASL_TEST_EXPECT(buf2.size() == 2); - ASL_TEST_EXPECT(d[0] == false); - ASL_TEST_EXPECT(d[1] == false); - } - - ASL_TEST_EXPECT(buf.size() == 0); - ASL_TEST_EXPECT(d[0] == true); - ASL_TEST_EXPECT(d[1] == true); -} - -ASL_TEST(move_assign_from_heap) -{ - bool d[6]{}; - - { - asl::buffer buf; - asl::buffer buf2; - - buf.push(&d[0]); - buf.push(&d[1]); - buf.push(&d[2]); - - buf2.push(&d[3]); - buf2.push(&d[4]); - buf2.push(&d[5]); - - ASL_TEST_EXPECT(d[0] == false); - ASL_TEST_EXPECT(d[1] == false); - ASL_TEST_EXPECT(d[2] == false); - ASL_TEST_EXPECT(d[3] == false); - ASL_TEST_EXPECT(d[4] == false); - ASL_TEST_EXPECT(d[5] == false); - - buf2 = ASL_MOVE(buf); - - ASL_TEST_EXPECT(buf.size() == 0); - ASL_TEST_EXPECT(buf2.size() == 3); - - ASL_TEST_EXPECT(d[0] == false); - ASL_TEST_EXPECT(d[1] == false); - ASL_TEST_EXPECT(d[2] == false); - ASL_TEST_EXPECT(d[3] == true); - ASL_TEST_EXPECT(d[4] == true); - ASL_TEST_EXPECT(d[5] == true); - } - - ASL_TEST_EXPECT(d[0] == true); - ASL_TEST_EXPECT(d[1] == true); - ASL_TEST_EXPECT(d[2] == true); - ASL_TEST_EXPECT(d[3] == true); - ASL_TEST_EXPECT(d[4] == true); - ASL_TEST_EXPECT(d[5] == true); -} - -ASL_TEST(move_assign_trivial_heap_to_inline) -{ - isize_t alloc_count = 0; - asl::buffer buf{CounterAllocator{&alloc_count}}; - asl::buffer buf2{CounterAllocator{&alloc_count}}; - - buf.push(1); - buf.push(2); - ASL_TEST_EXPECT(alloc_count == 0); - - buf2.push(3); - buf2.push(4); - buf2.push(5); - ASL_TEST_EXPECT(alloc_count == 1); - - buf = ASL_MOVE(buf2); - ASL_TEST_EXPECT(alloc_count == 1); - - ASL_TEST_EXPECT(buf.size() == 3); - ASL_TEST_EXPECT(buf2.size() == 0); - ASL_TEST_EXPECT(buf[0] == 3); - ASL_TEST_EXPECT(buf[1] == 4); - ASL_TEST_EXPECT(buf[2] == 5); -} - -ASL_TEST(move_assign_trivial_inline_to_heap) -{ - isize_t alloc_count = 0; - asl::buffer buf{CounterAllocator{&alloc_count}}; - asl::buffer buf2{CounterAllocator{&alloc_count}}; - - buf.push(1); - buf.push(2); - ASL_TEST_EXPECT(alloc_count == 0); - - buf2.push(3); - buf2.push(4); - buf2.push(5); - ASL_TEST_EXPECT(alloc_count == 1); - - buf2 = ASL_MOVE(buf); - ASL_TEST_EXPECT(alloc_count == 1); - - ASL_TEST_EXPECT(buf.size() == 0); - ASL_TEST_EXPECT(buf2.size() == 2); - ASL_TEST_EXPECT(buf2[0] == 1); - ASL_TEST_EXPECT(buf2[1] == 2); -} - -ASL_TEST(move_assign_inline_to_heap) -{ - bool d[6]{}; - - { - asl::buffer buf; - asl::buffer buf2; - - buf.push(&d[0]); - buf.push(&d[1]); - - buf2.push(&d[2]); - buf2.push(&d[3]); - buf2.push(&d[4]); - buf2.push(&d[5]); - - buf2 = ASL_MOVE(buf); - - ASL_TEST_EXPECT(buf.size() == 0); - ASL_TEST_EXPECT(buf2.size() == 2); - ASL_TEST_EXPECT(d[0] == false); - ASL_TEST_EXPECT(d[1] == false); - ASL_TEST_EXPECT(d[2] == false); // moved but not destroyed - ASL_TEST_EXPECT(d[3] == false); // moved but not destroyed - ASL_TEST_EXPECT(d[4] == true); - ASL_TEST_EXPECT(d[5] == true); - } - - ASL_TEST_EXPECT(d[0] == true); - ASL_TEST_EXPECT(d[1] == true); - ASL_TEST_EXPECT(d[2] == false); // moved but not destroyed - ASL_TEST_EXPECT(d[3] == false); // moved but not destroyed - ASL_TEST_EXPECT(d[4] == true); - ASL_TEST_EXPECT(d[5] == true); -} - -ASL_TEST(move_assign_from_inline_incompatible_allocator) -{ - bool d[6]{}; - - { - asl::buffer buf; - asl::buffer buf2; - - buf.push(&d[0]); - buf.push(&d[1]); - - buf2.push(&d[2]); - buf2.push(&d[3]); - buf2.push(&d[4]); - buf2.push(&d[5]); - - buf2 = ASL_MOVE(buf); - - ASL_TEST_EXPECT(buf.size() == 0); - ASL_TEST_EXPECT(buf2.size() == 2); - ASL_TEST_EXPECT(d[0] == false); - ASL_TEST_EXPECT(d[1] == false); - ASL_TEST_EXPECT(d[2] == true); - ASL_TEST_EXPECT(d[3] == true); - ASL_TEST_EXPECT(d[4] == true); - ASL_TEST_EXPECT(d[5] == true); - } - - ASL_TEST_EXPECT(d[0] == true); - ASL_TEST_EXPECT(d[1] == true); - ASL_TEST_EXPECT(d[2] == true); - ASL_TEST_EXPECT(d[3] == true); - ASL_TEST_EXPECT(d[4] == true); - ASL_TEST_EXPECT(d[5] == true); -} - -ASL_TEST(copy_construct_inline) -{ - asl::buffer buf; - buf.push(0); - buf.push(1); - buf.push(2); - - asl::buffer buf2{buf}; - - ASL_TEST_EXPECT(buf.size() == buf2.size()); - ASL_TEST_EXPECT(buf.size() == 3); - ASL_TEST_EXPECT(buf[0] == 0); - ASL_TEST_EXPECT(buf[1] == 1); - ASL_TEST_EXPECT(buf[2] == 2); - ASL_TEST_EXPECT(buf2[0] == 0); - ASL_TEST_EXPECT(buf2[1] == 1); - ASL_TEST_EXPECT(buf2[2] == 2); -} - -ASL_TEST(copy_assign_into_smaller) -{ - asl::buffer buf; - buf.push(0); - buf.push(1); - buf.push(2); - - asl::buffer buf2; - buf2.push(4); - - buf2 = buf; - - ASL_TEST_EXPECT(buf.size() == 3); - ASL_TEST_EXPECT(buf2.size() == 3); - - ASL_TEST_EXPECT(buf[0] == 0); - ASL_TEST_EXPECT(buf[1] == 1); - ASL_TEST_EXPECT(buf[2] == 2); - ASL_TEST_EXPECT(buf2[0] == 0); - ASL_TEST_EXPECT(buf2[1] == 1); - ASL_TEST_EXPECT(buf2[2] == 2); -} - -ASL_TEST(copy_assign_into_larger) -{ - asl::buffer buf; - buf.push(0); - buf.push(1); - buf.push(2); - - asl::buffer buf2; - buf2.push(4); - - buf = buf2; - - ASL_TEST_EXPECT(buf.size() == 1); - ASL_TEST_EXPECT(buf2.size() == 1); - - ASL_TEST_EXPECT(buf[0] == 4); - ASL_TEST_EXPECT(buf2[0] == 4); -} - -ASL_TEST(resize_default) -{ - asl::buffer buf; - - buf.push(5); - buf.resize(4); - - ASL_TEST_ASSERT(buf.size() == 4); - ASL_TEST_EXPECT(buf[0] == 5); - ASL_TEST_EXPECT(buf[1] == 0); - ASL_TEST_EXPECT(buf[2] == 0); - ASL_TEST_EXPECT(buf[3] == 0); - - buf.resize(2); - - ASL_TEST_ASSERT(buf.size() == 2); - ASL_TEST_EXPECT(buf[0] == 5); - ASL_TEST_EXPECT(buf[1] == 0); -} - -ASL_TEST(resize) -{ - asl::buffer buf; - - buf.push(5); - buf.resize(4, 6); - - ASL_TEST_ASSERT(buf.size() == 4); - ASL_TEST_EXPECT(buf[0] == 5); - ASL_TEST_EXPECT(buf[1] == 6); - ASL_TEST_EXPECT(buf[2] == 6); - ASL_TEST_EXPECT(buf[3] == 6); - - buf.resize(2, 7); - - ASL_TEST_ASSERT(buf.size() == 2); - ASL_TEST_EXPECT(buf[0] == 5); - ASL_TEST_EXPECT(buf[1] == 6); -} - -ASL_TEST(resize_zero) -{ - asl::buffer buf; - for (int i = 0; i < 100; ++i) - { - buf.push(i); - } - - buf.resize_zero(200); - ASL_TEST_ASSERT(buf.size() == 200); - - for (int i = 0; i < 100; ++i) - { - ASL_TEST_EXPECT(buf[i] == i); - ASL_TEST_EXPECT(buf[100 + i] == 0); - } -} - +#include "asl/buffer.hpp" + +#include "asl/testing/testing.hpp" +#include "asl/tests/test_types.hpp" + +struct Big +{ + uint64_t data[8]; +}; + +static_assert(asl::buffer::kInlineCapacity == 5); +static_assert(asl::buffer::kInlineCapacity == 2); +static_assert(asl::buffer::kInlineCapacity == 23); +static_assert(asl::buffer::kInlineCapacity == 0); + +ASL_TEST(default_size) +{ + asl::buffer b1; + ASL_TEST_EXPECT(b1.size() == 0); + ASL_TEST_EXPECT(b1.capacity() == 5); + ASL_TEST_EXPECT(static_cast(b1.data()) == &b1); + + asl::buffer b2; + ASL_TEST_EXPECT(b2.size() == 0); + ASL_TEST_EXPECT(b2.capacity() == 0); + ASL_TEST_EXPECT(b2.data() == nullptr); +} + +struct CounterAllocator +{ + isize_t* count; + + void* alloc(const asl::layout& layout) const + { + *count += 1; + return asl::GlobalHeap::alloc(layout); + } + + void* realloc(void* ptr, const asl::layout& old, const asl::layout& new_layout) const + { + *count += 1; + return asl::GlobalHeap::realloc(ptr, old, new_layout); + } + + static void dealloc(void* ptr, const asl::layout& layout) + { + asl::GlobalHeap::dealloc(ptr, layout); + } + + constexpr bool operator==(const CounterAllocator&) const { return true; } +}; +static_assert(asl::allocator); + +struct IncompatibleAllocator +{ + static void* alloc(const asl::layout& layout) + { + return asl::GlobalHeap::alloc(layout); + } + + static void* realloc(void* ptr, const asl::layout& old, const asl::layout& new_layout) + { + return asl::GlobalHeap::realloc(ptr, old, new_layout); + } + + static void dealloc(void* ptr, const asl::layout& layout) + { + asl::GlobalHeap::dealloc(ptr, layout); + } + + constexpr bool operator==(const IncompatibleAllocator&) const { return false; } +}; +static_assert(asl::allocator); + +ASL_TEST(reserve_capacity) +{ + isize_t count = 0; + asl::buffer b(CounterAllocator{&count}); + ASL_TEST_EXPECT(b.size() == 0); + ASL_TEST_EXPECT(b.capacity() == 5); + ASL_TEST_EXPECT(count == 0); + + b.reserve_capacity(4); + ASL_TEST_EXPECT(b.size() == 0); + ASL_TEST_EXPECT(b.capacity() == 5); + ASL_TEST_EXPECT(count == 0); + + b.reserve_capacity(12); + ASL_TEST_EXPECT(b.size() == 0); + ASL_TEST_EXPECT(b.capacity() >= 12); + ASL_TEST_EXPECT(count == 1); + + b.reserve_capacity(13); + ASL_TEST_EXPECT(b.size() == 0); + ASL_TEST_EXPECT(b.capacity() >= 13); + ASL_TEST_EXPECT(count == 1); + + b.reserve_capacity(130); + ASL_TEST_EXPECT(b.size() == 0); + ASL_TEST_EXPECT(b.capacity() >= 130); + ASL_TEST_EXPECT(count == 2); +} + +ASL_TEST(push) +{ + asl::buffer b; + ASL_TEST_EXPECT(b.size() == 0); + + b.push(1); + ASL_TEST_EXPECT(b.size() == 1); + ASL_TEST_EXPECT(b[0] == 1); + + b.push(2); + b.push(3); + ASL_TEST_EXPECT(b.size() == 3); + ASL_TEST_EXPECT(b[0] == 1); + ASL_TEST_EXPECT(b[1] == 2); + ASL_TEST_EXPECT(b[2] == 3); + + b.push(4); + b.push(5); + b.push(6); + b.push(7); + ASL_TEST_EXPECT(b.size() == 7); + ASL_TEST_EXPECT(b[0] == 1); + ASL_TEST_EXPECT(b[1] == 2); + ASL_TEST_EXPECT(b[2] == 3); + ASL_TEST_EXPECT(b[3] == 4); + ASL_TEST_EXPECT(b[4] == 5); + ASL_TEST_EXPECT(b[5] == 6); + ASL_TEST_EXPECT(b[6] == 7); +} + +ASL_TEST(from_span) +{ + int data[] = {1, 2, 4, 8}; + asl::buffer b{data}; + + ASL_TEST_EXPECT(b.size() == 4); + ASL_TEST_EXPECT(b[0] == 1); + ASL_TEST_EXPECT(b[1] == 2); + ASL_TEST_EXPECT(b[2] == 4); + ASL_TEST_EXPECT(b[3] == 8); +} + +struct MoveableType +{ + int moved{}; + int value; + + explicit MoveableType(int x) : value{x} {} + MoveableType(const MoveableType&) = delete; + MoveableType(MoveableType&& other) : moved{other.moved + 1}, value{other.value} {} + MoveableType& operator=(const MoveableType&) = delete; + MoveableType& operator=(MoveableType&&) = delete; +}; +static_assert(!asl::trivially_copy_constructible); +static_assert(!asl::trivially_move_constructible); +static_assert(!asl::copyable); +static_assert(asl::move_constructible); + +ASL_TEST(push_move) +{ + asl::buffer b; + + static_assert(asl::buffer::kInlineCapacity > 0); + + b.push(0); + ASL_TEST_EXPECT(b[0].value == 0); + ASL_TEST_EXPECT(b[0].moved == 0); + + b.push(1); + ASL_TEST_EXPECT(b[0].value == 0); + ASL_TEST_EXPECT(b[0].moved == 0); + ASL_TEST_EXPECT(b[1].value == 1); + ASL_TEST_EXPECT(b[1].moved == 0); + + b.push(2); + ASL_TEST_EXPECT(b[0].value == 0); + ASL_TEST_EXPECT(b[0].moved == 1); + ASL_TEST_EXPECT(b[1].value == 1); + ASL_TEST_EXPECT(b[1].moved == 1); + ASL_TEST_EXPECT(b[2].value == 2); + ASL_TEST_EXPECT(b[2].moved == 0); + + b.push(3); + ASL_TEST_EXPECT(b[0].value == 0); + ASL_TEST_EXPECT(b[0].moved == 1); + ASL_TEST_EXPECT(b[1].value == 1); + ASL_TEST_EXPECT(b[1].moved == 1); + ASL_TEST_EXPECT(b[2].value == 2); + ASL_TEST_EXPECT(b[2].moved == 0); + ASL_TEST_EXPECT(b[3].value == 3); + ASL_TEST_EXPECT(b[3].moved == 0); + + b.push(4); + ASL_TEST_EXPECT(b[0].value == 0); + ASL_TEST_EXPECT(b[0].moved == 2); + ASL_TEST_EXPECT(b[1].value == 1); + ASL_TEST_EXPECT(b[1].moved == 2); + ASL_TEST_EXPECT(b[2].value == 2); + ASL_TEST_EXPECT(b[2].moved == 1); + ASL_TEST_EXPECT(b[3].value == 3); + ASL_TEST_EXPECT(b[3].moved == 1); + ASL_TEST_EXPECT(b[4].value == 4); + ASL_TEST_EXPECT(b[4].moved == 0); +} + +ASL_TEST(clear) +{ + asl::buffer b; + ASL_TEST_EXPECT(b.size() == 0); + + b.push(1); + b.push(2); + b.push(3); + b.push(4); + b.push(5); + b.push(6); + b.push(7); + ASL_TEST_EXPECT(b.size() == 7); + + b.clear(); + ASL_TEST_EXPECT(b.size() == 0); +} + +static_assert(asl::buffer::kInlineCapacity == 2); + +ASL_TEST(clear_destructor_small) +{ + bool d0 = false; + bool d1 = false; + + asl::buffer buf; + + buf.push(&d0); + buf.push(&d1); + + buf.clear(); + ASL_TEST_EXPECT(d0 == true); + ASL_TEST_EXPECT(d1 == true); +} + +ASL_TEST(clear_destructor_heap) +{ + bool d0 = false; + bool d1 = false; + bool d2 = false; + + asl::buffer buf; + + buf.push(&d0); + buf.push(&d1); + buf.push(&d2); + ASL_TEST_EXPECT(d0 == false); + ASL_TEST_EXPECT(d1 == false); + ASL_TEST_EXPECT(d2 == false); + + buf.clear(); + ASL_TEST_EXPECT(d0 == true); + ASL_TEST_EXPECT(d1 == true); + ASL_TEST_EXPECT(d2 == true); +} + +ASL_TEST(move_construct_from_heap) +{ + bool d[3]{}; + asl::buffer buf; + buf.push(&d[0]); + buf.push(&d[1]); + buf.push(&d[2]); + + { + asl::buffer buf2(ASL_MOVE(buf)); + ASL_TEST_EXPECT(buf2.size() == 3); + ASL_TEST_EXPECT(d[0] == false); + ASL_TEST_EXPECT(d[1] == false); + ASL_TEST_EXPECT(d[2] == false); + } + + ASL_TEST_EXPECT(buf.size() == 0); + ASL_TEST_EXPECT(d[0] == true); + ASL_TEST_EXPECT(d[1] == true); + ASL_TEST_EXPECT(d[2] == true); +} + +ASL_TEST(move_construct_inline_trivial) +{ + asl::buffer buf; + buf.push(1U); + buf.push(2U); + + asl::buffer buf2(ASL_MOVE(buf)); + ASL_TEST_EXPECT(buf2[0] == 1U); + ASL_TEST_EXPECT(buf2[1] == 2U); + + ASL_TEST_EXPECT(buf2.size() == 2); + ASL_TEST_EXPECT(buf.size() == 0); +} + +ASL_TEST(move_construct_from_inline_non_trivial) +{ + bool d[2]{}; + asl::buffer buf; + buf.push(&d[0]); + buf.push(&d[1]); + + { + asl::buffer buf2(ASL_MOVE(buf)); + ASL_TEST_EXPECT(buf2.size() == 2); + ASL_TEST_EXPECT(d[0] == false); + ASL_TEST_EXPECT(d[1] == false); + } + + ASL_TEST_EXPECT(buf.size() == 0); + ASL_TEST_EXPECT(d[0] == true); + ASL_TEST_EXPECT(d[1] == true); +} + +ASL_TEST(move_assign_from_heap) +{ + bool d[6]{}; + + { + asl::buffer buf; + asl::buffer buf2; + + buf.push(&d[0]); + buf.push(&d[1]); + buf.push(&d[2]); + + buf2.push(&d[3]); + buf2.push(&d[4]); + buf2.push(&d[5]); + + ASL_TEST_EXPECT(d[0] == false); + ASL_TEST_EXPECT(d[1] == false); + ASL_TEST_EXPECT(d[2] == false); + ASL_TEST_EXPECT(d[3] == false); + ASL_TEST_EXPECT(d[4] == false); + ASL_TEST_EXPECT(d[5] == false); + + buf2 = ASL_MOVE(buf); + + ASL_TEST_EXPECT(buf.size() == 0); + ASL_TEST_EXPECT(buf2.size() == 3); + + ASL_TEST_EXPECT(d[0] == false); + ASL_TEST_EXPECT(d[1] == false); + ASL_TEST_EXPECT(d[2] == false); + ASL_TEST_EXPECT(d[3] == true); + ASL_TEST_EXPECT(d[4] == true); + ASL_TEST_EXPECT(d[5] == true); + } + + ASL_TEST_EXPECT(d[0] == true); + ASL_TEST_EXPECT(d[1] == true); + ASL_TEST_EXPECT(d[2] == true); + ASL_TEST_EXPECT(d[3] == true); + ASL_TEST_EXPECT(d[4] == true); + ASL_TEST_EXPECT(d[5] == true); +} + +ASL_TEST(move_assign_trivial_heap_to_inline) +{ + isize_t alloc_count = 0; + asl::buffer buf{CounterAllocator{&alloc_count}}; + asl::buffer buf2{CounterAllocator{&alloc_count}}; + + buf.push(1); + buf.push(2); + ASL_TEST_EXPECT(alloc_count == 0); + + buf2.push(3); + buf2.push(4); + buf2.push(5); + ASL_TEST_EXPECT(alloc_count == 1); + + buf = ASL_MOVE(buf2); + ASL_TEST_EXPECT(alloc_count == 1); + + ASL_TEST_EXPECT(buf.size() == 3); + ASL_TEST_EXPECT(buf2.size() == 0); + ASL_TEST_EXPECT(buf[0] == 3); + ASL_TEST_EXPECT(buf[1] == 4); + ASL_TEST_EXPECT(buf[2] == 5); +} + +ASL_TEST(move_assign_trivial_inline_to_heap) +{ + isize_t alloc_count = 0; + asl::buffer buf{CounterAllocator{&alloc_count}}; + asl::buffer buf2{CounterAllocator{&alloc_count}}; + + buf.push(1); + buf.push(2); + ASL_TEST_EXPECT(alloc_count == 0); + + buf2.push(3); + buf2.push(4); + buf2.push(5); + ASL_TEST_EXPECT(alloc_count == 1); + + buf2 = ASL_MOVE(buf); + ASL_TEST_EXPECT(alloc_count == 1); + + ASL_TEST_EXPECT(buf.size() == 0); + ASL_TEST_EXPECT(buf2.size() == 2); + ASL_TEST_EXPECT(buf2[0] == 1); + ASL_TEST_EXPECT(buf2[1] == 2); +} + +ASL_TEST(move_assign_inline_to_heap) +{ + bool d[6]{}; + + { + asl::buffer buf; + asl::buffer buf2; + + buf.push(&d[0]); + buf.push(&d[1]); + + buf2.push(&d[2]); + buf2.push(&d[3]); + buf2.push(&d[4]); + buf2.push(&d[5]); + + buf2 = ASL_MOVE(buf); + + ASL_TEST_EXPECT(buf.size() == 0); + ASL_TEST_EXPECT(buf2.size() == 2); + ASL_TEST_EXPECT(d[0] == false); + ASL_TEST_EXPECT(d[1] == false); + ASL_TEST_EXPECT(d[2] == false); // moved but not destroyed + ASL_TEST_EXPECT(d[3] == false); // moved but not destroyed + ASL_TEST_EXPECT(d[4] == true); + ASL_TEST_EXPECT(d[5] == true); + } + + ASL_TEST_EXPECT(d[0] == true); + ASL_TEST_EXPECT(d[1] == true); + ASL_TEST_EXPECT(d[2] == false); // moved but not destroyed + ASL_TEST_EXPECT(d[3] == false); // moved but not destroyed + ASL_TEST_EXPECT(d[4] == true); + ASL_TEST_EXPECT(d[5] == true); +} + +ASL_TEST(move_assign_from_inline_incompatible_allocator) +{ + bool d[6]{}; + + { + asl::buffer buf; + asl::buffer buf2; + + buf.push(&d[0]); + buf.push(&d[1]); + + buf2.push(&d[2]); + buf2.push(&d[3]); + buf2.push(&d[4]); + buf2.push(&d[5]); + + buf2 = ASL_MOVE(buf); + + ASL_TEST_EXPECT(buf.size() == 0); + ASL_TEST_EXPECT(buf2.size() == 2); + ASL_TEST_EXPECT(d[0] == false); + ASL_TEST_EXPECT(d[1] == false); + ASL_TEST_EXPECT(d[2] == true); + ASL_TEST_EXPECT(d[3] == true); + ASL_TEST_EXPECT(d[4] == true); + ASL_TEST_EXPECT(d[5] == true); + } + + ASL_TEST_EXPECT(d[0] == true); + ASL_TEST_EXPECT(d[1] == true); + ASL_TEST_EXPECT(d[2] == true); + ASL_TEST_EXPECT(d[3] == true); + ASL_TEST_EXPECT(d[4] == true); + ASL_TEST_EXPECT(d[5] == true); +} + +ASL_TEST(copy_construct_inline) +{ + asl::buffer buf; + buf.push(0); + buf.push(1); + buf.push(2); + + asl::buffer buf2{buf}; + + ASL_TEST_EXPECT(buf.size() == buf2.size()); + ASL_TEST_EXPECT(buf.size() == 3); + ASL_TEST_EXPECT(buf[0] == 0); + ASL_TEST_EXPECT(buf[1] == 1); + ASL_TEST_EXPECT(buf[2] == 2); + ASL_TEST_EXPECT(buf2[0] == 0); + ASL_TEST_EXPECT(buf2[1] == 1); + ASL_TEST_EXPECT(buf2[2] == 2); +} + +ASL_TEST(copy_assign_into_smaller) +{ + asl::buffer buf; + buf.push(0); + buf.push(1); + buf.push(2); + + asl::buffer buf2; + buf2.push(4); + + buf2 = buf; + + ASL_TEST_EXPECT(buf.size() == 3); + ASL_TEST_EXPECT(buf2.size() == 3); + + ASL_TEST_EXPECT(buf[0] == 0); + ASL_TEST_EXPECT(buf[1] == 1); + ASL_TEST_EXPECT(buf[2] == 2); + ASL_TEST_EXPECT(buf2[0] == 0); + ASL_TEST_EXPECT(buf2[1] == 1); + ASL_TEST_EXPECT(buf2[2] == 2); +} + +ASL_TEST(copy_assign_into_larger) +{ + asl::buffer buf; + buf.push(0); + buf.push(1); + buf.push(2); + + asl::buffer buf2; + buf2.push(4); + + buf = buf2; + + ASL_TEST_EXPECT(buf.size() == 1); + ASL_TEST_EXPECT(buf2.size() == 1); + + ASL_TEST_EXPECT(buf[0] == 4); + ASL_TEST_EXPECT(buf2[0] == 4); +} + +ASL_TEST(resize_default) +{ + asl::buffer buf; + + buf.push(5); + buf.resize(4); + + ASL_TEST_ASSERT(buf.size() == 4); + ASL_TEST_EXPECT(buf[0] == 5); + ASL_TEST_EXPECT(buf[1] == 0); + ASL_TEST_EXPECT(buf[2] == 0); + ASL_TEST_EXPECT(buf[3] == 0); + + buf.resize(2); + + ASL_TEST_ASSERT(buf.size() == 2); + ASL_TEST_EXPECT(buf[0] == 5); + ASL_TEST_EXPECT(buf[1] == 0); +} + +ASL_TEST(resize) +{ + asl::buffer buf; + + buf.push(5); + buf.resize(4, 6); + + ASL_TEST_ASSERT(buf.size() == 4); + ASL_TEST_EXPECT(buf[0] == 5); + ASL_TEST_EXPECT(buf[1] == 6); + ASL_TEST_EXPECT(buf[2] == 6); + ASL_TEST_EXPECT(buf[3] == 6); + + buf.resize(2, 7); + + ASL_TEST_ASSERT(buf.size() == 2); + ASL_TEST_EXPECT(buf[0] == 5); + ASL_TEST_EXPECT(buf[1] == 6); +} + +ASL_TEST(resize_zero) +{ + asl::buffer buf; + for (int i = 0; i < 100; ++i) + { + buf.push(i); + } + + buf.resize_zero(200); + ASL_TEST_ASSERT(buf.size() == 200); + + for (int i = 0; i < 100; ++i) + { + ASL_TEST_EXPECT(buf[i] == i); + ASL_TEST_EXPECT(buf[100 + i] == 0); + } +} + diff --git a/asl/tests/float_tests.cpp b/asl/tests/float_tests.cpp index faf145b..d645be8 100644 --- a/asl/tests/float_tests.cpp +++ b/asl/tests/float_tests.cpp @@ -1,23 +1,23 @@ -#include "asl/float.hpp" - -#include "asl/testing/testing.hpp" - -ASL_TEST(is_infinity) -{ - ASL_TEST_EXPECT(!asl::is_infinity(0.0F)); - ASL_TEST_EXPECT(!asl::is_infinity(-25.0F)); - ASL_TEST_EXPECT(asl::is_infinity(45.0F / 0.0F)); - ASL_TEST_EXPECT(asl::is_infinity(-45.0F / 0.0F)); - ASL_TEST_EXPECT(asl::is_infinity(asl::infinity())); - ASL_TEST_EXPECT(asl::is_infinity(-asl::infinity())); -} - -ASL_TEST(is_nan) -{ - ASL_TEST_EXPECT(!asl::is_nan(0.0F)); - ASL_TEST_EXPECT(!asl::is_nan(-25.0F)); - ASL_TEST_EXPECT(!asl::is_nan(45.0F / 0.0F)); - ASL_TEST_EXPECT(asl::is_nan(asl::nan())); - ASL_TEST_EXPECT(asl::is_nan(asl::nan())); -} - +#include "asl/float.hpp" + +#include "asl/testing/testing.hpp" + +ASL_TEST(is_infinity) +{ + ASL_TEST_EXPECT(!asl::is_infinity(0.0F)); + ASL_TEST_EXPECT(!asl::is_infinity(-25.0F)); + ASL_TEST_EXPECT(asl::is_infinity(45.0F / 0.0F)); + ASL_TEST_EXPECT(asl::is_infinity(-45.0F / 0.0F)); + ASL_TEST_EXPECT(asl::is_infinity(asl::infinity())); + ASL_TEST_EXPECT(asl::is_infinity(-asl::infinity())); +} + +ASL_TEST(is_nan) +{ + ASL_TEST_EXPECT(!asl::is_nan(0.0F)); + ASL_TEST_EXPECT(!asl::is_nan(-25.0F)); + ASL_TEST_EXPECT(!asl::is_nan(45.0F / 0.0F)); + ASL_TEST_EXPECT(asl::is_nan(asl::nan())); + ASL_TEST_EXPECT(asl::is_nan(asl::nan())); +} + diff --git a/asl/tests/format_tests.cpp b/asl/tests/format_tests.cpp index b263abc..a91cac6 100644 --- a/asl/tests/format_tests.cpp +++ b/asl/tests/format_tests.cpp @@ -1,110 +1,110 @@ -#include "asl/format.hpp" -#include "asl/testing/testing.hpp" -#include "asl/float.hpp" -#include "asl/string_builder.hpp" - -static_assert(asl::formattable); - -ASL_TEST(format_args) -{ - // @Todo Introduce ASL_TEST_EXPECT_EQ, or ASL_TEST_EXPECT_STREQ - - auto s = asl::format_to_string("Hello, world!"); - ASL_TEST_EXPECT(s == "Hello, world!"_sv); - - s = asl::format_to_string(""); - ASL_TEST_EXPECT(s == ""_sv); - - s = asl::format_to_string("Hello, {}!", "world"); - ASL_TEST_EXPECT(s == "Hello, world!"_sv); - - s = asl::format_to_string("Hello, {}! {}", "world"); - ASL_TEST_EXPECT(s == "Hello, world! "_sv); - - s = asl::format_to_string("Hello, pup!", "world"); - ASL_TEST_EXPECT(s == "Hello, pup!"_sv); - - s = asl::format_to_string("{}", "CHEESE"); - ASL_TEST_EXPECT(s == "CHEESE"_sv); - - s = asl::format_to_string("{ ", "CHEESE"); - ASL_TEST_EXPECT(s == " "_sv); - - s = asl::format_to_string("{", "CHEESE"); - ASL_TEST_EXPECT(s == ""_sv); - - s = asl::format_to_string("a{{b"); - ASL_TEST_EXPECT(s == "a{b"_sv); - - s = asl::format_to_string("{{{}}} }", "CHEESE"); - ASL_TEST_EXPECT(s == "{CHEESE} }"_sv); -} - -ASL_TEST(format_integers) -{ - auto s = asl::format_to_string("{} {} {}", 0, 1, 2); - ASL_TEST_EXPECT(s == "0 1 2"_sv); - - s = asl::format_to_string("{} {} {}", 10, 11, 12); - ASL_TEST_EXPECT(s == "10 11 12"_sv); - - s = asl::format_to_string("{} {} {}", 100, 101, 102); - ASL_TEST_EXPECT(s == "100 101 102"_sv); - - s = asl::format_to_string("{} {} {}", 1000, 1001, 1002); - ASL_TEST_EXPECT(s == "1000 1001 1002"_sv); - - s = asl::format_to_string("{} {} {} {}", -1, -23, -456, -7890); - ASL_TEST_EXPECT(s == "-1 -23 -456 -7890"_sv); -} - -ASL_TEST(format_floats) -{ - auto s = asl::format_to_string("{} {} {}", 0.0F, 1.0, 2.0F); - ASL_TEST_EXPECT(s == "0 1 2"_sv); - - s = asl::format_to_string("{} {} {}", 0.1F, 0.001F, 0.123F); - ASL_TEST_EXPECT(s == "0.1 0.001 0.123"_sv); - - s = asl::format_to_string("{} {}", 1.25F, -22.3); - ASL_TEST_EXPECT(s == "1.25 -22.3"_sv); - - s = asl::format_to_string("{}", 1e32); - ASL_TEST_EXPECT(s == "100000000000000000000000000000000"_sv); - - s = asl::format_to_string("{}", 123e-8); - ASL_TEST_EXPECT(s == "0.00000123"_sv); - - s = asl::format_to_string("{} {}", asl::infinity(), -asl::infinity()); - ASL_TEST_EXPECT(s == "Infinity -Infinity"_sv); - - s = asl::format_to_string("{}", asl::nan()); - ASL_TEST_EXPECT(s == "NaN"_sv); -} - -ASL_TEST(format_boolean) -{ - auto s = asl::format_to_string("{} {}", true, false); - ASL_TEST_EXPECT(s == "true false"_sv); -} - -struct CustomFormat -{ - int x; - friend void AslFormat(asl::Formatter&, const CustomFormat&); -}; - -void AslFormat(asl::Formatter& f, const CustomFormat& c) -{ - f.write("("_sv); - AslFormat(f, c.x); - f.write(")"_sv); -} - -static_assert(asl::formattable); - -ASL_TEST(format_custom) -{ - auto s = asl::format_to_string("{}", CustomFormat{37}); - ASL_TEST_EXPECT(s == "(37)"_sv); -} +#include "asl/format.hpp" +#include "asl/testing/testing.hpp" +#include "asl/float.hpp" +#include "asl/string_builder.hpp" + +static_assert(asl::formattable); + +ASL_TEST(format_args) +{ + // @Todo Introduce ASL_TEST_EXPECT_EQ, or ASL_TEST_EXPECT_STREQ + + auto s = asl::format_to_string("Hello, world!"); + ASL_TEST_EXPECT(s == "Hello, world!"_sv); + + s = asl::format_to_string(""); + ASL_TEST_EXPECT(s == ""_sv); + + s = asl::format_to_string("Hello, {}!", "world"); + ASL_TEST_EXPECT(s == "Hello, world!"_sv); + + s = asl::format_to_string("Hello, {}! {}", "world"); + ASL_TEST_EXPECT(s == "Hello, world! "_sv); + + s = asl::format_to_string("Hello, pup!", "world"); + ASL_TEST_EXPECT(s == "Hello, pup!"_sv); + + s = asl::format_to_string("{}", "CHEESE"); + ASL_TEST_EXPECT(s == "CHEESE"_sv); + + s = asl::format_to_string("{ ", "CHEESE"); + ASL_TEST_EXPECT(s == " "_sv); + + s = asl::format_to_string("{", "CHEESE"); + ASL_TEST_EXPECT(s == ""_sv); + + s = asl::format_to_string("a{{b"); + ASL_TEST_EXPECT(s == "a{b"_sv); + + s = asl::format_to_string("{{{}}} }", "CHEESE"); + ASL_TEST_EXPECT(s == "{CHEESE} }"_sv); +} + +ASL_TEST(format_integers) +{ + auto s = asl::format_to_string("{} {} {}", 0, 1, 2); + ASL_TEST_EXPECT(s == "0 1 2"_sv); + + s = asl::format_to_string("{} {} {}", 10, 11, 12); + ASL_TEST_EXPECT(s == "10 11 12"_sv); + + s = asl::format_to_string("{} {} {}", 100, 101, 102); + ASL_TEST_EXPECT(s == "100 101 102"_sv); + + s = asl::format_to_string("{} {} {}", 1000, 1001, 1002); + ASL_TEST_EXPECT(s == "1000 1001 1002"_sv); + + s = asl::format_to_string("{} {} {} {}", -1, -23, -456, -7890); + ASL_TEST_EXPECT(s == "-1 -23 -456 -7890"_sv); +} + +ASL_TEST(format_floats) +{ + auto s = asl::format_to_string("{} {} {}", 0.0F, 1.0, 2.0F); + ASL_TEST_EXPECT(s == "0 1 2"_sv); + + s = asl::format_to_string("{} {} {}", 0.1F, 0.001F, 0.123F); + ASL_TEST_EXPECT(s == "0.1 0.001 0.123"_sv); + + s = asl::format_to_string("{} {}", 1.25F, -22.3); + ASL_TEST_EXPECT(s == "1.25 -22.3"_sv); + + s = asl::format_to_string("{}", 1e32); + ASL_TEST_EXPECT(s == "100000000000000000000000000000000"_sv); + + s = asl::format_to_string("{}", 123e-8); + ASL_TEST_EXPECT(s == "0.00000123"_sv); + + s = asl::format_to_string("{} {}", asl::infinity(), -asl::infinity()); + ASL_TEST_EXPECT(s == "Infinity -Infinity"_sv); + + s = asl::format_to_string("{}", asl::nan()); + ASL_TEST_EXPECT(s == "NaN"_sv); +} + +ASL_TEST(format_boolean) +{ + auto s = asl::format_to_string("{} {}", true, false); + ASL_TEST_EXPECT(s == "true false"_sv); +} + +struct CustomFormat +{ + int x; + friend void AslFormat(asl::Formatter&, const CustomFormat&); +}; + +void AslFormat(asl::Formatter& f, const CustomFormat& c) +{ + f.write("("_sv); + AslFormat(f, c.x); + f.write(")"_sv); +} + +static_assert(asl::formattable); + +ASL_TEST(format_custom) +{ + auto s = asl::format_to_string("{}", CustomFormat{37}); + ASL_TEST_EXPECT(s == "(37)"_sv); +} diff --git a/asl/tests/functional_tests.cpp b/asl/tests/functional_tests.cpp index f32e1b2..2cdbe7a 100644 --- a/asl/tests/functional_tests.cpp +++ b/asl/tests/functional_tests.cpp @@ -1,73 +1,73 @@ -#include "asl/functional.hpp" -#include "asl/testing/testing.hpp" - -struct HasFunction -{ - void do_something(int, float) {} -}; - -struct HasMember -{ - int member{}; - int member_array[4]{}; - void (*member_fn)(){}; -}; - -struct Functor -{ - int64_t operator()() { return 35; } - int operator()(int x) { return x; } -}; - -static int some_func0() { return 1; } -static int some_func1(int x) { return x + 1; } -[[maybe_unused]] static float some_func1(float x) { return x + 1; } -static int some_func2(int x, int b) { return x + b; } - -static_assert(asl::same_as, int64_t>); -static_assert(asl::same_as, int>); -static_assert(asl::same_as(some_func1))(float)>, float>); -static_assert(asl::same_as, void>); -static_assert(asl::same_as, int>); - -ASL_TEST(invoke_member_function) -{ - HasFunction c; - asl::invoke(&HasFunction::do_something, c, 5, 5.0F); - asl::invoke(&HasFunction::do_something, &c, 5, 5.0F); -} - -ASL_TEST(invoke_member_data) -{ - HasMember c; - - asl::invoke(&HasMember::member, c); - asl::invoke(&HasMember::member_array, c); - asl::invoke(&HasMember::member_fn, c); - asl::invoke(&HasMember::member, &c); - asl::invoke(&HasMember::member_array, &c); - asl::invoke(&HasMember::member_fn, &c); -} - -ASL_TEST(invoke_fn) -{ - ASL_TEST_EXPECT(asl::invoke(some_func0) == 1); - ASL_TEST_EXPECT(asl::invoke(static_cast(some_func1), 8) == 9); - ASL_TEST_EXPECT(asl::invoke(some_func2, 4, 8) == 12); - ASL_TEST_EXPECT(asl::invoke(&some_func0) == 1); - ASL_TEST_EXPECT(asl::invoke(static_cast(&some_func1), 8) == 9); - ASL_TEST_EXPECT(asl::invoke(&some_func2, 4, 8) == 12); -} - -ASL_TEST(invoke_operator_call) -{ - Functor f; - ASL_TEST_EXPECT(asl::invoke(f) == 35); - ASL_TEST_EXPECT(asl::invoke(f, 8) == 8); -} - -ASL_TEST(invoke_lambda) -{ - ASL_TEST_EXPECT(asl::invoke([](){ return 35; }) == 35); - ASL_TEST_EXPECT(asl::invoke([](int x){ return x + 2; }, 6) == 8); -} +#include "asl/functional.hpp" +#include "asl/testing/testing.hpp" + +struct HasFunction +{ + void do_something(int, float) {} +}; + +struct HasMember +{ + int member{}; + int member_array[4]{}; + void (*member_fn)(){}; +}; + +struct Functor +{ + int64_t operator()() { return 35; } + int operator()(int x) { return x; } +}; + +static int some_func0() { return 1; } +static int some_func1(int x) { return x + 1; } +[[maybe_unused]] static float some_func1(float x) { return x + 1; } +static int some_func2(int x, int b) { return x + b; } + +static_assert(asl::same_as, int64_t>); +static_assert(asl::same_as, int>); +static_assert(asl::same_as(some_func1))(float)>, float>); +static_assert(asl::same_as, void>); +static_assert(asl::same_as, int>); + +ASL_TEST(invoke_member_function) +{ + HasFunction c; + asl::invoke(&HasFunction::do_something, c, 5, 5.0F); + asl::invoke(&HasFunction::do_something, &c, 5, 5.0F); +} + +ASL_TEST(invoke_member_data) +{ + HasMember c; + + asl::invoke(&HasMember::member, c); + asl::invoke(&HasMember::member_array, c); + asl::invoke(&HasMember::member_fn, c); + asl::invoke(&HasMember::member, &c); + asl::invoke(&HasMember::member_array, &c); + asl::invoke(&HasMember::member_fn, &c); +} + +ASL_TEST(invoke_fn) +{ + ASL_TEST_EXPECT(asl::invoke(some_func0) == 1); + ASL_TEST_EXPECT(asl::invoke(static_cast(some_func1), 8) == 9); + ASL_TEST_EXPECT(asl::invoke(some_func2, 4, 8) == 12); + ASL_TEST_EXPECT(asl::invoke(&some_func0) == 1); + ASL_TEST_EXPECT(asl::invoke(static_cast(&some_func1), 8) == 9); + ASL_TEST_EXPECT(asl::invoke(&some_func2, 4, 8) == 12); +} + +ASL_TEST(invoke_operator_call) +{ + Functor f; + ASL_TEST_EXPECT(asl::invoke(f) == 35); + ASL_TEST_EXPECT(asl::invoke(f, 8) == 8); +} + +ASL_TEST(invoke_lambda) +{ + ASL_TEST_EXPECT(asl::invoke([](){ return 35; }) == 35); + ASL_TEST_EXPECT(asl::invoke([](int x){ return x + 2; }, 6) == 8); +} diff --git a/asl/tests/hash_map_tests.cpp b/asl/tests/hash_map_tests.cpp index 53c419c..619c5e7 100644 --- a/asl/tests/hash_map_tests.cpp +++ b/asl/tests/hash_map_tests.cpp @@ -1,48 +1,48 @@ -#include "asl/testing/testing.hpp" -#include "asl/hash_map.hpp" - -ASL_TEST(default) -{ - asl::hash_map map; - - ASL_TEST_EXPECT(!map.contains(45)); - ASL_TEST_EXPECT(!map.contains(46)); - - map.insert(45, 5); - map.insert(46, 6); - - ASL_TEST_EXPECT(map.size() == 2); - - ASL_TEST_EXPECT(map.contains(45)); - ASL_TEST_EXPECT(map.contains(46)); - ASL_TEST_EXPECT(!map.contains(47)); - - ASL_TEST_EXPECT(*map.get(45) == 5); - ASL_TEST_EXPECT(*map.get(46) == 6); - ASL_TEST_EXPECT(map.get(47) == nullptr); - - ASL_TEST_EXPECT(map.remove(45)); - ASL_TEST_EXPECT(!map.remove(45)); - - ASL_TEST_EXPECT(map.size() == 1); - - ASL_TEST_EXPECT(!map.contains(45)); - ASL_TEST_EXPECT(map.contains(46)); - ASL_TEST_EXPECT(!map.contains(47)); - - ASL_TEST_EXPECT(map.get(45) == nullptr); - ASL_TEST_EXPECT(*map.get(46) == 6); - ASL_TEST_EXPECT(map.get(47) == nullptr); - - map.insert(46, 460); - - ASL_TEST_EXPECT(map.size() == 1); - - ASL_TEST_EXPECT(!map.contains(45)); - ASL_TEST_EXPECT(map.contains(46)); - ASL_TEST_EXPECT(!map.contains(47)); - - ASL_TEST_EXPECT(map.get(45) == nullptr); - ASL_TEST_EXPECT(*map.get(46) == 460); - ASL_TEST_EXPECT(map.get(47) == nullptr); -} +#include "asl/testing/testing.hpp" +#include "asl/hash_map.hpp" + +ASL_TEST(default) +{ + asl::hash_map map; + + ASL_TEST_EXPECT(!map.contains(45)); + ASL_TEST_EXPECT(!map.contains(46)); + + map.insert(45, 5); + map.insert(46, 6); + + ASL_TEST_EXPECT(map.size() == 2); + + ASL_TEST_EXPECT(map.contains(45)); + ASL_TEST_EXPECT(map.contains(46)); + ASL_TEST_EXPECT(!map.contains(47)); + + ASL_TEST_EXPECT(*map.get(45) == 5); + ASL_TEST_EXPECT(*map.get(46) == 6); + ASL_TEST_EXPECT(map.get(47) == nullptr); + + ASL_TEST_EXPECT(map.remove(45)); + ASL_TEST_EXPECT(!map.remove(45)); + + ASL_TEST_EXPECT(map.size() == 1); + + ASL_TEST_EXPECT(!map.contains(45)); + ASL_TEST_EXPECT(map.contains(46)); + ASL_TEST_EXPECT(!map.contains(47)); + + ASL_TEST_EXPECT(map.get(45) == nullptr); + ASL_TEST_EXPECT(*map.get(46) == 6); + ASL_TEST_EXPECT(map.get(47) == nullptr); + + map.insert(46, 460); + + ASL_TEST_EXPECT(map.size() == 1); + + ASL_TEST_EXPECT(!map.contains(45)); + ASL_TEST_EXPECT(map.contains(46)); + ASL_TEST_EXPECT(!map.contains(47)); + + ASL_TEST_EXPECT(map.get(45) == nullptr); + ASL_TEST_EXPECT(*map.get(46) == 460); + ASL_TEST_EXPECT(map.get(47) == nullptr); +} diff --git a/asl/tests/hash_set_tests.cpp b/asl/tests/hash_set_tests.cpp index 56cb07a..0c00c87 100644 --- a/asl/tests/hash_set_tests.cpp +++ b/asl/tests/hash_set_tests.cpp @@ -1,185 +1,185 @@ -#include "asl/hash_set.hpp" -#include "asl/testing/testing.hpp" -#include "asl/tests/test_types.hpp" -#include "asl/string.hpp" -#include "asl/string_view.hpp" - -ASL_TEST(empty) -{ - asl::hash_set set; - - ASL_TEST_EXPECT(set.size() == 0); - - for (int i = 0; i < 100; ++i) - { - ASL_TEST_EXPECT(!set.contains(i)); - } -} - -ASL_TEST(a_bunch_of_strings) -{ - asl::hash_set> set; - - set.insert("Hello, world!"); - ASL_TEST_EXPECT(set.size() == 1); - - set.insert("Hello, puppy!"); - ASL_TEST_EXPECT(set.size() == 2); - - set.insert("Hello, puppy!"); - ASL_TEST_EXPECT(set.size() == 2); - - ASL_TEST_EXPECT(set.contains("Hello, world!"_sv)); - ASL_TEST_EXPECT(set.contains("Hello, puppy!"_sv)); - ASL_TEST_EXPECT(!set.contains("Hello, Steven!"_sv)); -} - -ASL_TEST(a_bunch_of_ints) -{ - asl::hash_set set; - - int count = 3000; - - for (int i = 0; i < count; ++i) - { - set.insert(i); - } - - ASL_TEST_EXPECT(set.size() == count); - - for (int i = 0; i < count * 2; ++i) - { - ASL_TEST_EXPECT(set.contains(i) == (i < count)); - } -} - -struct HashWithDestructor: public DestructorObserver -{ - int x; - - HashWithDestructor(int x_, bool* ptr) - : DestructorObserver{ptr} - , x{x_} - {} - - constexpr bool operator==(const HashWithDestructor& other) const - { - return x == other.x; - } -}; - -struct CustomComparator -{ - static bool eq(const HashWithDestructor& a, const HashWithDestructor& b) - { - return a.x == b.x; - } - - static bool eq(const HashWithDestructor& a, int b) - { - return a.x == b; - } -}; - -struct CustomHasher -{ - static uint64_t hash(const HashWithDestructor& b) - { - return asl::hash_value(b.x); - } - - static uint64_t hash(int x) - { - return asl::hash_value(x); - } -}; - -ASL_TEST(destructor_and_remove) -{ - static constexpr int kCount = 200; - bool destroyed[kCount]{}; - - { - asl::hash_set set; - - for (int i = 0; i < kCount; ++i) - { - set.insert(i, &destroyed[i]); // NOLINT - } - - ASL_TEST_EXPECT(set.size() == kCount); - - for (int i = 0; i < kCount; ++i) - { - ASL_TEST_EXPECT(!destroyed[i]); // NOLINT - } - - for (int i = 0; i < kCount; i += 2) - { - ASL_TEST_EXPECT(set.remove(i)); - } - - for (int i = 0; i < kCount; i += 2) - { - ASL_TEST_EXPECT(!set.contains(i)); - ASL_TEST_EXPECT(set.contains(i+1)); - ASL_TEST_EXPECT(destroyed[i]); // NOLINT - ASL_TEST_EXPECT(!destroyed[i + 1]); // NOLINT - } - } - - for (int i = 0; i < kCount; ++i) - { - ASL_TEST_EXPECT(destroyed[i]); // NOLINT - } -} - -ASL_TEST(copy) -{ - asl::hash_set set1; - - for (int i = 0; i < 100; ++i) - { - set1.insert(i); - } - - asl::hash_set set2 = set1; - asl::hash_set set3; - set3 = set1; - - ASL_TEST_EXPECT(set2.size() == 100); - ASL_TEST_EXPECT(set3.size() == 100); - - for (int i = 0; i < 100; ++i) - { - ASL_TEST_EXPECT(set2.contains(i)); - ASL_TEST_EXPECT(set3.contains(i)); - } -} - -ASL_TEST(move) -{ - asl::hash_set set1; - - for (int i = 0; i < 100; ++i) - { - set1.insert(i); - } - - asl::hash_set set2 = ASL_MOVE(set1); - - ASL_TEST_EXPECT(set2.size() == 100); - for (int i = 0; i < 100; ++i) - { - ASL_TEST_EXPECT(set2.contains(i)); - } - - set1 = ASL_MOVE(set2); - - ASL_TEST_EXPECT(set1.size() == 100); - for (int i = 0; i < 100; ++i) - { - ASL_TEST_EXPECT(set1.contains(i)); - } -} - +#include "asl/hash_set.hpp" +#include "asl/testing/testing.hpp" +#include "asl/tests/test_types.hpp" +#include "asl/string.hpp" +#include "asl/string_view.hpp" + +ASL_TEST(empty) +{ + asl::hash_set set; + + ASL_TEST_EXPECT(set.size() == 0); + + for (int i = 0; i < 100; ++i) + { + ASL_TEST_EXPECT(!set.contains(i)); + } +} + +ASL_TEST(a_bunch_of_strings) +{ + asl::hash_set> set; + + set.insert("Hello, world!"); + ASL_TEST_EXPECT(set.size() == 1); + + set.insert("Hello, puppy!"); + ASL_TEST_EXPECT(set.size() == 2); + + set.insert("Hello, puppy!"); + ASL_TEST_EXPECT(set.size() == 2); + + ASL_TEST_EXPECT(set.contains("Hello, world!"_sv)); + ASL_TEST_EXPECT(set.contains("Hello, puppy!"_sv)); + ASL_TEST_EXPECT(!set.contains("Hello, Steven!"_sv)); +} + +ASL_TEST(a_bunch_of_ints) +{ + asl::hash_set set; + + int count = 3000; + + for (int i = 0; i < count; ++i) + { + set.insert(i); + } + + ASL_TEST_EXPECT(set.size() == count); + + for (int i = 0; i < count * 2; ++i) + { + ASL_TEST_EXPECT(set.contains(i) == (i < count)); + } +} + +struct HashWithDestructor: public DestructorObserver +{ + int x; + + HashWithDestructor(int x_, bool* ptr) + : DestructorObserver{ptr} + , x{x_} + {} + + constexpr bool operator==(const HashWithDestructor& other) const + { + return x == other.x; + } +}; + +struct CustomComparator +{ + static bool eq(const HashWithDestructor& a, const HashWithDestructor& b) + { + return a.x == b.x; + } + + static bool eq(const HashWithDestructor& a, int b) + { + return a.x == b; + } +}; + +struct CustomHasher +{ + static uint64_t hash(const HashWithDestructor& b) + { + return asl::hash_value(b.x); + } + + static uint64_t hash(int x) + { + return asl::hash_value(x); + } +}; + +ASL_TEST(destructor_and_remove) +{ + static constexpr int kCount = 200; + bool destroyed[kCount]{}; + + { + asl::hash_set set; + + for (int i = 0; i < kCount; ++i) + { + set.insert(i, &destroyed[i]); // NOLINT + } + + ASL_TEST_EXPECT(set.size() == kCount); + + for (int i = 0; i < kCount; ++i) + { + ASL_TEST_EXPECT(!destroyed[i]); // NOLINT + } + + for (int i = 0; i < kCount; i += 2) + { + ASL_TEST_EXPECT(set.remove(i)); + } + + for (int i = 0; i < kCount; i += 2) + { + ASL_TEST_EXPECT(!set.contains(i)); + ASL_TEST_EXPECT(set.contains(i+1)); + ASL_TEST_EXPECT(destroyed[i]); // NOLINT + ASL_TEST_EXPECT(!destroyed[i + 1]); // NOLINT + } + } + + for (int i = 0; i < kCount; ++i) + { + ASL_TEST_EXPECT(destroyed[i]); // NOLINT + } +} + +ASL_TEST(copy) +{ + asl::hash_set set1; + + for (int i = 0; i < 100; ++i) + { + set1.insert(i); + } + + asl::hash_set set2 = set1; + asl::hash_set set3; + set3 = set1; + + ASL_TEST_EXPECT(set2.size() == 100); + ASL_TEST_EXPECT(set3.size() == 100); + + for (int i = 0; i < 100; ++i) + { + ASL_TEST_EXPECT(set2.contains(i)); + ASL_TEST_EXPECT(set3.contains(i)); + } +} + +ASL_TEST(move) +{ + asl::hash_set set1; + + for (int i = 0; i < 100; ++i) + { + set1.insert(i); + } + + asl::hash_set set2 = ASL_MOVE(set1); + + ASL_TEST_EXPECT(set2.size() == 100); + for (int i = 0; i < 100; ++i) + { + ASL_TEST_EXPECT(set2.contains(i)); + } + + set1 = ASL_MOVE(set2); + + ASL_TEST_EXPECT(set1.size() == 100); + for (int i = 0; i < 100; ++i) + { + ASL_TEST_EXPECT(set1.contains(i)); + } +} + diff --git a/asl/tests/hash_tests.cpp b/asl/tests/hash_tests.cpp index 6098102..20a5183 100644 --- a/asl/tests/hash_tests.cpp +++ b/asl/tests/hash_tests.cpp @@ -1,260 +1,260 @@ -#include "asl/testing/testing.hpp" -#include "asl/hash.hpp" -#include "asl/string_view.hpp" -#include "asl/string.hpp" -#include "asl/buffer.hpp" -#include "asl/box.hpp" -#include "asl/option.hpp" -#include "asl/status.hpp" -#include "asl/status_or.hpp" - -static_assert(!asl::hashable); -static_assert(!asl::hashable); -static_assert(!asl::hashable); - -static_assert(asl::hashable); -static_assert(asl::hashable); -static_assert(asl::hashable); -static_assert(asl::hashable); -static_assert(asl::hashable); - -static_assert(asl::hashable); -static_assert(asl::hashable); -static_assert(asl::hashable); -static_assert(asl::hashable); - -ASL_TEST(integers) -{ - uint64_t a = asl::hash_value(45); - uint64_t b = asl::hash_value(45); - uint64_t c = asl::hash_value(46); - uint64_t d = asl::hash_value(45); - - ASL_TEST_EXPECT(a == b); - ASL_TEST_EXPECT(a != c); - ASL_TEST_EXPECT(a != d); -} - -static_assert(asl::hashable); - -ASL_TEST(bool) -{ - ASL_TEST_EXPECT(asl::hash_value(true) == asl::hash_value(true)); - ASL_TEST_EXPECT(asl::hash_value(false) == asl::hash_value(false)); - ASL_TEST_EXPECT(asl::hash_value(true) != asl::hash_value(false)); -} - -static_assert(asl::hashable); -static_assert(asl::hashable>); - -ASL_TEST(strings) -{ - ASL_TEST_EXPECT(asl::hash_value("hello"_sv) == asl::hash_value("hello"_sv)); - ASL_TEST_EXPECT(asl::hash_value("hello"_sv) != asl::hash_value("hello "_sv)); - ASL_TEST_EXPECT(asl::hash_value("hello"_sv) != asl::hash_value("HELLO"_sv)); - - ASL_TEST_EXPECT(asl::hash_value(asl::string("hello"_sv)) == asl::hash_value(asl::string("hello"_sv))); - ASL_TEST_EXPECT(asl::hash_value(asl::string("hello"_sv)) != asl::hash_value(asl::string("hello "_sv))); - ASL_TEST_EXPECT(asl::hash_value(asl::string("hello"_sv)) != asl::hash_value(asl::string("HELLO"_sv))); - - ASL_TEST_EXPECT(asl::hash_value("hello"_sv) == asl::hash_value(asl::string("hello"_sv))); -} - -static_assert(asl::hashable>); -static_assert(!asl::hashable>); -static_assert(asl::hashable>); - -ASL_TEST(span) -{ - int ints1[] = {1, 2, 3}; - int ints2[] = {1, 2, 3}; - int ints3[] = {1, 2}; - int ints4[] = {3, 2, 1}; - - ASL_TEST_EXPECT(asl::hash_value(asl::span(ints1)) == asl::hash_value(asl::span(ints2))); - ASL_TEST_EXPECT(asl::hash_value(asl::span(ints1)) != asl::hash_value(asl::span(ints3))); - ASL_TEST_EXPECT(asl::hash_value(asl::span(ints1)) != asl::hash_value(asl::span(ints4))); - - asl::string_view strs1[] = {"a", "abc", "hello"}; - asl::string_view strs2[] = {"a", "abc", "hello"}; - asl::string_view strs3[] = {"a", "abc"}; - asl::string_view strs4[] = {"a", "abc", "hello", "what"}; - - ASL_TEST_EXPECT(asl::hash_value(asl::span(strs1)) == asl::hash_value(asl::span(strs2))); - ASL_TEST_EXPECT(asl::hash_value(asl::span(strs1)) != asl::hash_value(asl::span(strs3))); - ASL_TEST_EXPECT(asl::hash_value(asl::span(strs1)) != asl::hash_value(asl::span(strs4))); -} - -static_assert(asl::hashable>); -static_assert(!asl::hashable>); - -ASL_TEST(buffer) -{ - asl::buffer ints1; - ints1.push(1); - ints1.push(2); - ints1.push(3); - - asl::buffer ints2; - ints2.push(1); - ints2.push(2); - ints2.push(3); - - asl::buffer ints3; - ints3.push(1); - ints3.push(2); - - asl::buffer ints4; - ints4.push(1); - ints4.push(2); - ints4.push(4); - - ASL_TEST_EXPECT(asl::hash_value(ints1) == asl::hash_value(ints2)); - ASL_TEST_EXPECT(asl::hash_value(ints1) != asl::hash_value(ints3)); - ASL_TEST_EXPECT(asl::hash_value(ints1) != asl::hash_value(ints4)); - ASL_TEST_EXPECT(asl::hash_value(ints1) == asl::hash_value(ints1.as_span())); - - asl::buffer strs1; - strs1.push("Hello"); - strs1.push("World"); - - asl::buffer strs2; - strs2.push("Hello"); - strs2.push("World"); - - asl::buffer strs3; - strs3.push("Hello"); - strs3.push("world"); - - asl::buffer strs4; - strs4.push("Hello"); - strs4.push("World"); - strs4.push("World"); - - ASL_TEST_EXPECT(asl::hash_value(strs1) == asl::hash_value(strs2)); - ASL_TEST_EXPECT(asl::hash_value(strs1) != asl::hash_value(strs3)); - ASL_TEST_EXPECT(asl::hash_value(strs1) != asl::hash_value(strs4)); - ASL_TEST_EXPECT(asl::hash_value(strs1) == asl::hash_value(strs1.as_span())); -} - -enum Enum1 {}; -