From ecf0185db0474d5094634f449818f1006438948e Mon Sep 17 00:00:00 2001 From: pmpknu Date: Tue, 22 Oct 2024 17:32:39 +0300 Subject: [PATCH] tests(p12) add dune's settings and tests for tailrec --- p12/.gitignore | 29 +++++++++++++++++++++++++++++ p12/bin/dune | 4 ++++ p12/bin/main.ml | 1 + p12/dune-project | 23 +++++++++++++++++++++++ p12/lib/dune | 4 ++++ p12/p12.opam | 28 ++++++++++++++++++++++++++++ p12/test/dune | 3 +++ p12/test/test_p12.ml | 21 +++++++++++++++++++++ 8 files changed, 113 insertions(+) create mode 100644 p12/.gitignore create mode 100644 p12/bin/dune create mode 100644 p12/bin/main.ml create mode 100644 p12/dune-project create mode 100644 p12/lib/dune create mode 100644 p12/p12.opam create mode 100644 p12/test/dune create mode 100644 p12/test/test_p12.ml diff --git a/p12/.gitignore b/p12/.gitignore new file mode 100644 index 0000000..a18e084 --- /dev/null +++ b/p12/.gitignore @@ -0,0 +1,29 @@ +*.annot +*.cmo +*.cma +*.cmi +*.a +*.o +*.cmx +*.cmxs +*.cmxa + +# ocamlbuild working directory +_build/ + +# ocamlbuild targets +*.byte +*.native + +# oasis generated files +setup.data +setup.log + +# Merlin configuring file for Vim and Emacs +.merlin + +# Dune generated files +*.install + +# Local OPAM switch +_opam/ diff --git a/p12/bin/dune b/p12/bin/dune new file mode 100644 index 0000000..ee7a65f --- /dev/null +++ b/p12/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name p12) + (name main) + (libraries p12_lib)) diff --git a/p12/bin/main.ml b/p12/bin/main.ml new file mode 100644 index 0000000..7bf6048 --- /dev/null +++ b/p12/bin/main.ml @@ -0,0 +1 @@ +let () = print_endline "Hello, World!" diff --git a/p12/dune-project b/p12/dune-project new file mode 100644 index 0000000..602d1d7 --- /dev/null +++ b/p12/dune-project @@ -0,0 +1,23 @@ +(lang dune 3.16) + +(name p12) + +(generate_opam_files true) + +(source + (github pmpknu/fp-lab1)) + +(authors "Dan Gorlyakov") + + +(license MIT) + +; (documentation https://url/to/documentation) + +(package + (name p12) + (synopsis "fp lab1") + (description "two tasks for the first lab for fp course at itmo") + (depends ocaml dune) +) + diff --git a/p12/lib/dune b/p12/lib/dune new file mode 100644 index 0000000..1fdd3f4 --- /dev/null +++ b/p12/lib/dune @@ -0,0 +1,4 @@ +(library + (name p12_lib) + (modules iterative map module rec tailrec) +) diff --git a/p12/p12.opam b/p12/p12.opam new file mode 100644 index 0000000..b7bf127 --- /dev/null +++ b/p12/p12.opam @@ -0,0 +1,28 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "fp lab1" +description: "two tasks for the first lab for fp course at itmo" +authors: ["Dan Gorlyakov"] +license: "MIT" +homepage: "https://github.com/pmpknu/fp-lab1" +bug-reports: "https://github.com/pmpknu/fp-lab1/issues" +depends: [ + "ocaml" + "dune" {>= "3.16"} + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/pmpknu/fp-lab1.git" diff --git a/p12/test/dune b/p12/test/dune new file mode 100644 index 0000000..cf36bed --- /dev/null +++ b/p12/test/dune @@ -0,0 +1,3 @@ +(test + (name test_p12) + (libraries p12_lib ounit2)) diff --git a/p12/test/test_p12.ml b/p12/test/test_p12.ml new file mode 100644 index 0000000..74c4b0b --- /dev/null +++ b/p12/test/test_p12.ml @@ -0,0 +1,21 @@ +open OUnit2 +open P12_lib + +(* Tailrec tests *) +let test_tailrec_count_factors _ = + OUnit2.assert_equal 6 (Tailrec.count_factors_tail 28); + OUnit2.assert_equal 9 (Tailrec.count_factors_tail 36); + OUnit2.assert_equal 0 (Tailrec.count_factors_tail 0) + +let test_tailrec_find_triangular _ = + OUnit2.assert_equal 28 (Tailrec.find_triangular_with_divisors_tail 5); + OUnit2.assert_equal 76576500 (Tailrec.find_triangular_with_divisors_tail 500) + +let suite = + "Project Euler Problem 12 Tests" >::: [ + "Tailrec - count_factors" >:: test_tailrec_count_factors; + "Tailrec - find_triangular" >:: test_tailrec_find_triangular; + ] + +let _ = run_test_tt_main suite + \ No newline at end of file