test.ml 838 B

12345678910111213141516171819202122232425262728293031323334353637
  1. open Base
  2. open OUnit2
  3. let sample = {|..##.......
  4. #...#...#..
  5. .#....#..#.
  6. ..#.#...#.#
  7. .#...##..#.
  8. ..#.##.....
  9. .#.#.#....#
  10. .#........#
  11. #.##...#...
  12. #...##....#
  13. .#..#...#.#|}
  14. let test_parse_map map _ =
  15. let _ = Lib.parse_map map in ()
  16. let test_slope map slope exp _ =
  17. let map = Lib.parse_map map in
  18. assert_equal (Lib.count_trees_in_slope map slope) exp
  19. let test_slopes map slopes exp _ =
  20. let map = Lib.parse_map map in
  21. let count = Lib.count_trees_in_slope map in
  22. let counts = List.map ~f:count slopes in
  23. let product = List.fold ~init:1 ~f:(fun x y -> x * y) counts in
  24. assert_equal product exp
  25. let () =
  26. run_test_tt_main
  27. ("day three" >:::
  28. [
  29. "parse map" >:: test_parse_map sample;
  30. "test map" >:: test_slope sample (3, 1) 7;
  31. "test map" >:: test_slopes sample Lib.all_slopes 336;
  32. ])