forked from ls1intum/Artemis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OCaml template for programming exercises (ls1intum#3045)
- Loading branch information
Showing
32 changed files
with
253 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/resources/templates/bamboo/ocaml/regularRuns/1_build_and_test_the_code.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# the build process is specified in `run.sh` in the test repository | ||
chmod +x run.sh | ||
./run.sh |
42 changes: 42 additions & 0 deletions
42
src/main/resources/templates/ocaml/exercise/git.attributes.file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Handle line endings automatically for files detected as text | ||
# and leave all files detected as binary untouched. | ||
* text=auto | ||
|
||
# | ||
# The above will handle all files NOT found below | ||
# | ||
# These files are text and should be normalized (Convert crlf => lf) | ||
*.bash text eol=lf | ||
*.css text diff=css | ||
*.df text | ||
*.htm text diff=html | ||
*.html text diff=html | ||
*.hs text | ||
*.java text diff=java | ||
*.js text | ||
*.json text | ||
*.jsp text | ||
*.jspf text | ||
*.jspx text | ||
*.properties text | ||
*.sh text eol=lf | ||
*.tld text | ||
*.txt text | ||
*.tag text | ||
*.tagx text | ||
*.xml text | ||
*.yml text | ||
|
||
# These files are binary and should be left untouched | ||
# (binary is a macro for -text -diff) | ||
*.class binary | ||
*.dll binary | ||
*.ear binary | ||
*.gif binary | ||
*.ico binary | ||
*.jar binary | ||
*.jpg binary | ||
*.jpeg binary | ||
*.png binary | ||
*.so binary | ||
*.war binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# OCaml output files | ||
*.out | ||
*.exe | ||
*.cmi | ||
*.cmo | ||
|
||
# Dune output | ||
_build |
7 changes: 7 additions & 0 deletions
7
src/main/resources/templates/ocaml/exercise/src/assignment.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
let add a b = failwith "TODO add" | ||
|
||
let filter p xs = failwith "TODO filter" | ||
|
||
let starts_with haystack hay = failwith "TODO starts_with" | ||
|
||
let starts_with2 haystack hay = failwith "TODO starts_with2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Arithemtic, Lists and Using Libraries | ||
|
||
In this exercise, you will use basic features of the OCaml programming language for arithemtic, list and string operations. | ||
|
||
1. [task][add](test suite for sum:0:add 0 0,test suite for sum:1:add 2 1) | ||
Implement the function `add` that takes two values of type `int` and returns their sum. | ||
|
||
2. [task][filter](test suite for sum:2:filter even [1;2]) | ||
Implement the generic and recursive function `filter` that that takes a predicate of type `'a -> bool` and a list of type `'a list`. The function should return the list of elements contained in the input list that fulfill the predicate. The elements in the returned list must appear in the same order as in the input list. | ||
|
||
3. [task][starts_with](test suite for sum:4:starts_with false, test suite for sum:3:starts_with true) | ||
Implement the function `starts_with` that takes two `string`s and returns `true` if, and only if, the second string is a prefix of the first. Use the appropriate library function provided by the `BatString` module from the "batteries" library. | ||
|
||
3. [task][starts_with2](test suite for sum:5:starts_with2 true , test suite for sum:6:starts_with2 false) | ||
Implement the function `starts_with2` which has the same specification as `starts_with`, but now, use the appropriate library function provided by the `Base.String` module from the "core" library. |
42 changes: 42 additions & 0 deletions
42
src/main/resources/templates/ocaml/solution/git.attributes.file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Handle line endings automatically for files detected as text | ||
# and leave all files detected as binary untouched. | ||
* text=auto | ||
|
||
# | ||
# The above will handle all files NOT found below | ||
# | ||
# These files are text and should be normalized (Convert crlf => lf) | ||
*.bash text eol=lf | ||
*.css text diff=css | ||
*.df text | ||
*.htm text diff=html | ||
*.html text diff=html | ||
*.hs text | ||
*.java text diff=java | ||
*.js text | ||
*.json text | ||
*.jsp text | ||
*.jspf text | ||
*.jspx text | ||
*.properties text | ||
*.sh text eol=lf | ||
*.tld text | ||
*.txt text | ||
*.tag text | ||
*.tagx text | ||
*.xml text | ||
*.yml text | ||
|
||
# These files are binary and should be left untouched | ||
# (binary is a macro for -text -diff) | ||
*.class binary | ||
*.dll binary | ||
*.ear binary | ||
*.gif binary | ||
*.ico binary | ||
*.jar binary | ||
*.jpg binary | ||
*.jpeg binary | ||
*.png binary | ||
*.so binary | ||
*.war binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# OCaml output files | ||
*.out | ||
*.exe | ||
*.cmi | ||
*.cmo | ||
|
||
# Dune output | ||
_build |
9 changes: 9 additions & 0 deletions
9
src/main/resources/templates/ocaml/solution/src/assignment.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
let add a b = a + b | ||
|
||
let rec filter p = function | ||
| [] -> [] | ||
| a :: t -> if p a then a :: (filter p t) else filter p t | ||
|
||
let starts_with = BatString.starts_with | ||
|
||
let starts_with2 haysteck hay = Base.String.is_prefix haysteck ~prefix:hay |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
B _build | ||
PKG oUnit | ||
PKG batteries | ||
PKG core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(include_subdirs unqualified) | ||
|
||
(test | ||
(name test) | ||
(flags (:standard -warn-error -A)) | ||
(libraries ounit2 batteries core) | ||
;;; results will appear in _build/results.xml | ||
(action (run %{test} -output-junit-file "../results.xml")) | ||
) |
42 changes: 42 additions & 0 deletions
42
src/main/resources/templates/ocaml/test/git.attributes.file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Handle line endings automatically for files detected as text | ||
# and leave all files detected as binary untouched. | ||
* text=auto | ||
|
||
# | ||
# The above will handle all files NOT found below | ||
# | ||
# These files are text and should be normalized (Convert crlf => lf) | ||
*.bash text eol=lf | ||
*.css text diff=css | ||
*.df text | ||
*.htm text diff=html | ||
*.html text diff=html | ||
*.hs text | ||
*.java text diff=java | ||
*.js text | ||
*.json text | ||
*.jsp text | ||
*.jspf text | ||
*.jspx text | ||
*.properties text | ||
*.sh text eol=lf | ||
*.tld text | ||
*.txt text | ||
*.tag text | ||
*.tagx text | ||
*.xml text | ||
*.yml text | ||
|
||
# These files are binary and should be left untouched | ||
# (binary is a macro for -text -diff) | ||
*.class binary | ||
*.dll binary | ||
*.ear binary | ||
*.gif binary | ||
*.ico binary | ||
*.jar binary | ||
*.jpg binary | ||
*.jpeg binary | ||
*.png binary | ||
*.so binary | ||
*.war binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
dune-project | ||
test-reports | ||
_build | ||
*.exe | ||
*.cmi | ||
*.cmo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
OUTPUT_FOLDER="test-reports" | ||
|
||
eval $(opam env) | ||
|
||
if [ ! -d "$OUTPUT_FOLDER" ]; then | ||
mkdir $OUTPUT_FOLDER | ||
fi | ||
(dune runtest --build-dir=$OUTPUT_FOLDER || exit 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
open OUnit2 | ||
open Assignment | ||
|
||
let even i = i mod 2 == 0 | ||
|
||
let tests = "test suite for sum" >::: [ | ||
(* Test add, use string_of_int for output in failur case *) | ||
"add 0 0" >:: (fun _ -> assert_equal 0 (add 0 0) ~printer:string_of_int); | ||
"add 2 1" >:: (fun _ -> assert_equal 3 (add 2 1) ~printer:string_of_int); | ||
"filter even [1;2]" >:: (fun _ -> assert_equal [2] (filter even [1;2])); | ||
"starts_with true" >:: (fun _ -> assert_bool "starts_with should return true" (starts_with "hallo" "hal")); | ||
"starts_with false" >:: (fun _ -> assert_bool "starts_with should return false" (not (starts_with "hallo" "allo"))); | ||
"starts_with2 true " >:: (fun _ -> assert_bool "starts_with2 should return true" (starts_with2 "hallo" "hal")); | ||
"starts_with2 false" >:: (fun _ -> assert_bool "starts_with2 should return false" (not (starts_with2 "hallo" "allo"))); | ||
] | ||
|
||
let _ = | ||
run_test_tt_main tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.