package game import ( "testing" "muhq.space/muhqs-game/go/utils" ) const PASS_STRING = "muhq\u00A0pass" var s *LocalState = NewLocalState() var p *Player = s.AddNewPlayer("muhq", NewDeck()) func TestUpkeepAction(t *testing.T) { s := NewLocalState() p := s.AddNewPlayer("muhq", NewDeck()) o := s.AddNewPlayer("opponent", NewDeck()) m, _ := GetMap("2P-ring-street") s.SetMap(m) archer := s.addNewUnit(NewCard("base/archer"), Position{0, 0}, p) farmer := s.addNewUnit(NewCard("misc/farmer"), Position{0, 1}, p) // Change controller knight := s.addNewUnit(NewCard("base/knight"), Position{0, 2}, o) knight.controller = p king := s.addNewUnit(NewCard("misc/king"), Position{2, 2}, o) n := newUpkeepPrompt(p) ctx := n.Context.(TargetSelectionCtx) if ctx.Action.Source().(*Player) != p { t.Fatal("unexpected player ", p) } trgts := ctx.Action.Targets() if !trgts.AllowSelection() { t.Fatal("upkeep action does not allow target selection") } if trgts.RequireSelection() { t.Fatal("upkeep action does require selection") } opts := trgts.Options() if !utils.InterfaceSliceContains(opts, archer) || !utils.InterfaceSliceContains(opts, farmer) || !utils.InterfaceSliceContains(opts, farmer) { t.Fatal("Upkeep action targets does not contain the controlled units") } if utils.InterfaceSliceContains(opts, king) { t.Fatal("Upkeep action targets contains uncontrolled units") } } func TestMarshalPass(t *testing.T) { exp := PASS_STRING a := NewPassPriority(p) is := string(MarshalAction(a)) if is != exp { t.Fatalf("expected string %s does not match %s\n", exp, is) } } func TestUnmarshalPass(t *testing.T) { in := PASS_STRING a, err := UnmarshalAction(s, []byte(in)) if err != nil { t.Fatal(err) } if _, ok := a.(*PassPriority); !ok { t.Fatalf("expexted PassPriority not %s", a) } } const PICK_ACTION_STRING = "muhq\u00A0pick\u00A0base/archer:[base/archer, magic/more!]" func TestMarshalPickAction(t *testing.T) { exp := PICK_ACTION_STRING poc := NewPileOfCards() c := NewCard("base/archer") poc.AddCard(c) poc.AddCard(NewCard("magic/more!")) a := NewDraftPick(p, poc, c) is := string(MarshalAction(a)) if is != exp { t.Fatalf("expected string %s does not match %s\n", exp, is) } } func TestUnmarshalPickAction(t *testing.T) { in := PICK_ACTION_STRING a, err := UnmarshalAction(s, []byte(in)) if err != nil { t.Fatal(err) } var p *DraftPick var ok bool if p, ok = a.(*DraftPick); !ok { t.Fatalf("expexted DraftPick not %v", a) } if len(p.pack.Cards()) != 2 { t.Fatalf("expexted two cards in pack not %d", len(p.pack.Cards())) } if p.pick.Name != "Archer" { t.Fatalf("expexted archer beeing picked not %s", p.pick.Path()) } }