Skip to content

Commit

Permalink
added spec for Columns
Browse files Browse the repository at this point in the history
  • Loading branch information
rapha committed Apr 17, 2011
1 parent 9272f39 commit 8c04158
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
@@ -1,7 +1,7 @@
all: spec

clean:
find -E . -regex '.*\.(cm..?|a|o|exe|byte|source_dependencies|toplevel)' | xargs rm
find -E . -regex '.*(\.cm..?|\.a|\.o|\.exe|\.byte|.source_dependencies|toplevel)$$' | xargs rm

toplevel: game.cma
ocamlmktop -o toplevel unix.cma nums.cma bigarray.cma str.cma `ocamlfind query camomile`/camomile.cma `ocamlfind query batteries`/batteries_uni.cma game.cma
Expand Down
48 changes: 48 additions & 0 deletions spec/columns_spec.ml
@@ -0,0 +1,48 @@
open Ospecl.Spec
open Ospecl.Matchers

let specs = [
describe "Columns" [
describe ".append" begin
let equals_row = equal_to Row.to_string in
let open Col in [
describe "on Columns.empty" [
it "returns Row1 in any row" begin
let rows =
left_to_right
|> List.map (fun col -> Columns.empty |> Columns.append col "something" |> snd)
in

rows =~ every_item (equals_row Row.Row1)
end
];
it "returns increasing rows in the same column" begin
let open Row in

let equals_row_list = equal_to_list Row.to_string in

let actual_rows =
[Col1; Col1; Col1]
|> List.fold_left (fun (cols, rows) col ->
let (cols, row) = Columns.append col "a" cols in
(cols, row::rows)
) (Columns.empty, [])
|> snd |> List.rev

in
actual_rows =~ equals_row_list [Row1; Row2; Row3]
end;
it "throws Column_full after 6 drops in a given column" begin
let cols =
List.fold_left
(fun cols col -> Columns.append col "a" cols |> fst)
Columns.empty
[Col1; Col1; Col1; Col1; Col1; Col1]
in

(fun _ -> Columns.append Col1 "a" cols) =~ does raise_exn Columns.Full
end
]
end;
];
]
2 changes: 1 addition & 1 deletion src/col.ml
Expand Up @@ -24,4 +24,4 @@ let of_int = function
| 6 -> Col7
| _ -> invalid_arg "col index must be in range [0-6]"

let to_string index = "Col" ^ (index |> to_int |> (+) 1 |> string_of_int)
let to_string index = "Col" ^ (index |> to_int |> succ |> string_of_int)
2 changes: 1 addition & 1 deletion src/row.ml
Expand Up @@ -22,5 +22,5 @@ let of_int = function
| 5 -> Row6
| i -> invalid_arg (Printf.sprintf "Row index of %d is invalid. Must be in range [0-5]." i)

let to_string index = "Row" ^ (index |> to_int |> string_of_int)
let to_string index = "Row" ^ (index |> to_int |> succ |> string_of_int)

0 comments on commit 8c04158

Please sign in to comment.