Skip to content

Commit

Permalink
tests(p12) add dune's settings and tests for tailrec
Browse files Browse the repository at this point in the history
  • Loading branch information
pmpknu committed Oct 22, 2024
1 parent 82390bf commit ecf0185
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 0 deletions.
29 changes: 29 additions & 0 deletions p12/.gitignore
Original file line number Diff line number Diff line change
@@ -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/
4 changes: 4 additions & 0 deletions p12/bin/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(executable
(public_name p12)
(name main)
(libraries p12_lib))
1 change: 1 addition & 0 deletions p12/bin/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = print_endline "Hello, World!"
23 changes: 23 additions & 0 deletions p12/dune-project
Original file line number Diff line number Diff line change
@@ -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)
)

4 changes: 4 additions & 0 deletions p12/lib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(library
(name p12_lib)
(modules iterative map module rec tailrec)
)
28 changes: 28 additions & 0 deletions p12/p12.opam
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions p12/test/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(test
(name test_p12)
(libraries p12_lib ounit2))
21 changes: 21 additions & 0 deletions p12/test/test_p12.ml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ecf0185

Please sign in to comment.