Go binary/server for helping run/build sessions for the Maze Rats TTRPG
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

81 lines
2.6 KiB

package tables
import (
"reflect"
"strings"
"testing"
)
func TestGenCharacter(t *testing.T) {
t.Parallel()
char := GenCharacter(1)
tests := []struct {
field string
actual interface{}
expected interface{}
}{
{field: "Name", actual: char.Name, expected: "Vivian Villin"},
{field: "Stats.MaxHealth", actual: char.Stats.MaxHealth, expected: 4},
{field: "Stats.Armor", actual: char.Stats.Armor, expected: 6},
{field: "Stats.STR", actual: char.Stats.STR, expected: 0},
{field: "Stats.DEX", actual: char.Stats.DEX, expected: 1},
{field: "Stats.WIL", actual: char.Stats.WIL, expected: 2},
{field: "Feature", actual: char.Feature, expected: "Shadowjack (Advantage on moving silently or hiding in shadows)"},
{field: "Weapons", actual: char.Weapons, expected: []string{"Warhammer", "Whip"}},
{field: "Items", actual: char.Items, expected: []string{"Vial of Acid", "Waterskin", "Chisel", "Fishing Net", "Metal file", "Hacksaw"}},
{field: "Appearance", actual: char.Appearance, expected: "Bullnecked"},
{field: "PhysicalDetail", actual: char.PhysicalDetail, expected: "Bushy eyebrows"},
{field: "Background", actual: char.Background, expected: "Peddler"},
{field: "Clothing", actual: char.Clothing, expected: "Food-stained"},
{field: "Personality", actual: char.Personality, expected: "Cowardly"},
{field: "Mannerism:", actual: char.Mannerism, expected: "Robotic"},
}
for _, sTest := range tests {
// https://github.com/golang/go/wiki/CommonMistakes#using-reference-to-loop-iterator-variable
sTest := sTest
t.Run("Character."+sTest.field, func(t *testing.T) {
t.Parallel()
if !reflect.DeepEqual(sTest.actual, sTest.expected) {
t.Errorf("Expected %#v to equal %#v", sTest.actual, sTest.expected)
}
})
}
}
var expectedText = strings.TrimSpace(`
Name: Vivian Villin
Feature: Shadowjack (Advantage on moving silently or hiding in shadows)
Background: Peddler
Stats:
Health: 4
Armor: 6 (+1 for shield, +1 for light armor, +2 for heavy armor)
STR: 0 (Used for raw power, stamina, or physical resilience)
DEX: 1 (Used for speed, agility, or precision)
WIL: 2 (Used for force of personality, perception, or willpower)
Appearance: Bullnecked
Physical Detail: Bushy eyebrows
Clothing: Food-stained
Personality: Cowardly
Mannerism: Robotic
Items:
Vial of Acid
Waterskin
Chisel
Fishing Net
Metal file
Hacksaw
`)
func TestCharacterToText(t *testing.T) {
t.Parallel()
char := GenCharacter(1)
result, err := CharacterToText(char)
if err != nil {
t.Error(err)
}
if result != expectedText {
t.Errorf("Exected following to be equal:\n%#v\n%#v", result, expectedText)
}
}