Following the approach from https://github.com/trampgeek/moodle-qtype_coderunner?tab=readme-ov-file#supporting-or-implementing-new-languages
More docs: https://hub.docker.com/r/trampgeek/jobeinabox/ https://github.com/trampgeek/jobeinabox
docker exec -it <container_id_or_name> bash
Search for the jobeinabox
container id
As per https://github.com/trampgeek/jobeinabox/blob/master/Dockerfile , the container is based on ubuntu:24.04, so installing Scala goes like this:
# install scala scalac
# check latest 2.x version: https://www.scala-lang.org/download/
sudo apt update
sudo apt install curl
export SCALA_VERSION=2.12.20
curl -fsSL https://downloads.lightbend.com/scala/${SCALA_VERSION}/scala-${SCALA_VERSION}.tgz | tar -xz -C /usr/local
ln -s /usr/local/scala-${SCALA_VERSION}/bin/scala /usr/bin/scala
ln -s /usr/local/scala-${SCALA_VERSION}/bin/scalac /usr/bin/scalac
# smoke test
cd
echo 'object HelloWorld extends App{println("yes :-)")}' > HelloWorld.scala
scalac HelloWorld.scala
scala HelloWorld
rm HelloWorld*
Following the approach from https://github.com/trampgeek/moodle-qtype_coderunner?tab=readme-ov-file#supporting-or-implementing-new-languages
- Create a new CodeRunner question.
- Choose the question type python3
- Click Customise
- Replace the contents of the Template text area with the template code below.
- Uncheck the Is combinator checkbox
- Enter TEMPLATE_QUESTION_scala_using_python as the question name
- Enter whatever text you wish to use to describe the question type in the Question text area. This text will be displayed to any authors using this new question type if they open the Question type details section of the question authoring form.
- Open Advanced Customisation
- Set Is prototype? to Yes (user defined)
- Set Question type to scala_via_python.
- Set Time limit to 15.
- Set Memory limit to 0.
- Set Run_spec parameters to { "memorylimit": 0, "cputime": 15 }.
- Set Ace language to scala, so that the students' code will be edited as Scala (syntax highlighting) even though the prototype is in Python.
- Save the question.
You should now find the new question type scala_via_python appearing in the Question type dropdown of the author edit form for a new CodeRunner question. This new question type should allow you to create questions in scala.
The full question prototype for the scala_via_python question type is included in this gist
- write a new CodeRunner question, select scala_via_python question type
- give it a name: Exercice 1: Array.reverse
- give it a question text: Reverse an array without using the reverse method
- as answer, give
def reverse(in: Array[Int]): Array[Int] = {
val result: Array[Int] = new Array[Int](in.length)
for (i <- in.indices) {
result(i) = in(in.length - 1 - i)
}
result
}
- as pre-filled answer, give
// Implement the reverse function marked with (???) below.
// You may NOT use the built-in reverse methode from Array
def reverse(in: Array[Int]): Array[Int] = ???
- as 1st testcase, set Test case 1 to:
// Test with 1,2,3
assert(reverse(Array(1, 2, 3)).sameElements(Array(3, 2, 1)), "Test reverse(Array(1, 2, 3)) failed")
- Leave the other fields from the testcase empty.
- Write more tests and save question
See https://coderunner.org.nz/mod/forum/discuss.php?d=722#p2961 for futher information
Quoting Richard Lobb :
The JVM is a notorious memory gobbler, and it's difficult to run it under Linux ulimit
memory restrictions, even without the complication of running it on top of Python.
Try simply setting the Jobe memory limit to 0, which turns off the ulimit on memory,
and removing all the memory limits on the scalac command. You should be able to trust
the JVM to manage memory itself, at least sufficiently to prevent the Jobe from thrashing.
You can add back JVM memory limits later if you have load problems on Jobe.
it's quite slow, so maybe group the tests?
{{ STUDENT_ANSWER }}
__student_answer__ = """{{ STUDENT_ANSWER | e('py') }}"""
SEPARATOR = "#<ab@17943918#@>#"
{% for TEST in TESTCASES %}
{{ TEST.testcode }}
{% if not loop.last %}
print(SEPARATOR)
{% endif %}
{% endfor %}