# HG changeset patch # User Pablo Meier # Date 1585108747 14400 # Tue Mar 24 23:59:07 2020 -0400 # Node ID d37a0ea37d4e203c06d20bcb6d6aac50d79655a2 # Parent 3694fbbb910d79d18e2241cd8ff797aae3e41929 Wire up the tests to actually use my definitions lol diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -3,8 +3,9 @@ run: build ./_build/default/src/$(OUTPUT).exe +.PHONY: test test: - dune runtest + dune runtest -f build: dune build src/$(OUTPUT).exe diff --git a/src/panacea.ml b/src/panacea.ml --- a/src/panacea.ml +++ b/src/panacea.ml @@ -1,3 +1,3 @@ (* open Core *) -let () = Panacea_lib.execute () +let () = Panacea_lib.Main.execute () diff --git a/src/panacea_lib/dune b/src/panacea_lib/dune --- a/src/panacea_lib/dune +++ b/src/panacea_lib/dune @@ -1,6 +1,7 @@ (library (name panacea_lib) (inline_tests) + (modules (:standard gameplay gamestate)) (libraries core re2 logs alcotest) (preprocess (pps ppx_deriving.show ppx_let ppx_jane ppx_inline_test))) diff --git a/src/panacea_lib/gamestate.ml b/src/panacea_lib/gamestate.ml --- a/src/panacea_lib/gamestate.ml +++ b/src/panacea_lib/gamestate.ml @@ -432,6 +432,14 @@ transformations +let player_at {curr_turn; players; _} = + let {location;_} = List.nth_exn players curr_turn in + location + + +let remaining_actions {actions_remaining;_} = actions_remaining + + let update_location city player = {player with location=city} let lose_card card player = diff --git a/src/panacea_lib/gamestate.mli b/src/panacea_lib/gamestate.mli --- a/src/panacea_lib/gamestate.mli +++ b/src/panacea_lib/gamestate.mli @@ -37,12 +37,21 @@ | City of infection_city -(** Printable representation of a Gamestate. *) -val show_gamestate : t -> string - (** Gives us a Gamestate that's ready to play! *) val starting_game : player_names:string list -> difficulty:difficulty -> t + +(* Access functions *) + +(** Where is the current player located? *) +val player_at : t -> infection_city + +(** How many actions do we have remaining? *) +val remaining_actions : t -> int + + +(* Update functions *) + (** Places the current active player to the location. *) val move_player_to : player:string -> city:infection_city -> t -> t @@ -72,3 +81,9 @@ (** Get the name of the player who's turn it is. *) val active_player : t -> string + + +(* Util/debug *) + +(** Printable representation of a Gamestate. *) +val show_gamestate : t -> string diff --git a/src/panacea_lib/main.ml b/src/panacea_lib/main.ml new file mode 100644 --- /dev/null +++ b/src/panacea_lib/main.ml @@ -0,0 +1,6 @@ +open Core + +let execute () = + Gamestate.starting_game ~player_names:["Pablo"; "Karen"; "Sapo"] ~difficulty:Gamestate.Standard + |> Gamestate.show_gamestate + |> print_endline diff --git a/src/panacea_lib/test/gameplay.ml b/src/panacea_lib/test/gameplay.ml --- a/src/panacea_lib/test/gameplay.ml +++ b/src/panacea_lib/test/gameplay.ml @@ -1,10 +1,27 @@ +(* Gameplay functions *) +open Base -let check msg x = Alcotest.(check bool) msg true x + +let original_state = Panacea_lib.Gamestate.starting_game + ~player_names:["Pablo";"Karen";"Sapo"] + ~difficulty:Panacea_lib.Gamestate.Standard + +let actions_on = + List.fold_left ~init:original_state ~f:Panacea_lib.Gameplay.apply_action + -let test_unit () = - check "Give it a shot" true; - check "Another" false +let test_apply_action () = + let open Panacea_lib.Gameplay in + let open Panacea_lib.Gamestate in + Alcotest.(check bool) + "4 Drives" + true + (phys_equal + (player_at (actions_on [Drive Chicago; Drive Montreal; Drive Washington; Drive NewYork])) + NewYork); + Alcotest.(check bool) "Mario voice" true true + let tests = [ - "time", `Quick, test_unit; + "time", `Quick, test_apply_action; ] diff --git a/test/run_tests.ml b/test/run_tests.ml --- a/test/run_tests.ml +++ b/test/run_tests.ml @@ -1,5 +1,3 @@ -(* Gameplay functions *) - let test_suites: unit Alcotest.test list = [ "Gameplay Tests", Test_panacea.Gameplay.tests; ]