Files
code_of_conquest_dnd/client/tests/unit/test_currency.gd
Phillip Tarrant 2a372bff2f feat(currency): the Currency value type — copper, ratios, formatting
One integer, stored in copper. The ratios are rules and live in code; prices
are content and land in M8. format() suppresses empty denominations so being
broke reads as '47c', not '0g 0s 47c'.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QYa9u7Kdxv5gX4AnwWexy8
2026-07-12 18:26:22 -05:00

43 lines
1.2 KiB
GDScript

extends "res://addons/gut/test.gd"
func test_format_zero_is_copper():
assert_eq(Currency.format(0), "0c")
func test_format_sub_silver():
assert_eq(Currency.format(8), "8c")
assert_eq(Currency.format(47), "47c")
func test_format_exact_denominations():
assert_eq(Currency.format(100), "1s")
assert_eq(Currency.format(10000), "1g")
func test_format_full_ladder():
assert_eq(Currency.format(143), "1s 43c")
assert_eq(Currency.format(347), "3s 47c")
assert_eq(Currency.format(124008), "12g 40s 8c")
func test_format_skips_empty_middle_and_tail():
assert_eq(Currency.format(10008), "1g 8c", "an empty silver place is skipped, not zero-padded")
assert_eq(Currency.format(124000), "12g 40s", "an empty copper place is skipped")
func test_value_of_each_denomination():
assert_eq(Currency.value("copper"), 1)
assert_eq(Currency.value("silver"), 100)
assert_eq(Currency.value("gold"), 10000)
func test_non_currency_id_is_not_money():
assert_false(Currency.is_currency("worn_shortsword"))
assert_eq(Currency.value("worn_shortsword"), 0)
func test_currency_ids_are_currency():
for id in ["copper", "silver", "gold"]:
assert_true(Currency.is_currency(id), "%s is money" % id)