Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • tuhe/unitgrade_private
1 result
Show changes
Showing
with 251 additions and 45 deletions
# example_in_progress/in_progress.py
self.title = f"Checking if reverse_list({ls}) = {reverse}" # Programmatically set the title
def ex_test_output_capture(self):
with self.capture() as out:
print("hello world 42") # Genereate some output (i.e. in a homework script)
self.assertEqual(out.numbers[0], 42) # out.numbers is a list of all numbers generated
self.assertEqual(out.output, "hello world 42") # you can also access the raw output.
class Question2(UTestCase):
@cache
def my_reversal(self, ls):
# The '@cache' decorator ensures the function is not run on the *students* computer
# Instead the code is run on the teachers computer and the result is passed on with the
# other pre-computed results -- i.e. this function will run regardless of how the student happens to have
# implemented reverse_list.
return reverse_list(ls)
def test_reverse_tricky(self):
ls = (2,4,8)
ls2 = self.my_reversal(tuple(ls)) # This will always produce the right result, [8, 4, 2]
print("The correct answer is supposed to be", ls2) # Show students the correct answer
self.assertEqualC(reverse_list(ls)) # This will actually test the students code.
return "Buy world!" # This value will be stored in the .token file
\ No newline at end of file
# example_moss/moss_example.py
from unitgrade_private.plagiarism.mossit import moss_it, get_id
if __name__ == "__main__":
# Extract the moss id ("12415...") from the perl script and test:
id = get_id("../../../02465private/admin/moss.pl")
moss_it(whitelist_dir="whitelist", submissions_dir="student_submissions", moss_id=id)
\ No newline at end of file
(1,2) (1,2) (1,2)
(1,2) (2,2) (1,2)
(1,2) (1,2) (1,2)
(9,8) (2,-2) (2,-2)
(2,-2) (2,-2) (2,-2)
(2,-2) (2,-2) (9,8)
(10,10) (3,0) (3,0)
(3,0) (4,0) (3,0)
(3,0) (3,0) (10,10)
Result of scaling A by 2
(2,4) (2,4) (2,4)
(2,4) (4,4) (2,4)
(2,4) (2,4) (2,4)
......@@ -18,9 +18,4 @@ class Report1(Report):
pack_imports = [cs101] # Include all .py files in this folder
if __name__ == "__main__":
# from HtmlTestRunner import HTMLTestRunner
import HtmlTestRunner
unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='example_dir'))
# evaluate_report_student(Report1())
\ No newline at end of file
evaluate_report_student(Report1())
\ No newline at end of file
# example_simplest/instructor/cs101/report1.py
import unittest
from unitgrade import Report, evaluate_report_student
import cs101
from cs101.homework1 import reverse_list, add
class Week1(unittest.TestCase):
def test_add(self):
self.assertEqual(add(2,2), 4)
self.assertEqual(add(-100, 5), -95)
def test_reverse(self):
self.assertEqual(reverse_list([1,2,3]), [3,2,1])
class Report1(Report):
title = "CS 101 Report 1"
questions = [(Week1, 10)] # Include a single question for a total of 10 credits.
pack_imports = [cs101] # Include all .py files in this folder
if __name__ == "__main__":
evaluate_report_student(Report1())
\ No newline at end of file
# example_simplest/instructor/cs101/report1.py
from cs101.homework1 import reverse_list, add
class Week1(unittest.TestCase):
def test_add(self):
self.assertEqual(add(2,2), 4)
self.assertEqual(add(-100, 5), -95)
def test_reverse(self):
self.assertEqual(reverse_list([1,2,3]), [3,2,1])
\ No newline at end of file
# example_hints/instructor/cs106/report1hints.py
class Week1(UTestCase):
def test_find_all_primes(self):
"""
Hints:
* Insert a breakpoint and check what your function find_primes(4) actually outputs
"""
self.assertEqual(find_primes(4), [2, 3], msg="The list should only contain primes <= 4")
class Report1Hints(Report):
title = "CS 106 Report 1"
questions = [(Week1, 10)]
pack_imports = [homework_hints]
\ No newline at end of file
# example_framework/instructor/cs102/report2.py
from unitgrade import UTestCase, cache
class Week1(UTestCase):
@classmethod
def setUpClass(cls) -> None:
......@@ -12,5 +10,5 @@ class Week1(UTestCase):
self.assertEqualC(add(2,2))
self.assertEqualC(add(-100, 5))
# def test_reverse(self):
# self.assertEqualC(reverse_list([1, 2, 3]))
\ No newline at end of file
def test_reverse(self):
self.assertEqualC(reverse_list([1, 2, 3]))
\ No newline at end of file
# example_framework/instructor/cs102/report2.py
# class Week1Titles(UTestCase):
# """ The same problem as before with nicer titles """
# def test_add(self):
# """ Test the addition method add(a,b) """
# self.assertEqualC(add(2,2))
# print("output generated by test")
# self.assertEqualC(add(-100, 5))
# # self.assertEqual(2,3, msg="This test automatically fails.")
#
# def test_reverse(self):
# ls = [1, 2, 3]
# reverse = reverse_list(ls)
# self.assertEqualC(reverse)
# # Although the title is set after the test potentially fails, it will *always* show correctly for the student.
# self.title = f"Checking if reverse_list({ls}) = {reverse}" # Programmatically set the title
\ No newline at end of file
class Week1Titles(UTestCase):
""" The same problem as before with nicer titles """
def test_add(self):
""" Test the addition method add(a,b) """
self.assertEqualC(add(2,2))
print("output generated by test")
self.assertEqualC(add(-100, 5))
def test_reverse(self):
ls = [1, 2, 3]
reverse = reverse_list(ls)
self.assertEqualC(reverse)
# Although the title is set after the test potentially fails, it will *always* show correctly for the student.
self.title = f"Checking if reverse_list({ls}) = {reverse}" # Programmatically set the title
\ No newline at end of file
# example_framework/instructor/cs102/report2.py
class Week1Titles(UTestCase):
""" The same problem as before with nicer titles """
def test_add(self):
""" Test the addition method add(a,b) """
self.assertEqualC(add(2,2))
print("output generated by test")
self.assertEqualC(add(-100, 5))
def test_reverse(self):
ls = [1, 2, 3]
reverse = reverse_list(ls)
self.assertEqualC(reverse)
# Although the title is set after the test potentially fails, it will *always* show correctly for the student.
self.title = f"Checking if reverse_list({ls}) = {reverse}" # Programmatically set the title
\ No newline at end of file
# example_framework/instructor/cs102/report2.py
# class Question2(UTestCase):
# @cache
# def my_reversal(self, ls):
# # The '@cache' decorator ensures the function is not run on the *students* computer
# # Instead the code is run on the teachers computer and the result is passed on with the
# # other pre-computed results -- i.e. this function will run regardless of how the student happens to have
# # implemented reverse_list.
# return reverse_list(ls)
#
# def test_reverse_tricky(self):
# ls = (2,4,8)
# ls2 = self.my_reversal(tuple(ls)) # This will always produce the right result, [8, 4, 2]
# print("The correct answer is supposed to be", ls2) # Show students the correct answer
# self.assertEqualC(reverse_list(ls)) # This will actually test the students code.
# return "Buy world!" # This value will be stored in the .token file
\ No newline at end of file
class Question2(UTestCase):
@cache
def my_reversal(self, ls):
# The '@cache' decorator ensures the function is not run on the *students* computer
# Instead the code is run on the teachers computer and the result is passed on with the
# other pre-computed results -- i.e. this function will run regardless of how the student happens to have
# implemented reverse_list.
return reverse_list(ls)
def test_reverse_tricky(self):
ls = (2,4,8)
ls2 = self.my_reversal(tuple(ls)) # This will always produce the right result, [8, 4, 2]
print("The correct answer is supposed to be", ls2) # Show students the correct answer
self.assertEqualC(reverse_list(ls)) # This will actually test the students code.
return "Buy world!" # This value will be stored in the .token file
\ No newline at end of file
# example_framework/instructor/cs102/report2.py
class Question2(UTestCase):
@cache
def my_reversal(self, ls):
# The '@cache' decorator ensures the function is not run on the *students* computer
# Instead the code is run on the teachers computer and the result is passed on with the
# other pre-computed results -- i.e. this function will run regardless of how the student happens to have
# implemented reverse_list.
return reverse_list(ls)
def test_reverse_tricky(self):
ls = (2,4,8)
ls2 = self.my_reversal(tuple(ls)) # This will always produce the right result, [8, 4, 2]
print("The correct answer is supposed to be", ls2) # Show students the correct answer
self.assertEqualC(reverse_list(ls)) # This will actually test the students code.
return "Buy world!" # This value will be stored in the .token file
\ No newline at end of file
# example_framework/instructor/cs102/report2.py
from unitgrade import UTestCase, cache
class Week1(UTestCase):
@classmethod
def setUpClass(cls) -> None:
a = 234
def test_add(self):
self.assertEqualC(add(2,2))
self.assertEqualC(add(-100, 5))
def test_reverse(self):
self.assertEqualC(reverse_list([1, 2, 3]))
\ No newline at end of file
# autolab_example_py_upload/instructor/cs102_autolab/report2_test.py
class Week1Titles(UTestCase):
""" The same problem as before with nicer titles """
def test_add(self):
""" Test the addition method add(a,b) """
self.assertEqualC(add(2,2))
print("output generated by test")
self.assertEqualC(add(-100, 5))
# self.assertEqual(2,3, msg="This test automatically fails.")
def test_reverse(self):
ls = [1, 2, 3]
reverse = reverse_list(ls)
self.assertEqualC(reverse)
# Although the title is set after the test potentially fails, it will *always* show correctly for the student.
self.title = f"Checking if reverse_list({ls}) = {reverse}" # Programmatically set the title
\ No newline at end of file
# autolab_example_py_upload/instructor/cs102_autolab/report2_test.py
class Question2(UTestCase):
@cache
def my_reversal(self, ls):
# The '@cache' decorator ensures the function is not run on the *students* computer
# Instead the code is run on the teachers computer and the result is passed on with the
# other pre-computed results -- i.e. this function will run regardless of how the student happens to have
# implemented reverse_list.
return reverse_list(ls)
def test_reverse_tricky(self):
ls = (2,4,8)
ls2 = self.my_reversal(tuple(ls)) # This will always produce the right result, [8, 4, 2]
print("The correct answer is supposed to be", ls2) # Show students the correct answer
self.assertEqualC(reverse_list(ls)) # This will actually test the students code.
return "Buy world!" # This value will be stored in the .token file
\ No newline at end of file
# autolab_example_py_upload/instructor/cs102_autolab/report2_test.py
from unitgrade import UTestCase, cache
import homework1
import unittest
class Week1(UTestCase):
def test_add(self):
self.assertEqualC(add(2,2))
self.assertEqualC(add(-100, 5))
def test_reverse(self):
self.assertEqualC(reverse_list([1, 2, 3]))
\ No newline at end of file
# example_docker/instructor/cs103/report3_complete.py
from unitgrade import UTestCase, Report
from unitgrade.utils import hide
from unitgrade import evaluate_report_student
import cs103
class AutomaticPass(UTestCase):
def test_automatic_pass(self):
self.assertEqual(2, 2) # For simplicity, this test will always pass
@hide # The @hide-decorator tells unitgrade_v1 to hide the test for students.
def test_hidden_fail(self):
self.assertEqual(2, 3) # For simplicity, this test will always fail.
class Report3(Report):
title = "CS 101 Report 3"
questions = [(AutomaticPass, 10)] # Include a single question for 10 credits.
pack_imports = [cs103]
\ No newline at end of file
# example_docker/instructor/cs103/report3.py
from unitgrade import UTestCase, Report
from unitgrade.utils import hide
from unitgrade import evaluate_report_student
import cs103
class AutomaticPass(UTestCase):
def test_automatic_pass(self):
self.assertEqual(2, 2) # For simplicity, this test will always pass
class Report3(Report):
title = "CS 101 Report 3"
questions = [(AutomaticPass, 10)] # Include a single question for 10 credits.
pack_imports = [cs103]
\ No newline at end of file
def reverse_list(mylist): #!f #!s;keeptags
def reverse_list(mylist): #!f
"""
Given a list 'mylist' returns a list consisting of the same elements in reverse order. E.g.
reverse_list([1,2,3]) should return [3,2,1] (as a list).
......@@ -12,4 +12,4 @@ def add(a,b): #!f
if __name__ == "__main__": # Example usage:
print(f"Your result of 2 + 2 = {add(2,2)}")
print(f"Reversing a small list", reverse_list([2,3,5,7])) #!s
print(f"Reversing a small list", reverse_list([2,3,5,7]))
def reverse_list(mylist): #!f #!s;keeptags
def reverse_list(mylist):
"""
Given a list 'mylist' returns a list consisting of the same elements in reverse order. E.g.
reverse_list([1,2,3]) should return [3,2,1] (as a list).
"""
return list(reversed(mylist))
def add(a,b): #!f
def add(a,b):
""" Given two numbers `a` and `b` this function should simply return their sum:
> add(a,b) = a+b """
return a+b
......@@ -13,4 +13,4 @@ def add(a,b): #!f
if __name__ == "__main__":
# Example usage:
print(f"Your result of 2 + 2 = {add(2,2)}")
print(f"Reversing a small list", reverse_list([2,3,5,7])) #!s
print(f"Reversing a small list", reverse_list([2,3,5,7]))