Skip to content

Commit

Permalink
Put coverage off in appropriate places + fix Test Plan
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-sunwook committed May 24, 2021
1 parent 77584e6 commit 528a6df
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
12 changes: 12 additions & 0 deletions board.ml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ let get_adjacent_tiles (row, col) t =
let rec space_tr acc = function
| 0 -> acc
| len -> space_tr (acc ^ " ") (len - 1)
[@@coverage off]

(** [space len] is a space with length of [len].*)
let space len = space_tr "" len
Expand All @@ -153,13 +154,15 @@ let row_to_string spacing row =
let add_letter str t = str ^ space ^ Char.escaped t.letter in
let spaced_str = Array.fold_left add_letter "" row in
String.sub spaced_str spacing (String.length spaced_str - spacing)
[@@coverage off]

(** [formatted_int i] is string representation of [i] with two digits.
Example: 1 becomes "01", 12 becomes "12" Remark: The length of
[formatted_int] should equal the [spacing] variables used in other
functions*)
let formatted_int i =
string_of_int i |> fun s -> if String.length s = 1 then "0" ^ s else s
[@@coverage off]

(**[col_indices_row_string n] is the first row in [to_string] which
marks the indices of the 0th to the ([n]-1)th column. *)
Expand All @@ -169,6 +172,7 @@ let col_indices_row_string n =
| n -> rec_tr (i + 1) (acc ^ formatted_int i ^ " ") (n - 1)
in
rec_tr 0 "" n
[@@coverage off]

let to_string b =
let spacing = 2 in
Expand All @@ -184,6 +188,7 @@ let to_string b =
^ col_indices_row_string (Array.length rows)
^ "\n"
^ String.sub string_of_rows 1 (String.length string_of_rows - 1)
[@@coverage off]

let bonus_to_color bon =
match bon with
Expand All @@ -204,34 +209,40 @@ let extract_ready_to_print_row
([ itile_to_color itil ], Char.escaped til.letter ^ space spacing))
tb ib
|> Array.to_list
[@@coverage off]

let extract_ready_to_print_rows spacing b =
Array.map2
(extract_ready_to_print_row spacing)
b.tile_board b.info_board
|> Array.mapi (fun i row ->
([], formatted_int i ^ space spacing) :: row)
[@@coverage off]

let print_ready_to_print_row row =
List.fold_left
(fun _ (styles, str) -> ANSITerminal.print_string styles str)
() row;
print_string [] "\n"
[@@coverage off]

let print_ready_to_print_rows rows =
for i = 0 to Array.length rows - 1 do
print_ready_to_print_row rows.(i)
done
[@@coverage off]

let print_col_indices_row spacing n =
print_string [] (space (spacing * 2) ^ col_indices_row_string n)
[@@coverage off]

let print_legend () =
print_string [ bonus_to_color N ] (string_of_bonus N ^ " ");
print_string [ bonus_to_color DL ] (string_of_bonus DL ^ " ");
print_string [ bonus_to_color TL ] (string_of_bonus TL ^ " ");
print_string [ bonus_to_color DW ] (string_of_bonus DW ^ " ");
print_string [ bonus_to_color TW ] (string_of_bonus TW ^ " ")
[@@coverage off]

let print_board b =
let spacing = 2 in
Expand All @@ -242,6 +253,7 @@ let print_board b =
print_string [] "\n";
print_ready_to_print_rows ready_to_print_rows;
print_legend ()
[@@coverage off]

(** Helper function to check if word is in dictionary*)
let word_in_dict dict word = List.mem word dict
Expand Down
12 changes: 6 additions & 6 deletions display.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ let print_end () = print_endline "\nThank you for playing!\n"
let print_winner score = function
| [ n ] ->
print_endline
("\nThe winner is player " ^ string_of_int n ^ " with score "
^ string_of_int score ^ "!")
( "\nThe winner is player " ^ string_of_int n ^ " with score "
^ string_of_int score ^ "!" )
| [ fst; snd ] ->
print_endline
("\nThe winners are players " ^ string_of_int fst ^ " and "
^ string_of_int snd ^ " with score " ^ string_of_int score ^ "!"
( "\nThe winners are players " ^ string_of_int fst ^ " and "
^ string_of_int snd ^ " with score " ^ string_of_int score ^ "!"
)
| lst ->
print_endline
("\nThe winners are players "
( "\nThe winners are players "
^ List.fold_left
(fun acc x -> acc ^ string_of_int x ^ ", ")
"" lst
^ " with score " ^ string_of_int score ^ "!")
^ " with score " ^ string_of_int score ^ "!" )

let print_pool p =
print_endline ("\nLetter Pool: " ^ Pool.to_string p ^ " tiles left.")
Expand Down
1 change: 1 addition & 0 deletions hand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,4 @@ let to_string hand =
List.fold_left (fun str c -> str ^ ", " ^ Char.escaped c) "" hand
in
String.sub s 1 (String.length s - 1)
[@@coverage off]
2 changes: 1 addition & 1 deletion pool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ let draw_letter pool =
pool.letters <- remove_nth i pool.letters;
drawn_letter

let to_string pool = string_of_int (size pool)
let to_string pool = string_of_int (size pool) [@@coverage off]
2 changes: 1 addition & 1 deletion score.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ let update_score sc new_words =

let get_score sc = sc.score

let to_string sc = string_of_int sc.score
let to_string sc = string_of_int sc.score [@@coverage off]
6 changes: 3 additions & 3 deletions test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ open Pool
Test Plan
The Game module is tested via playtest, as the interaction on the
command line is the core experience of the module. All other modules
are tested by both unit tests and playtest.
The Game module and Display module is tested via playtest, as the
interaction on the command line is the core experience of the modules.
All other modules are tested by both unit tests and playtest.
We mainly use blackbox testing as evaluating the actual edge cases in
the gameplay is important - not causing errors is not enough. After we
Expand Down

0 comments on commit 528a6df

Please sign in to comment.