aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/economy/coins_test.go
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2024-09-13 14:32:15 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2024-09-13 14:32:15 -0400
commit51723cfd9a7d31643fa7c14cc2df9d8e9e2bd33d (patch)
tree70cc0e0f9d789b4be3d9249c3ecc23608bb9fa10 /economy/coins_test.go
parent8759523157afb38f8565687ebd0e1f29a1af3e42 (diff)
Add money and head handling functions
Created types to manage the cannonical coinage of DnD. First pass at computing computing values for heads.
Diffstat (limited to 'economy/coins_test.go')
-rw-r--r--economy/coins_test.go90
1 files changed, 90 insertions, 0 deletions
diff --git a/economy/coins_test.go b/economy/coins_test.go
new file mode 100644
index 0000000..d318fbe
--- /dev/null
+++ b/economy/coins_test.go
@@ -0,0 +1,90 @@
+package economy_test
+
+import (
+ "nonsense-time/economy"
+ "testing"
+)
+
+func assert[T comparable](t *testing.T, expected T, actual T) bool {
+ if expected != actual {
+ t.Logf("expected %v != actual %v\n", expected, actual)
+ t.Fail()
+ return false
+ }
+
+ return true
+}
+
+func TestMoneyAdd(t *testing.T) {
+ a := economy.Money{0, -1, -2, -3, -4}
+ b := economy.Money{1, 2, 3, 4, 5}
+ a.Add(b)
+
+ pass := true
+ pass = pass && assert(t, 1, a.Copper)
+ pass = pass && assert(t, 1, a.Silver)
+ pass = pass && assert(t, 1, a.Electrum)
+ pass = pass && assert(t, 1, a.Gold)
+ pass = pass && assert(t, 1, a.Platinum)
+ if !pass {
+ t.Logf("%+v\n", a)
+ }
+
+}
+
+func TestMoneySubtract(t *testing.T) {
+ a := economy.Money{1, 2, 3, 4, 5}
+ b := economy.Money{0, 1, 2, 3, 4}
+
+ a.Subtract(b)
+
+ pass := true
+ pass = pass && assert(t, 1, a.Copper)
+ pass = pass && assert(t, 1, a.Silver)
+ pass = pass && assert(t, 1, a.Electrum)
+ pass = pass && assert(t, 1, a.Gold)
+ pass = pass && assert(t, 1, a.Platinum)
+ if !pass {
+ t.Logf("%+v\n", a)
+ }
+}
+
+func TestMoneyMult(t *testing.T) {
+ a := economy.Money{1, 2, 3, 5, 7}
+ b := economy.Money{11, 13, 17, 19, 23}
+
+ t.Log("Testing positive multiplication")
+ a.Multiply(b)
+
+ pass := true
+ pass = pass && assert(t, 11, a.Copper)
+ pass = pass && assert(t, 26, a.Silver)
+ pass = pass && assert(t, 51, a.Electrum)
+ pass = pass && assert(t, 95, a.Gold)
+ pass = pass && assert(t, 161, a.Platinum)
+ if !pass {
+ t.Logf("%+v\n", a)
+ }
+}
+
+func TestMoneyValue(t *testing.T) {
+ a := economy.Money{1, 1, 1, 1, 1}
+
+ t.Log("Testing all positive coins")
+ if !assert(t, 1161, a.Value()) {
+ t.Log(a)
+ }
+
+ t.Log("Testing all negative coins")
+ a = economy.Money{-1, -1, -1, -1, -1}
+ if !assert(t, -1161, a.Value()) {
+ t.Log(a)
+ }
+
+ t.Log("Testing mixed coins")
+ a.Copper = 10
+ a.Electrum = 2
+ if !assert(t, -1000, a.Value()) {
+ t.Log(a)
+ }
+}