summaryrefslogtreecommitdiff
path: root/testapp/exam
diff options
context:
space:
mode:
Diffstat (limited to 'testapp/exam')
-rw-r--r--testapp/exam/bash_code_evaluator.py (renamed from testapp/exam/evaluators/bash_code_evaluator.py)0
-rw-r--r--testapp/exam/code_evaluator.py (renamed from testapp/exam/evaluators/code_evaluator.py)0
-rwxr-xr-xtestapp/exam/code_server.py2
-rw-r--r--testapp/exam/cpp_code_evaluator.py (renamed from testapp/exam/evaluators/cpp_code_evaluator.py)0
-rw-r--r--testapp/exam/docs/sample.args2
-rwxr-xr-xtestapp/exam/docs/sample.sh2
-rw-r--r--testapp/exam/docs/sample_questions.py84
-rw-r--r--testapp/exam/docs/sample_questions.xml43
-rw-r--r--testapp/exam/evaluators/__init__.py0
-rw-r--r--testapp/exam/forms.py4
-rw-r--r--testapp/exam/java_code_evaluator.py (renamed from testapp/exam/evaluators/java_code_evaluator.py)0
-rw-r--r--testapp/exam/language_registry.py (renamed from testapp/exam/evaluators/language_registry.py)0
-rw-r--r--testapp/exam/models.py5
-rw-r--r--testapp/exam/python_code_evaluator.py (renamed from testapp/exam/evaluators/python_code_evaluator.py)0
-rw-r--r--testapp/exam/scilab_code_evaluator.py (renamed from testapp/exam/evaluators/scilab_code_evaluator.py)0
-rw-r--r--testapp/exam/settings.py12
-rw-r--r--testapp/exam/tests.py29
17 files changed, 162 insertions, 21 deletions
diff --git a/testapp/exam/evaluators/bash_code_evaluator.py b/testapp/exam/bash_code_evaluator.py
index a468fd7..a468fd7 100644
--- a/testapp/exam/evaluators/bash_code_evaluator.py
+++ b/testapp/exam/bash_code_evaluator.py
diff --git a/testapp/exam/evaluators/code_evaluator.py b/testapp/exam/code_evaluator.py
index 381b2e8..381b2e8 100644
--- a/testapp/exam/evaluators/code_evaluator.py
+++ b/testapp/exam/code_evaluator.py
diff --git a/testapp/exam/code_server.py b/testapp/exam/code_server.py
index 7c675cb..8f53425 100755
--- a/testapp/exam/code_server.py
+++ b/testapp/exam/code_server.py
@@ -31,7 +31,7 @@ import re
import json
# Local imports.
from settings import SERVER_PORTS, SERVER_POOL_PORT
-from evaluators.language_registry import get_registry, set_registry
+from language_registry import set_registry, get_registry
MY_DIR = abspath(dirname(__file__))
diff --git a/testapp/exam/evaluators/cpp_code_evaluator.py b/testapp/exam/cpp_code_evaluator.py
index 7242884..7242884 100644
--- a/testapp/exam/evaluators/cpp_code_evaluator.py
+++ b/testapp/exam/cpp_code_evaluator.py
diff --git a/testapp/exam/docs/sample.args b/testapp/exam/docs/sample.args
new file mode 100644
index 0000000..4d9f00d
--- /dev/null
+++ b/testapp/exam/docs/sample.args
@@ -0,0 +1,2 @@
+1 2
+2 1
diff --git a/testapp/exam/docs/sample.sh b/testapp/exam/docs/sample.sh
new file mode 100755
index 0000000..e935cb3
--- /dev/null
+++ b/testapp/exam/docs/sample.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+[[ $# -eq 2 ]] && echo $(( $1 + $2 )) && exit $(( $1 + $2 ))
diff --git a/testapp/exam/docs/sample_questions.py b/testapp/exam/docs/sample_questions.py
new file mode 100644
index 0000000..60f32cb
--- /dev/null
+++ b/testapp/exam/docs/sample_questions.py
@@ -0,0 +1,84 @@
+from datetime import date
+
+questions = [
+[Question(
+ summary='Factorial',
+ points=2,
+ language='python',
+ type='code',
+ description='''
+Write a function called <code>fact</code> which takes a single integer argument
+(say <code>n</code>) and returns the factorial of the number.
+For example:<br/>
+<code>fact(3) -> 6</code>
+''',
+ test='''
+assert fact(0) == 1
+assert fact(5) == 120
+''',
+ snippet="def fact(num):"
+ ),
+#Add tags here as a list of string.
+['Python','function','factorial'],
+],
+
+[Question(
+ summary='Simple function',
+ points=1,
+ language='python',
+ type='code',
+ description='''Create a simple function called <code>sqr</code> which takes a single
+argument and returns the square of the argument. For example: <br/>
+<code>sqr(3) -> 9</code>.''',
+ test='''
+import math
+assert sqr(3) == 9
+assert abs(sqr(math.sqrt(2)) - 2.0) < 1e-14
+ ''',
+ snippet="def sqr(num):"
+ ),
+#Add tags here as a list of string.
+['Python','function'],
+],
+
+[Question(
+ summary='Bash addition',
+ points=2,
+ language='bash',
+ type='code',
+ description='''Write a shell script which takes two arguments on the
+ command line and prints the sum of the two on the output.''',
+ test='''\
+docs/sample.sh
+docs/sample.args
+''',
+ snippet="#!/bin/bash"
+ ),
+#Add tags here as a list of string.
+[''],
+],
+
+[Question(
+ summary='Size of integer in Python',
+ points=0.5,
+ language='python',
+ type='mcq',
+ description='''What is the largest integer value that can be represented
+in Python?''',
+ options='''No Limit
+2**32
+2**32 - 1
+None of the above
+''',
+ test = "No Limit"
+ ),
+#Add tags here as a list of string.
+['mcq'],
+],
+
+] #list of questions ends here
+
+quiz = Quiz(start_date=date.today(),
+ duration=10,
+ description='Basic Python Quiz 1'
+ )
diff --git a/testapp/exam/docs/sample_questions.xml b/testapp/exam/docs/sample_questions.xml
new file mode 100644
index 0000000..53c76f8
--- /dev/null
+++ b/testapp/exam/docs/sample_questions.xml
@@ -0,0 +1,43 @@
+<question_bank>
+
+<question>
+<summary>
+Factorial
+</summary>
+<description>
+Write a function called "fact" which takes a single integer argument (say "n")
+and returns the factorial of the number.
+For example fact(3) -> 6
+</description>
+<points>2</points>
+<type>python</type>
+<test>
+assert fact(0) == 1
+assert fact(5) == 120
+</test>
+<options>
+</options>
+</question>
+
+<question>
+<summary>
+Simple function
+</summary>
+<description>
+Create a simple function called "sqr" which takes a single argument and
+returns the square of the argument
+For example sqr(3) -> 9.
+</description>
+<points>1</points>
+<type>python</type>
+<test>
+import math
+assert sqr(3) == 9
+assert abs(sqr(math.sqrt(2)) - 2.0) &lt; 1e-14
+</test>
+<options>
+</options>
+</question>
+
+
+</question_bank>
diff --git a/testapp/exam/evaluators/__init__.py b/testapp/exam/evaluators/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/testapp/exam/evaluators/__init__.py
+++ /dev/null
diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py
index b56e545..b7625be 100644
--- a/testapp/exam/forms.py
+++ b/testapp/exam/forms.py
@@ -17,8 +17,8 @@ languages = (
("select", "Select Language"),
("python", "Python"),
("bash", "Bash"),
- ("C", "C Language"),
- ("C++", "C++ Language"),
+ ("c", "C Language"),
+ ("cpp", "C++ Language"),
("java", "Java Language"),
("scilab", "Scilab"),
)
diff --git a/testapp/exam/evaluators/java_code_evaluator.py b/testapp/exam/java_code_evaluator.py
index 4367259..4367259 100644
--- a/testapp/exam/evaluators/java_code_evaluator.py
+++ b/testapp/exam/java_code_evaluator.py
diff --git a/testapp/exam/evaluators/language_registry.py b/testapp/exam/language_registry.py
index 76a23d7..76a23d7 100644
--- a/testapp/exam/evaluators/language_registry.py
+++ b/testapp/exam/language_registry.py
diff --git a/testapp/exam/models.py b/testapp/exam/models.py
index e5a51af..1e1fbea 100644
--- a/testapp/exam/models.py
+++ b/testapp/exam/models.py
@@ -329,10 +329,7 @@ class AnswerPaper(models.Model):
def questions_left(self):
"""Returns the number of questions left."""
qu = self.get_unanswered_questions()
- if len(qu) == 0:
- return 0
- else:
- return qu.count('|') + 1
+ return len(qu)
def get_unanswered_questions(self):
"""Returns the list of unanswered questions."""
diff --git a/testapp/exam/evaluators/python_code_evaluator.py b/testapp/exam/python_code_evaluator.py
index 0c473cf..0c473cf 100644
--- a/testapp/exam/evaluators/python_code_evaluator.py
+++ b/testapp/exam/python_code_evaluator.py
diff --git a/testapp/exam/evaluators/scilab_code_evaluator.py b/testapp/exam/scilab_code_evaluator.py
index 392cd45..392cd45 100644
--- a/testapp/exam/evaluators/scilab_code_evaluator.py
+++ b/testapp/exam/scilab_code_evaluator.py
diff --git a/testapp/exam/settings.py b/testapp/exam/settings.py
index 5d3fb15..55c82dc 100644
--- a/testapp/exam/settings.py
+++ b/testapp/exam/settings.py
@@ -20,10 +20,10 @@ SERVER_TIMEOUT = 2
URL_ROOT = ''
code_evaluators = {
- "python": "evaluators.python_code_evaluator.PythonCodeEvaluator",
- "c": "evaluators.c_cpp_code_evaluator.CCPPCodeEvaluator",
- "cpp": "evaluators.c_cpp_code_evaluator.CCPPCodeEvaluator",
- "java": "evaluators.java_evaluator.JavaCodeEvaluator",
- "bash": "evaluators.bash_evaluator.BashCodeEvaluator",
- "scilab": "evaluators.scilab_evaluator.ScilabCodeEvaluator",
+ "python": "python_code_evaluator.PythonCodeEvaluator",
+ "c": "c_cpp_code_evaluator.CCPPCodeEvaluator",
+ "cpp": "c_cpp_code_evaluator.CCPPCodeEvaluator",
+ "java": "java_code_evaluator.JavaCodeEvaluator",
+ "bash": "bash_code_evaluator.BashCodeEvaluator",
+ "scilab": "scilab_code_evaluator.ScilabCodeEvaluator",
}
diff --git a/testapp/exam/tests.py b/testapp/exam/tests.py
index 7a8d30c..cd84874 100644
--- a/testapp/exam/tests.py
+++ b/testapp/exam/tests.py
@@ -20,6 +20,7 @@ def setUpModule():
# create a quiz
Quiz.objects.create(start_date='2014-06-16', duration=30, active=False,
+ attempts_allowed=-1, time_between_attempts=0,
description='demo quiz', pass_criteria=40,
language='Python', prerequisite=None)
@@ -60,10 +61,11 @@ class QuestionTestCases(unittest.TestCase):
snippet='def myfunc()')
self.question.save()
self.question.tags.add('python', 'function')
- self.testcase = TestCase(question=self.question,
+ self.testcase = TestCase(question=self.question,
func_name='def myfunc', kw_args='a=10,b=11',
pos_args='12,13', expected_answer='15')
- answer_data = {"user_answer": "demo_answer",
+ answer_data = { "test": "",
+ "user_answer": "demo_answer",
"test_parameter": [{"func_name": "def myfunc",
"expected_answer": "15",
"test_id": self.testcase.id,
@@ -71,8 +73,9 @@ class QuestionTestCases(unittest.TestCase):
"kw_args": {"a": "10",
"b": "11"}
}],
- "id": self.question.id,
- "language": "Python"}
+ "id": self.question.id,
+ "ref_code_path": "",
+ }
self.answer_data_json = json.dumps(answer_data)
self.user_answer = "demo_answer"
@@ -180,6 +183,9 @@ class QuestionPaperTestCases(unittest.TestCase):
self.user = User.objects.get(pk=1)
+ self.attempted_papers = AnswerPaper.objects.filter(question_paper=self.question_paper,
+ user=self.user)
+
def test_questionpaper(self):
""" Test question paper"""
self.assertEqual(self.question_paper.quiz.description, 'demo quiz')
@@ -228,7 +234,10 @@ class QuestionPaperTestCases(unittest.TestCase):
def test_make_answerpaper(self):
""" Test make_answerpaper() method of Question Paper"""
- answerpaper = self.question_paper.make_answerpaper(self.user, self.ip)
+ already_attempted = self.attempted_papers.count()
+ attempt_num = already_attempted + 1
+ answerpaper = self.question_paper.make_answerpaper(self.user, self.ip,
+ attempt_num)
self.assertIsInstance(answerpaper, AnswerPaper)
paper_questions = set((answerpaper.questions).split('|'))
self.assertEqual(len(paper_questions), 7)
@@ -249,13 +258,17 @@ class AnswerPaperTestCases(unittest.TestCase):
self.question_paper.save()
# create answerpaper
- self.answerpaper = AnswerPaper(user=self.user, profile=self.profile,
+ self.answerpaper = AnswerPaper(user=self.user,
questions='1|2|3',
question_paper=self.question_paper,
start_time='2014-06-13 12:20:19.791297',
end_time='2014-06-13 12:50:19.791297',
user_ip=self.ip)
self.answerpaper.questions_answered = '1'
+ self.attempted_papers = AnswerPaper.objects.filter(question_paper=self.question_paper,
+ user=self.user)
+ already_attempted = self.attempted_papers.count()
+ self.answerpaper.attempt_number = already_attempted + 1
self.answerpaper.save()
# answers for the Answer Paper
@@ -271,7 +284,6 @@ class AnswerPaperTestCases(unittest.TestCase):
def test_answerpaper(self):
""" Test Answer Paper"""
self.assertEqual(self.answerpaper.user.username, 'demo_user')
- self.assertEqual(self.answerpaper.profile_id, 1)
self.assertEqual(self.answerpaper.user_ip, self.ip)
questions = self.answerpaper.questions
num_questions = len(questions.split('|'))
@@ -299,7 +311,8 @@ class AnswerPaperTestCases(unittest.TestCase):
def test_skip(self):
""" Test skip() method of Answer Paper"""
- next_question_id = self.answerpaper.skip()
+ current_question = self.answerpaper.current_question()
+ next_question_id = self.answerpaper.skip(current_question)
self.assertTrue(next_question_id is not None)
self.assertEqual(next_question_id, '3')