func main() { var dungeonMapName = flag.String("dungeon", "", "Dungeon map file") flag.Parse() if *dungeonMapName == "" { flag.Usage() os.Exit(1) } dungeonMap, err := dungeon.Load(*dungeonMapName) if err != nil { fmt.Println(err) os.Exit(1) } strategy := strategy.Dijkstra{} solver := solver.New(dungeonMap, &strategy) minHP, bestRoute, err := solver.Solve() if err != nil { fmt.Println(err) os.Exit(1) } fmt.Printf("MIN HP: %d\n", minHP) fmt.Printf("BEST ROUTE: %s\n", strings.Join(bestRoute, " -> ")) }
"github.com/tscolari/dungeon_game/solver" "github.com/tscolari/dungeon_game/solver/fakes" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Solver", func() { var strategy *fakes.FakeStrategy var dungeonMap dungeon.Dungeon var subject *solver.Solver BeforeEach(func() { dungeonMap = dungeon.Dungeon{} strategy = new(fakes.FakeStrategy) subject = solver.New(dungeonMap, strategy) }) Describe("#Solve", func() { It("converts the strategy value to actually minHP points", func() { strategy.FindBestRouteReturns(-10, []string{}, nil) minHP, _, _ := subject.Solve() Expect(minHP).To(Equal(11)) }) It("forwards the error if the strategy returns one", func() { expectedError := errors.New("something bad happened") strategy.FindBestRouteReturns(0, []string{}, expectedError) _, _, err := subject.Solve()