jacekpoz
3231124346
commitef2fdaab86
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 14:22:09 2024 +0200 improve all vector types by deunionifying them commite994825668
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 14:19:56 2024 +0200 use w and h for radii in ellipse intersects commit2eb53fb8a3
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 13:47:03 2024 +0200 add PTK_LIST_CLEAR commita63f65067d
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 13:46:29 2024 +0200 remove semicolon from filled macro commit4ac6a1bb70
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 13:31:13 2024 +0200 ... commit5142127ae0
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 12:50:08 2024 +0200 add clickable to components if encountered commitb1f31b7965
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 12:41:52 2024 +0200 stupid fucking switch syntax commit8ff74e7235
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 12:40:05 2024 +0200 remove redundant vertex update commit448e9fed14
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 12:10:48 2024 +0200 handle button hitboxes properly commita4025fa924
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 12:04:11 2024 +0200 add more const on local variables commitc7386ddfbf
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 12:02:24 2024 +0200 fix rect triangle comments (xd) commitca212ac65e
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 11:57:33 2024 +0200 spam const over local variables and function parameters commit43707826d9
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 11:31:50 2024 +0200 improve rect triangle init readability commit2b3f4c58c4
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 02:08:18 2024 +0200 set ellipse rect's type to the ellipse's type commit4872e59e16
Merge:336aadc
565aa4d
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 01:29:01 2024 +0200 Merge branch 'main' into button commit336aadc7a0
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 01:25:13 2024 +0200 whoops forgot about this one commit29f0d9f56a
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 01:22:45 2024 +0200 improve component initialization compound literals zero-initialize all omitted fields including children.size, now we don't have to explicitly do that in each function commit913286e9e7
Merge:425e670
520b0b9
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 01:18:39 2024 +0200 Merge branch 'main' into button commit425e6709b4
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 01:16:38 2024 +0200 initialize children size to 0 on childless components commit70ef0e030f
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 01:13:39 2024 +0200 fix vertex input attribute description commit44204b5677
Merge:0788992
f95c47d
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 01:03:26 2024 +0200 Merge branch 'main' into button commit0788992af4
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 00:45:13 2024 +0200 remove vk_clickable from components commit7cc71d3177
Merge:3020724
b74186b
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 00:44:02 2024 +0200 Merge branch 'main' into button commit3020724319
Merge:83c7968
80a8069
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 00:18:31 2024 +0200 Merge branch 'main' into button commit83c7968d48
Author: jacekpoz <jacekpoz@proton.me> Date: Tue Aug 13 00:03:51 2024 +0200 a few component changes before separating them from shapes commit4b1fdf8e04
Author: jacekpoz <jacekpoz@proton.me> Date: Mon Aug 12 23:49:52 2024 +0200 rename button to clickable in one more place commit6aeb2124d9
Author: jacekpoz <jacekpoz@proton.me> Date: Mon Aug 12 23:49:39 2024 +0200 improve box creation commitaf3066ab7b
Author: jacekpoz <jacekpoz@proton.me> Date: Mon Aug 12 23:48:39 2024 +0200 add pointer versions of add and remove all in ptk list commitb95ddb45a0
Author: jacekpoz <jacekpoz@proton.me> Date: Mon Aug 12 23:48:14 2024 +0200 rename button to clickable commit50197a6a21
Author: jacekpoz <jacekpoz@proton.me> Date: Sun Aug 11 21:09:02 2024 +0200 change default component members and add PTK_COMPONENT_DEFINE commit2b5be4c732
Author: jacekpoz <jacekpoz@proton.me> Date: Sun Aug 11 21:07:53 2024 +0200 extract PTK_LIST_STATIC_INIT into PTK_ARRAY commit276138043d
Author: jacekpoz <jacekpoz@proton.me> Date: Fri Aug 9 22:04:01 2024 +0200 make the example target not remove the binary commitc101379150
Author: jacekpoz <jacekpoz@proton.me> Date: Fri Aug 9 17:16:35 2024 +0200 initial button test
108 lines
4.5 KiB
C
108 lines
4.5 KiB
C
// Copyright (jacekpoz 2024). Licensed under the EUPL-1.2 or later.
|
|
|
|
#include <test.h>
|
|
#include <ptk_list.h>
|
|
|
|
PTK_LIST_DEFINE(uint32_t);
|
|
|
|
TEST_START()
|
|
TEST("create list", {
|
|
const size_t size = 5;
|
|
PTK_LIST(uint32_t) list = PTK_LIST_NEW(uint32_t, size);
|
|
|
|
TEST_ASSERT(list.allocated == size, "incorrect list allocation");
|
|
TEST_ASSERT(list.size == 0, "list isn't empty after allocation");
|
|
});
|
|
|
|
TEST("add elements without growing", {
|
|
const size_t size = 5;
|
|
PTK_LIST(uint32_t) list = PTK_LIST_NEW(uint32_t, size);
|
|
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){21});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){37});
|
|
|
|
TEST_ASSERT(list.size == 2, "size doesn't match number of elements added");
|
|
TEST_ASSERT(list.allocated == size, "needlessly grew list");
|
|
|
|
TEST_ASSERT(list.data[0] == 21, "first element doesn't match");
|
|
TEST_ASSERT(list.data[1] == 37, "second element doesn't match");
|
|
});
|
|
|
|
TEST("add elements and grow", {
|
|
const size_t size = 1;
|
|
PTK_LIST(uint32_t) list = PTK_LIST_NEW(uint32_t, size);
|
|
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){21});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){37});
|
|
|
|
TEST_ASSERT(list.allocated == size * 2, "(1st grow) didn't grow size by a factor of 2");
|
|
TEST_ASSERT(list.data[1] == 37, "(1st grow) element added in grown space doesn't match");
|
|
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){2137});
|
|
|
|
TEST_ASSERT(list.allocated == size * 4, "(2nd grow) didn't grow size by a factor of 2");
|
|
TEST_ASSERT(list.data[2] == 2137, "(2nd grow) element added in grown space doesn't match");
|
|
});
|
|
|
|
TEST("add multiple elements", {
|
|
const size_t size = 1;
|
|
PTK_LIST(uint32_t) list = PTK_LIST_NEW(uint32_t, size);
|
|
|
|
PTK_LIST_ADD_ALL(uint32_t, list, { 21, 37, 2137, 31, 27, 7312 });
|
|
TEST_ASSERT(list.size == 6, "size doesn't match number of elements added");
|
|
|
|
TEST_ASSERT(list.data[0] == 21, "first element doesn't match");
|
|
TEST_ASSERT(list.data[5] == 7312, "last element doesn't match");
|
|
});
|
|
|
|
TEST("remove elements", {
|
|
const size_t size = 1;
|
|
PTK_LIST(uint32_t) list = PTK_LIST_NEW(uint32_t, size);
|
|
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){21});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){37});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){2137});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){31});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){27});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){7312});
|
|
|
|
PTK_LIST_REMOVE(uint32_t, list, (uint32_t){2137});
|
|
TEST_ASSERT(list.size == 5, "size doesn't match after removing");
|
|
TEST_ASSERT(list.data[2] == 31, "remaining elements not moved to the left");
|
|
TEST_ASSERT(list.data[4] == 7312, "last element moved improperly (check for off-by-ones)");
|
|
});
|
|
|
|
TEST("remove multiple elements", {
|
|
const size_t size = 1;
|
|
PTK_LIST(uint32_t) list = PTK_LIST_NEW(uint32_t, size);
|
|
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){21});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){37});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){2137});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){31});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){27});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){7312});
|
|
|
|
PTK_LIST_REMOVE_ALL(uint32_t, list, { 2137, 37, 27 });
|
|
TEST_ASSERT(list.size == 3, "size doesn't match after removing");
|
|
TEST_ASSERT(list.data[1] == 31, "remaining elements not moved to the left");
|
|
TEST_ASSERT(list.data[2] == 7312, "last element moved improperly (check for off-by-ones)");
|
|
});
|
|
|
|
TEST("remove elements at index", {
|
|
const size_t size = 1;
|
|
PTK_LIST(uint32_t) list = PTK_LIST_NEW(uint32_t, size);
|
|
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){21});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){37});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){2137});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){31});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){27});
|
|
PTK_LIST_ADD(uint32_t, list, (uint32_t){7312});
|
|
|
|
PTK_LIST_REMOVE_AT(uint32_t, list, 2);
|
|
TEST_ASSERT(list.size == 5, "size doesn't match after removing");
|
|
TEST_ASSERT(list.data[2] == 31, "remaining elements not moved to the left");
|
|
TEST_ASSERT(list.data[4] == 7312, "last element moved improperly (check for off-by-ones)");
|
|
});
|
|
TEST_FINISH()
|