summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtestapp/c_cpp_files/main_blackJack.cpp41
-rwxr-xr-xtestapp/c_cpp_files/main_lessThan9.cpp38
-rw-r--r--testapp/exam/forms.py2
-rw-r--r--testapp/exam/models.py4
-rw-r--r--testapp/exam/urls.py4
-rw-r--r--testapp/exam/views.py85
-rw-r--r--testapp/java_files/main_lastDigit.java36
-rw-r--r--testapp/java_files/main_moreThan30.java36
-rw-r--r--testapp/java_files/main_palindrome.java4
-rw-r--r--testapp/static/exam/js/add_question.js5
-rw-r--r--testapp/static/exam/js/edit_question.js2
11 files changed, 211 insertions, 46 deletions
diff --git a/testapp/c_cpp_files/main_blackJack.cpp b/testapp/c_cpp_files/main_blackJack.cpp
new file mode 100755
index 0000000..e4f0963
--- /dev/null
+++ b/testapp/c_cpp_files/main_blackJack.cpp
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+extern int blackJack(int, int);
+
+template <class T>
+
+void check(T expect, T result)
+{
+ if (expect == result)
+ {
+ printf("\nCorrect:\n Expected %d got %d \n",expect,result);
+ }
+ else
+ {
+ printf("\nIncorrect:\n Expected %d got %d \n",expect,result);
+ exit (1);
+ }
+}
+
+int main(void)
+{
+ int result;
+ result = blackJack(11, 12);
+ printf("Input submitted to the function: 11, 12");
+ check(12, result);
+ result = blackJack(15, 19);
+ printf("Input submitted to the function: 15, 19");
+ check(19, result);
+ result = blackJack(10, 21);
+ printf("Input submitted to the function: 10, 21");
+ check(21, result);
+ result = blackJack(31, 22);
+ printf("Input submitted to the function: 31, 22");
+ check(0, result);
+ result = blackJack(91, 61);
+ printf("Input submitted to the function: 91, 61");
+ check(0, result);
+ printf("All Correct\n");
+ return 0;
+}
diff --git a/testapp/c_cpp_files/main_lessThan9.cpp b/testapp/c_cpp_files/main_lessThan9.cpp
new file mode 100755
index 0000000..1a89731
--- /dev/null
+++ b/testapp/c_cpp_files/main_lessThan9.cpp
@@ -0,0 +1,38 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+extern bool lessThan9(int);
+
+template <class T>
+
+void check(T expect, T result)
+{
+ if (expect == result)
+ {
+ printf("\nCorrect:\n Expected %d got %d \n",expect,result);
+ }
+ else
+ {
+ printf("\nIncorrect:\n Expected %d got %d \n",expect,result);
+ exit (1);
+ }
+}
+
+int main(void)
+{
+ bool result;
+ result = lessThan9(10);
+ printf("Input submitted to the function: 10");
+ check(false, result);
+ result = lessThan9(17);
+ printf("Input submitted to the function: 17");
+ check(true, result);
+ result = lessThan9(16);
+ printf("Input submitted to the function: 16");
+ check(true, result);
+ result = lessThan9(15);
+ printf("Input submitted to the function: 15");
+ check(false, result);
+ printf("All Correct\n");
+ return 0;
+}
diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py
index 8506de2..917bea7 100644
--- a/testapp/exam/forms.py
+++ b/testapp/exam/forms.py
@@ -167,6 +167,7 @@ class QuestionForm(forms.Form):
options = self.cleaned_data['options']
type = self.cleaned_data["type"]
active = self.cleaned_data["active"]
+ snippet = self.cleaned_data["snippet"]
new_question = Question()
new_question.summary = summary
@@ -176,4 +177,5 @@ class QuestionForm(forms.Form):
new_question.options = options
new_question.type = type
new_question.active = active
+ new_question.snippet = snippet
new_question.save()
diff --git a/testapp/exam/models.py b/testapp/exam/models.py
index 2aa02c9..babde0f 100644
--- a/testapp/exam/models.py
+++ b/testapp/exam/models.py
@@ -67,7 +67,7 @@ class Answer(models.Model):
question = models.ForeignKey(Question)
# The answer submitted by the user.
- answer = models.TextField()
+ answer = models.TextField(null=True, blank=True)
# Error message when auto-checking the answer.
error = models.TextField()
@@ -120,7 +120,7 @@ class QuestionPaper(models.Model):
################################################################################
class AnswerPaper(models.Model):
- """A question paper for a student -- one per student typically.
+ """A answer paper for a student -- one per student typically.
"""
# The user taking this question paper.
user = models.ForeignKey(User)
diff --git a/testapp/exam/urls.py b/testapp/exam/urls.py
index b3cfceb..14aaa8a 100644
--- a/testapp/exam/urls.py
+++ b/testapp/exam/urls.py
@@ -7,10 +7,10 @@ urlpatterns = patterns('exam.views',
url(r'^results/$','results_user'),
url(r'^start/$', 'start'),
url(r'^start/(?P<questionpaper_id>\d+)/$','start'),
- url(r'^quit/(?P<answerpaper_id>\d+)/$', 'quit'),
+ url(r'^quit/(?P<questionpaper_id>\d+)/$', 'quit'),
url(r'^intro/$','start'),
url(r'^complete/$', 'complete'),
- url(r'^complete/(?P<answerpaper_id>\d+)/$', 'complete'),
+ url(r'^complete/(?P<questionpaper_id>\d+)/$', 'complete'),
url(r'^register/$', 'user_register'),
url(r'^(?P<q_id>\d+)/$', 'question'),
url(r'^(?P<q_id>\d+)/check/$', 'check'),
diff --git a/testapp/exam/views.py b/testapp/exam/views.py
index 55ccd38..2545d8b 100644
--- a/testapp/exam/views.py
+++ b/testapp/exam/views.py
@@ -627,7 +627,7 @@ def start(request, questionpaper_id=None):
except QuestionPaper.DoesNotExist:
msg = 'Quiz not found, please contact your '\
'instructor/administrator. Please login again thereafter.'
- return complete(request, reason=msg)
+ return complete(request, msg, questionpaper_id)
try:
old_paper = AnswerPaper.objects.get(\
@@ -678,7 +678,8 @@ def question(request, q_id, questionpaper_id,success_msg=None):
except AnswerPaper.DoesNotExist:
return my_redirect('/exam/start/')
if not paper.question_paper.quiz.active:
- return complete(request, reason='The quiz has been deactivated!')
+ reason='The quiz has been deactivated!'
+ return complete(request, reason, questionpaper_id)
time_left = paper.time_left()
if time_left == 0:
@@ -700,12 +701,11 @@ def question(request, q_id, questionpaper_id,success_msg=None):
context_instance=ci)
-def show_question(request, q_id, questionpaper_id,success_msg=None,
- answerpaper_id=None):
+def show_question(request, q_id, questionpaper_id,success_msg=None):
"""Show a question if possible."""
if len(q_id) == 0:
msg = 'Congratulations! You have successfully completed the quiz.'
- return complete(request, msg,answerpaper_id)
+ return complete(request, msg,questionpaper_id)
else:
return question(request, q_id, questionpaper_id,success_msg)
@@ -722,16 +722,21 @@ def check(request, q_id, questionpaper_id=None):
snippet_code = request.POST.get('snippet')
user_answer = request.POST.get('answer')
skip = request.POST.get('skip', None)
+ success_msg = False
+ success = True
if skip is not None:
next_q = paper.skip()
return show_question(request, next_q, questionpaper_id)
if question.type == 'mcq':
# Add the answer submitted, regardless of it being correct or not.
- new_answer = Answer(question=question, answer=user_answer,
- correct=False)
- new_answer.save()
- paper.answers.add(new_answer)
+ if user_answer is not None :
+ print "EEERRRROOOORRRRRRR :P"
+ new_answer = Answer(question=question, answer=user_answer,
+ correct=False)
+ new_answer.save()
+ paper.answers.add(new_answer)
+
else:
"""Add the answer submitted with the Snippet code,
regardless of it being correct or not."""
@@ -745,13 +750,16 @@ def check(request, q_id, questionpaper_id=None):
# questions, we obtain the results via XML-RPC with the code executed
# safely in a separate process (the code_server.py) running as nobody.
if question.type == 'mcq':
- success = True # Only one attempt allowed for MCQ's.
- if user_answer.strip() == question.test.strip():
- new_answer.correct = True
- new_answer.marks = question.points
- new_answer.error = 'Correct answer'
- else:
- new_answer.error = 'Incorrect answer'
+ if user_answer is not None:
+ success = True # Only one attempt allowed for MCQ's.
+ if user_answer.strip() == question.test.strip():
+ new_answer.correct = True
+ new_answer.marks = question.points
+ new_answer.error = 'Correct answer'
+ success_msg = True
+ else:
+ new_answer.error = 'Incorrect answer'
+ new_answer.save()
else:
user_dir = get_user_dir(user)
success, err_msg = code_server.run_code(answer_check, question.test,
@@ -761,15 +769,17 @@ def check(request, q_id, questionpaper_id=None):
# Note the success and save it along with the marks.
new_answer.correct = success
new_answer.marks = question.points
+ success_msg = True
+ new_answer.save()
- new_answer.save()
-
+ time_left = paper.time_left()
if not success: # Should only happen for non-mcq questions.
- time_left = paper.time_left()
if time_left == 0:
- return complete(request, reason='Your time is up!')
+ reason='Your time is up!'
+ return complete(request, reason, questionpaper_id)
if not paper.question_paper.quiz.active:
- return complete(request, reason='The quiz has been deactivated!')
+ reason='The quiz has been deactivated!'
+ return complete(request, reason, questionpaper_id)
context = {'question': question, 'error_message': err_msg,
'paper': paper, 'last_attempt': user_answer,
'quiz_name': paper.question_paper.quiz.description,
@@ -779,32 +789,39 @@ def check(request, q_id, questionpaper_id=None):
return my_render_to_response('exam/question.html', context,
context_instance=ci)
else:
- next_q = paper.completed_question(question.id)
- success_msg = True
- return show_question(request, next_q, questionpaper_id,success_msg,
- paper.id)
+ if time_left <= 0:
+ print "success"
+ print str(time_left)
+ reason='Your time is up!'
+ return complete(request, reason, questionpaper_id)
+ else:
+ print "fail"
+ print time_left
+ next_q = paper.completed_question(question.id)
+ return show_question(request, next_q, questionpaper_id,success_msg)
-def quit(request, answerpaper_id=None):
+def quit(request, questionpaper_id=None):
"""Show the quit page when the user logs out."""
- context = {'id': answerpaper_id}
+ context = {'id': questionpaper_id}
return my_render_to_response('exam/quit.html', context,
context_instance=RequestContext(request))
-def complete(request, reason=None, answerpaper_id=None):
+def complete(request, reason=None, questionpaper_id=None):
"""Show a page to inform user that the quiz has been compeleted."""
user = request.user
- if answerpaper_id is None:
+ if questionpaper_id is None:
logout(request)
- context = {'message': "You are successfully Logged out."}
+ message = reason or "You are successfully logged out."
+ context = {'message': message}
return my_render_to_response('exam/complete.html', context)
else:
- paper = AnswerPaper.objects.get(id=answerpaper_id)
+ q_paper = QuestionPaper.objects.get(id=questionpaper_id)
+ paper = AnswerPaper.objects.get(user=user, question_paper=q_paper)
obt_marks = paper.get_total_marks()
tot_marks = paper.question_paper.total_marks
- print tot_marks
if obt_marks == paper.question_paper.total_marks:
context = {'message': "Hurray ! You did an excellent job.\
you answered all the questions correctly.\
@@ -813,7 +830,8 @@ def complete(request, reason=None, answerpaper_id=None):
logout(request)
return my_render_to_response('exam/complete.html',context)
else:
- context = {'message': reason}
+ message = reason or "You are successfully logged out"
+ context = {'message': message }
logout(request)
return my_render_to_response('exam/complete.html',context)
no = False
@@ -991,6 +1009,7 @@ def show_all_questions(request):
form.initial['options'] = d.options
form.initial['type'] = d.type
form.initial['active'] = d.active
+ form.initial['snippet'] = d.snippet
form_tags = d.tags.all()
form_tags_split = form_tags.values('name')
initial_tags = ""
diff --git a/testapp/java_files/main_lastDigit.java b/testapp/java_files/main_lastDigit.java
new file mode 100644
index 0000000..05439e2
--- /dev/null
+++ b/testapp/java_files/main_lastDigit.java
@@ -0,0 +1,36 @@
+class main_lastDigit
+{
+ public static <E> void check(E expect, E result)
+ {
+ if(result.equals(expect))
+ {
+ System.out.println("Correct:\nOutput expected "+expect+" and got "+result+"\n");
+ }
+ else
+ {
+ System.out.println("Incorrect:\nOutput expected "+expect+" but got "+result+"\n");
+ System.exit(1);
+ }
+ }
+ public static void main(String arg[])
+ {
+ Test t = new Test();
+ boolean result;
+ result= t.lastDigit(12, 2, 13);
+ System.out.println("Input submitted to the function: 12, 2, 13");
+ check(true, result);
+ result = t.lastDigit(11, 52, 32);
+ System.out.println("Input submitted to the function: 11, 52, 32");
+ check(true, result);
+ result = t.lastDigit(6, 34, 22);
+ System.out.println("Input submitted to the function: 6, 34, 22");
+ check(false, result);
+ result = t.lastDigit(6, 46, 26);
+ System.out.println("Input submitted to the function: 63");
+ check(true, result);
+ result = t.lastDigit(91, 90, 92);
+ System.out.println("Input submitted to the function: 91");
+ check(false, result);
+
+ }
+}
diff --git a/testapp/java_files/main_moreThan30.java b/testapp/java_files/main_moreThan30.java
new file mode 100644
index 0000000..7da31cb
--- /dev/null
+++ b/testapp/java_files/main_moreThan30.java
@@ -0,0 +1,36 @@
+class main_moreThan30
+{
+ public static <E> void check(E expect, E result)
+ {
+ if(result.equals(expect))
+ {
+ System.out.println("Correct:\nOutput expected "+expect+" and got "+result+"\n");
+ }
+ else
+ {
+ System.out.println("Incorrect:\nOutput expected "+expect+" but got "+result+"\n");
+ System.exit(1);
+ }
+ }
+ public static void main(String arg[])
+ {
+ Test t = new Test();
+ boolean result;
+ result= t.moreThan30(30);
+ System.out.println("Input submitted to the function: 30");
+ check(false, result);
+ result = t.moreThan30(151);
+ System.out.println("Input submitted to the function: 151");
+ check(true, result);
+ result = t.moreThan30(66);
+ System.out.println("Input submitted to the function: 66");
+ check(false, result);
+ result = t.moreThan30(63);
+ System.out.println("Input submitted to the function: 63");
+ check(true, result);
+ result = t.moreThan30(91);
+ System.out.println("Input submitted to the function: 91");
+ check(true, result);
+
+ }
+}
diff --git a/testapp/java_files/main_palindrome.java b/testapp/java_files/main_palindrome.java
index bd463e5..c0745f9 100644
--- a/testapp/java_files/main_palindrome.java
+++ b/testapp/java_files/main_palindrome.java
@@ -4,11 +4,11 @@ class main_palindrome
{
if(result.equals(expect))
{
- System.out.println("Correct\n:Output expected "+expect+" and got "+result);
+ System.out.println("Correct:\nOutput expected "+expect+" and got "+result+"\n");
}
else
{
- System.out.println("Incorrect:\nOutput expected "+expect+" but got "+result);
+ System.out.println("Incorrect:\nOutput expected "+expect+" but got "+result+"\n");
System.exit(1);
}
}
diff --git a/testapp/static/exam/js/add_question.js b/testapp/static/exam/js/add_question.js
index e001ee7..ba17492 100644
--- a/testapp/static/exam/js/add_question.js
+++ b/testapp/static/exam/js/add_question.js
@@ -77,10 +77,6 @@ function textareaformat()
document.getElementById('id_points').setAttribute('class','mini-text');
document.getElementById('id_tags').setAttribute('class','tag-text');
- jQuery().ready(function()
- {
- $("#id_snippet").val("#To avoid indentation errors use tabs for indentation for Python questions");
- });
$('#id_snippet').bind('keydown', function( event ){
if(navigator.userAgent.match("Gecko"))
@@ -135,7 +131,6 @@ function textareaformat()
$('#id_snippet').bind('focus', function( event ){
document.getElementById("id_snippet").rows=5;
document.getElementById("id_snippet").cols=40;
- $('#id_snippet').val("");
});
$('#id_snippet').bind('blur', function( event ){
document.getElementById("id_snippet").rows=1;
diff --git a/testapp/static/exam/js/edit_question.js b/testapp/static/exam/js/edit_question.js
index a5d4e2b..28d95f9 100644
--- a/testapp/static/exam/js/edit_question.js
+++ b/testapp/static/exam/js/edit_question.js
@@ -152,7 +152,6 @@ function textareaformat()
var snippet_id = document.getElementById('id_snippet'+i);
$(snippet_id).bind('focus',function(event){
this.rows = 5;
- $(snippet_id).val("");
});
$(snippet_id).bind('keydown', function (event){
catchTab(snippet_id,event);
@@ -170,7 +169,6 @@ function textareaformat()
jQuery().ready(function()
{
jQuery("#id_tags" + i).autocomplete("/taggit_autocomplete_modified/json", { multiple: true });
- $(snippet_id).val("#To avoid indentation errors use tab for indentation for Python questions");
});
}
}