mirror of
https://github.com/cellos51/balatro-gba.git
synced 2026-09-09 17:36:16 -05:00
* initial commit * wip * WIP * WIP * clang format * Choose Seed navigation mostly done * seed input navigation done * seed input done * cleanup and clang format * Implement base 10 to 36 conversions * Enable seeded runs * clang format * show default deck sprite, name and description * Rename Deck enum to DeckType * Implement arbitrary 9-patch expand system * Make 9-patch example smaller in the docs * Improve NinePatchRect docs * fix Deck back side sprite palette * clang format * Add last deck description * clang format * Fix 'Z' in seed input keyboard * Fix rebase issue * fix deck sprite not updating * Documents static funcs in run_setup.c * more documentation * clang format * Move Play button to the left in its row * Tests WIP * removing tests for random.h * use the new StateMachine struct * First wave of fixes * Fix the 9-patch again * Changed the base 36 logic so it's in big endian * properly set end of base 36 string to '\0' * typos * fix cursor position after rolling a seed + fix random seed generation * Make keyboard more intuitive to use * static const var * Address more comment from @ricfehr3 * clang format * clang format * clang format * clang format * clang format * clang format * clang format * fix deck palette * create the `DEF_SEED_KEYBOARD_BUTTON_OBJECT` macro * Replace `expand_3x3` by a call to `expand_9-patch` * clang format * clang format * clang format * fix rebase iussue in state_machine.h --------- Co-authored-by: MathisMartin31 <mathis.martin31@gmail.com>
300 lines
11 KiB
C
300 lines
11 KiB
C
#include <font.h>
|
|
#include <stdint.h>
|
|
#include <util.h>
|
|
#include <assert.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
|
|
void test_truncate_uint_to_suffixed_str()
|
|
{
|
|
/*
|
|
* I want to avoid testing the rounding so it can be easily changed
|
|
* so all tests are numbers that are rounded down regardless of rounding method.
|
|
* That way the function can be modified to round to nearest integer easily.
|
|
*/
|
|
|
|
char suffixed_str_buff[UINT_MAX_DIGITS + 1] = {'\0'};
|
|
|
|
truncate_uint_to_suffixed_str(100, 3, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "100") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1000, 3, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1K") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1000, 2, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1K") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1000, 1, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1K") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1000, 0, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1K") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(0, 0, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "0") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(100, 2, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "100") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(100, 1, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "100") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(123, 1, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "123") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1234, 3, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1" FP2_STR "K") == 0); // "1.2K"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1600, 3, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1" FP6_STR "K") == 0); // "1.6K"
|
|
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1000, 4, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1000") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1000, 5, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1000") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(12123, 4, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "12" FP1_STR "K") == 0); // "12.1K"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(123123, 4, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "123K") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(123123, 5, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "123" FP1_STR "K") == 0); // "123.1K"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(123123, 6, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "123123") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(123123, 7, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "123123") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(12345123, 6, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "12" FP3_STR "45M") == 0); // "12.345M"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(12123123, 5, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "12" FP1_STR "2M") == 0); // "12.12M"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1008000, 5, suffixed_str_buff);
|
|
|
|
assert(strcmp(suffixed_str_buff, "1" FP0_STR "08M") == 0); // "1.008M"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(3029000, 5, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "3" FP0_STR "29M") == 0); // "3.029M"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(10007000, 5, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "10M") == 0); // Decimal point fully truncated
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(10005123, 6, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "10" FP0_STR "05M") == 0); // "10.005M"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(12123123, 4, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "12" FP1_STR "M") == 0); // "12.1M"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(54123123, 4, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "54" FP1_STR "M") == 0); // "54.1M"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(123123123, 4, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "123M") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(123123123, 6, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "123" FP1_STR "2M") == 0); // "123.12M"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(987123123, 6, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "987" FP1_STR "2M") == 0); // "987.12M"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(123123123, 7, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "123" FP1_STR "23M") == 0); // "123.123M"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(123123123, 8, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "123" FP1_STR "231M") == 0); // "123.1231M"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(123123123, 9, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "123123123") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1123123123, 4, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1" FP1_STR "2B") == 0); // "1.12B"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str((uint32_t)3012012012, 4, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "3" FP0_STR "1B") == 0); // "3.01B"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1234123123, 5, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1" FP2_STR "34B") == 0); // "1.234B"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1000512345, 6, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1" FP0_STR "005B") == 0); // "1.0005B"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1234561234, 7, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1" FP2_STR "3456B") == 0); // "1.23456B"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1000061234, 7, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1" FP0_STR "0006B") == 0); // "1.00006B"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1234567123, 8, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1" FP2_STR "34567B") == 0); // "1.234567B"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1000007123, 8, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1" FP0_STR "00007B") == 0); // "1.000007B"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1234567812, 9, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1" FP2_STR "345678B") == 0); // "1.2345678B"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1000000812, 9, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1" FP0_STR "000008B") == 0); // "1.0000008B"
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1123123123, 10, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1123123123") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1123123123, UINT_MAX_DIGITS, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1123123123") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(1123123123, 100, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "1123123123") == 0);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(UINT32_MAX, 4, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "4" FP2_STR "9B") == 0); // "4.29B"
|
|
|
|
// This is one of the few tests that checks rounding down, try not to add many more
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(UINT32_MAX, 5, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, "4" FP2_STR "94B") == 0); // "4.294B"
|
|
|
|
char max_uint_str_buff[UINT_MAX_DIGITS + 1] = {'\0'};
|
|
snprintf(max_uint_str_buff, sizeof(max_uint_str_buff), "%lu", UINT32_MAX);
|
|
|
|
suffixed_str_buff[0] = '\0';
|
|
truncate_uint_to_suffixed_str(UINT32_MAX, UINT_MAX_DIGITS, suffixed_str_buff);
|
|
assert(strcmp(suffixed_str_buff, max_uint_str_buff) == 0);
|
|
}
|
|
|
|
void test_base36_conversions(void)
|
|
{
|
|
char base36_str[BASE36_MAX_DIGITS + 1] = {'\0'};
|
|
uint32_t base10_int;
|
|
|
|
// Base-36 Str => Int
|
|
|
|
snprintf(base36_str, sizeof(base36_str), "%s", "ZZZZZZ");
|
|
assert(base36_to_u32(base36_str) == MAX_BASE36);
|
|
|
|
snprintf(base36_str, sizeof(base36_str), "%s", "000000");
|
|
assert(base36_to_u32(base36_str) == 0);
|
|
|
|
snprintf(base36_str, sizeof(base36_str), "%s", "000001");
|
|
assert(base36_to_u32(base36_str) == 1);
|
|
|
|
snprintf(base36_str, sizeof(base36_str), "%s", "000010");
|
|
assert(base36_to_u32(base36_str) == 36);
|
|
|
|
snprintf(base36_str, sizeof(base36_str), "%s", "000100");
|
|
assert(base36_to_u32(base36_str) == 1296);
|
|
|
|
snprintf(base36_str, sizeof(base36_str), "%s", "001000");
|
|
assert(base36_to_u32(base36_str) == 46656);
|
|
|
|
snprintf(base36_str, sizeof(base36_str), "%s", "010000");
|
|
assert(base36_to_u32(base36_str) == 1679616);
|
|
|
|
snprintf(base36_str, sizeof(base36_str), "%s", "100000");
|
|
assert(base36_to_u32(base36_str) == 60466176);
|
|
|
|
// Base-36 Str => Int
|
|
|
|
base10_int = 0;
|
|
u32_to_base36(base10_int, base36_str);
|
|
assert(strcmp(base36_str, "000000") == 0);
|
|
|
|
base10_int = 1;
|
|
u32_to_base36(base10_int, base36_str);
|
|
assert(strcmp(base36_str, "000001") == 0);
|
|
|
|
base10_int = 36;
|
|
u32_to_base36(base10_int, base36_str);
|
|
assert(strcmp(base36_str, "000010") == 0);
|
|
|
|
base10_int = 1296;
|
|
u32_to_base36(base10_int, base36_str);
|
|
assert(strcmp(base36_str, "000100") == 0);
|
|
|
|
base10_int = 46656;
|
|
u32_to_base36(base10_int, base36_str);
|
|
assert(strcmp(base36_str, "001000") == 0);
|
|
|
|
base10_int = 1679616;
|
|
u32_to_base36(base10_int, base36_str);
|
|
assert(strcmp(base36_str, "010000") == 0);
|
|
|
|
base10_int = 60466176;
|
|
u32_to_base36(base10_int, base36_str);
|
|
assert(strcmp(base36_str, "100000") == 0);
|
|
|
|
base10_int = MAX_BASE36;
|
|
u32_to_base36(base10_int, base36_str);
|
|
assert(strcmp(base36_str, "ZZZZZZ") == 0);
|
|
|
|
base10_int = UINT32_MAX;
|
|
u32_to_base36(base10_int, base36_str);
|
|
assert(strcmp(base36_str, "ZZZZZZ") == 0);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
printf("Testing Truncating UINT32.\n");
|
|
test_truncate_uint_to_suffixed_str();
|
|
|
|
printf("Testing Base-36 conversions.\n");
|
|
test_base36_conversions();
|
|
|
|
printf("-------------------------------------------------------------------------------\n");
|
|
printf("Util Tests Passed :)\n");
|
|
printf("-------------------------------------------------------------------------------\n");
|
|
|
|
return 0;
|
|
} |