func TestDroidippyGames(t *testing.T) { gamedir, err := os.Open("games") if err != nil { t.Fatalf("%v", err) } defer gamedir.Close() gamefiles, err := gamedir.Readdirnames(0) if err != nil { t.Fatalf("%v", err) } sort.Sort(sort.StringSlice(gamefiles)) for _, name := range gamefiles { if skip := os.Getenv("SKIP"); skip == "" || bytes.Compare([]byte(skip), []byte(name)) < 1 { if gameFileReg.MatchString(name) { phases, orders, positions, fails, s := assertGame(t, name) fmt.Printf("Checked %v phases, executed %v orders and asserted %v positions in %v, found %v failures.\n", phases, orders, positions, name, fails) if fails > 0 { dip.DumpLog() for prov, err := range s.Resolutions() { t.Errorf("%v: %v", prov, err) } t.Fatalf("%v failed!", name) } } } } }
func testDATC(t *testing.T, statePair *datc.StatePair) { var s *state.State if statePair.Before.Phase == nil { s = Blank(&phase{ year: 1901, season: cla.Spring, typ: cla.Movement, }) } else { s = Blank(statePair.Before.Phase) } s.SetUnits(statePair.Before.Units) s.SetDislodgeds(statePair.Before.Dislodgeds) s.SetSupplyCenters(statePair.Before.SCs) for prov, order := range statePair.Before.Orders { if s.Phase().Type() == cla.Movement { if u, _, ok := s.Unit(prov); ok && u.Nation == order.Nation { s.SetOrder(prov, order.Order) } } else if s.Phase().Type() == cla.Retreat { if u, _, ok := s.Dislodged(prov); ok && u.Nation == order.Nation { s.SetOrder(prov, order.Order) } } else if s.Phase().Type() == cla.Adjustment { if order.Order.Type() == cla.Build { if n, _, ok := s.SupplyCenter(prov); ok && n == order.Nation { s.SetOrder(prov, order.Order) } } else if order.Order.Type() == cla.Disband { if u, _, ok := s.Unit(prov); ok && u.Nation == order.Nation { s.SetOrder(prov, order.Order) } } } else { t.Fatalf("Unsupported phase type %v", s.Phase().Type()) } } for _, order := range statePair.Before.FailedOrders { if order.Order.Type() == cla.Move && !order.Order.Flags()[cla.ViaConvoy] { s.AddBounce(order.Order.Targets()[0], order.Order.Targets()[1]) } } for _, order := range statePair.Before.SuccessfulOrders { if order.Order.Type() == cla.Move && !order.Order.Flags()[cla.ViaConvoy] { s.SetDislodger(order.Order.Targets()[0], order.Order.Targets()[1]) } } s.Next() err := false for prov, unit := range statePair.After.Units { if found, ok := s.Units()[prov]; ok { if !found.Equal(unit) { err = true t.Errorf("%v: Expected %v in %v, but found %v", statePair.Case, unit, prov, found) } } else { err = true t.Errorf("%v: Expected %v in %v, but found nothing", statePair.Case, unit, prov) } } for prov, unit := range statePair.After.Dislodgeds { if found, ok := s.Dislodgeds()[prov]; ok { if !found.Equal(unit) { err = true t.Errorf("%v: Expected %v dislodged in %v, but found %v", statePair.Case, unit, prov, found) } } else { err = true t.Errorf("%v: Expected %v dislodged in %v, but found nothing", statePair.Case, unit, prov) } } for prov, unit := range s.Units() { if _, ok := statePair.After.Units[prov]; !ok { err = true t.Errorf("%v: Expected %v to be empty, but found %v", statePair.Case, prov, unit) } } for prov, unit := range s.Dislodgeds() { if _, ok := statePair.After.Dislodgeds[prov]; !ok { err = true t.Errorf("%v: Expected %v to be empty of dislodged units, but found %v", statePair.Case, prov, unit) } } if err { dip.DumpLog() t.Errorf("%v: ### Units:", statePair.Case) for prov, unit := range statePair.Before.Units { t.Errorf("%v: %v %v", statePair.Case, prov, unit) } t.Errorf("%v: ### Dislodged before:", statePair.Case) for prov, disl := range statePair.Before.Dislodgeds { t.Errorf("%v: %v %v", statePair.Case, prov, disl) } t.Errorf("%v: ### Orders:", statePair.Case) for _, order := range statePair.Before.Orders { t.Errorf("%v: %v", statePair.Case, order.Order) } t.Errorf("%v: ### Units after:", statePair.Case) for prov, unit := range s.Units() { t.Errorf("%v: %v %v", statePair.Case, prov, unit) } t.Errorf("%v: ### Dislodged after:", statePair.Case) for prov, unit := range s.Dislodgeds() { t.Errorf("%v: %v %v", statePair.Case, prov, unit) } t.Errorf("%v: ### Errors:", statePair.Case) for prov, err := range s.Resolutions() { t.Errorf("%v: %v %v", statePair.Case, prov, err) } t.Fatalf("%v failed", statePair.Case) } }