replaced line 79 for debugging
This commit is contained in:
@@ -75,7 +75,9 @@ EOF
|
|||||||
} >> "$outfile"
|
} >> "$outfile"
|
||||||
|
|
||||||
score="$(echo "$output" | tail -n 1 | grep -Eo '[0-9]+[[:space:]]*/[[:space:]]*[0-9]+' || echo N/A)"
|
score="$(echo "$output" | tail -n 1 | grep -Eo '[0-9]+[[:space:]]*/[[:space:]]*[0-9]+' || echo N/A)"
|
||||||
sed -i.bak "s/STUDENT_SCORE/$score/" "$outfile" && rm "$outfile.bak"
|
safe_score="$(printf '%s' "$score" | sed 's/[\/&]/\\&/g')"
|
||||||
|
sed -i.bak "s/STUDENT_SCORE/${safe_score}/" "$outfile" && rm "$outfile.bak"
|
||||||
|
|
||||||
|
|
||||||
echo "Graded $id"
|
echo "Graded $id"
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,2]))
|
||||||
|
|
||||||
|
# print(compute_sum([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_sum([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
|
||||||
|
# print(compute_product([1,2]))
|
||||||
|
|
||||||
|
# print(compute_product([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_product([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -3,3 +3,10 @@ DCS 211: Lab 1
|
|||||||
Name: Reed, Andrew
|
Name: Reed, Andrew
|
||||||
Score: STUDENT_SCORE
|
Score: STUDENT_SCORE
|
||||||
====================================
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
File "/Users/benjamin/Desktop/GitHub Local/DCS 211/Lab 1 - Group Work/lab1_files/autograde/areed2/__graded_areed2.py", line 59
|
||||||
|
from typing import Callable
|
||||||
|
^^^^
|
||||||
|
IndentationError: expected an indented block after function definition on line 41
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Kenny, Chris
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Amini, Edward
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Miele, Fran
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Jiang, Jerry
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Roelofs, Julia
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
File "/Users/benjamin/Desktop/GitHub Local/DCS 211/Lab 1 - Group Work/lab1_files/autograde/jroelofs/__graded_jroelofs.py", line 59
|
||||||
|
from typing import Callable
|
||||||
|
^^^^
|
||||||
|
IndentationError: expected an indented block after function definition on line 41
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Marte, Juan Carlos Tapia
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Baron, Liam
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Rouhou, Leith
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Hrinda, Luke
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
File "/Users/benjamin/Desktop/GitHub Local/DCS 211/Lab 1 - Group Work/lab1_files/autograde/lhrinda/__graded_lhrinda.py", line 59
|
||||||
|
from typing import Callable
|
||||||
|
^^^^
|
||||||
|
IndentationError: expected an indented block after function definition on line 41
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Paynter, Lucy
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Cory, Max
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Donaghy, Megan
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Logan, Miles
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
File "/Users/benjamin/Desktop/GitHub Local/DCS 211/Lab 1 - Group Work/lab1_files/autograde/mlogan/__graded_mlogan.py", line 59
|
||||||
|
from typing import Callable
|
||||||
|
^^^^
|
||||||
|
IndentationError: expected an indented block after function definition on line 41
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Nijjer, Mehar
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Shimizu, Micah
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Young, Malina
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Zuze, Noku
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
File "/Users/benjamin/Desktop/GitHub Local/DCS 211/Lab 1 - Group Work/lab1_files/autograde/nzuze/__graded_nzuze.py", line 59
|
||||||
|
from typing import Callable
|
||||||
|
^^^^
|
||||||
|
IndentationError: expected an indented block after function definition on line 41
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Enkh-Orgil, Yuka
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
File "/Users/benjamin/Desktop/GitHub Local/DCS 211/Lab 1 - Group Work/lab1_files/autograde/oenkhorgil/__graded_oenkhorgil.py", line 59
|
||||||
|
from typing import Callable
|
||||||
|
^^^^
|
||||||
|
IndentationError: expected an indented block after function definition on line 41
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Putnam-Bagley, Lando
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
File "/Users/benjamin/Desktop/GitHub Local/DCS 211/Lab 1 - Group Work/lab1_files/autograde/oputnambagley/__graded_oputnambagley.py", line 59
|
||||||
|
from typing import Callable
|
||||||
|
^^^^
|
||||||
|
IndentationError: expected an indented block after function definition on line 41
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Gleason, Ryan
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
File "/Users/benjamin/Desktop/GitHub Local/DCS 211/Lab 1 - Group Work/lab1_files/autograde/rgleason/__graded_rgleason.py", line 59
|
||||||
|
from typing import Callable
|
||||||
|
^^^^
|
||||||
|
IndentationError: expected an indented block after function definition on line 41
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Hughes, Sarah
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Maquera, Sara
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Rice, Sam
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Leamon, Ted
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Shapiro, Teddy
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
Testing compute_sum([]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_sum([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_sum([-1, 2, -3]):
|
||||||
|
✓ result = -2
|
||||||
|
expected = -2
|
||||||
|
Testing compute_product([]):
|
||||||
|
✓ result = None
|
||||||
|
expected = None
|
||||||
|
Testing compute_product([0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
Testing compute_product([1, 2, 3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, 2, -3]):
|
||||||
|
✓ result = 6
|
||||||
|
expected = 6
|
||||||
|
Testing compute_product([-1, -2, -3]):
|
||||||
|
✓ result = -6
|
||||||
|
expected = -6
|
||||||
|
Testing compute_product([-1, -2, -3, 0]):
|
||||||
|
✓ result = 0
|
||||||
|
expected = 0
|
||||||
|
------------------------------
|
||||||
|
Total tests passed: 10 / 10
|
||||||
|
------------------------------
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
12
Lab 1 - Group Work/lab1_files/autograde/dcs211_lab1_zali.txt
Normal file
12
Lab 1 - Group Work/lab1_files/autograde/dcs211_lab1_zali.txt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
==============================
|
||||||
|
DCS 211: Lab 1
|
||||||
|
Name: Ali, Zain
|
||||||
|
Score: STUDENT_SCORE
|
||||||
|
====================================
|
||||||
|
|
||||||
|
---- AUTOGRADE OUTPUT ----
|
||||||
|
File "/Users/benjamin/Desktop/GitHub Local/DCS 211/Lab 1 - Group Work/lab1_files/autograde/zali/__graded_zali.py", line 59
|
||||||
|
from typing import Callable
|
||||||
|
^^^^
|
||||||
|
IndentationError: expected an indented block after function definition on line 41
|
||||||
|
---- END AUTOGRADE OUTPUT ----
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,2]))
|
||||||
|
|
||||||
|
# print(compute_sum([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_sum([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
|
||||||
|
# print(compute_product([1,2]))
|
||||||
|
|
||||||
|
# print(compute_product([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_product([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,2]))
|
||||||
|
|
||||||
|
# print(compute_sum([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_sum([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
|
||||||
|
# print(compute_product([1,2]))
|
||||||
|
|
||||||
|
# print(compute_product([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_product([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
# print(compute_sum([1,2,3]))
|
||||||
|
# print(compute_sum([-1,-2,-3]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
# print(compute_product([1,2,3]))
|
||||||
|
# print(compute_product([-1,-2,-3]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
value = compute_sum([0])
|
||||||
|
# print(value)
|
||||||
|
value = compute_sum([1,2,3])
|
||||||
|
# print(value)
|
||||||
|
value = compute_sum([-1,-2,-3])
|
||||||
|
# print(value)
|
||||||
|
|
||||||
|
# main()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0,0,0]))
|
||||||
|
# print(compute_sum([1,2,3,4,5]))
|
||||||
|
# print(compute_sum([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_sum([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0,0,0]))
|
||||||
|
# print(compute_product([1,2,3,4,5]))
|
||||||
|
# print(compute_product([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_product([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_product([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# print(compute_sum([0,0,0]))
|
||||||
|
# print(compute_sum([1,2,3,4,5]))
|
||||||
|
# print(compute_sum([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_sum([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
# print(compute_product([0,0,0]))
|
||||||
|
# print(compute_product([1,2,3,4,5]))
|
||||||
|
# print(compute_product([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_product([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_product([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
# main()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
# print(compute_sum([1,2,3]))
|
||||||
|
# print(compute_sum([-1,-2,-3]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
# print(compute_product([1,2,3]))
|
||||||
|
# print(compute_product([-1,-2,-3]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
value = compute_sum([0])
|
||||||
|
# print(value)
|
||||||
|
value = compute_sum([1,2,3])
|
||||||
|
# print(value)
|
||||||
|
value = compute_sum([-1,-2,-3])
|
||||||
|
# print(value)
|
||||||
|
|
||||||
|
# main()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,2]))
|
||||||
|
|
||||||
|
# print(compute_sum([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_sum([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
|
||||||
|
# print(compute_product([1,2]))
|
||||||
|
|
||||||
|
# print(compute_product([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_product([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
# print(compute_sum([1,2,3]))
|
||||||
|
# print(compute_sum([-1,-2,-3]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
# print(compute_product([1,2,3]))
|
||||||
|
# print(compute_product([-1,-2,-3]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
value = compute_sum([0])
|
||||||
|
# print(value)
|
||||||
|
value = compute_sum([1,2,3])
|
||||||
|
# print(value)
|
||||||
|
value = compute_sum([-1,-2,-3])
|
||||||
|
# print(value)
|
||||||
|
|
||||||
|
# main()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0,0,0]))
|
||||||
|
# print(compute_sum([1,2,3,4,5]))
|
||||||
|
# print(compute_sum([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_sum([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0,0,0]))
|
||||||
|
# print(compute_product([1,2,3,4,5]))
|
||||||
|
# print(compute_product([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_product([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_product([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# print(compute_sum([0,0,0]))
|
||||||
|
# print(compute_sum([1,2,3,4,5]))
|
||||||
|
# print(compute_sum([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_sum([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
# print(compute_product([0,0,0]))
|
||||||
|
# print(compute_product([1,2,3,4,5]))
|
||||||
|
# print(compute_product([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_product([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_product([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
# main()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,2]))
|
||||||
|
|
||||||
|
# print(compute_sum([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_sum([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
|
||||||
|
# print(compute_product([1,2]))
|
||||||
|
|
||||||
|
# print(compute_product([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_product([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
110
Lab 1 - Group Work/lab1_files/autograde/mcory/__graded_mcory.py
Normal file
110
Lab 1 - Group Work/lab1_files/autograde/mcory/__graded_mcory.py
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,2]))
|
||||||
|
|
||||||
|
# print(compute_sum([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_sum([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
|
||||||
|
# print(compute_product([1,2]))
|
||||||
|
|
||||||
|
# print(compute_product([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_product([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
# print(compute_sum([1,2,3]))
|
||||||
|
# print(compute_sum([-1,-2,-3]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
# print(compute_product([1,2,3]))
|
||||||
|
# print(compute_product([-1,-2,-3]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
value = compute_sum([0])
|
||||||
|
# print(value)
|
||||||
|
value = compute_sum([1,2,3])
|
||||||
|
# print(value)
|
||||||
|
value = compute_sum([-1,-2,-3])
|
||||||
|
# print(value)
|
||||||
|
|
||||||
|
# main()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0,0,0]))
|
||||||
|
# print(compute_sum([1,2,3,4,5]))
|
||||||
|
# print(compute_sum([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_sum([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0,0,0]))
|
||||||
|
# print(compute_product([1,2,3,4,5]))
|
||||||
|
# print(compute_product([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_product([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_product([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# print(compute_sum([0,0,0]))
|
||||||
|
# print(compute_sum([1,2,3,4,5]))
|
||||||
|
# print(compute_sum([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_sum([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
# print(compute_product([0,0,0]))
|
||||||
|
# print(compute_product([1,2,3,4,5]))
|
||||||
|
# print(compute_product([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_product([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_product([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
# main()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,2]))
|
||||||
|
|
||||||
|
# print(compute_sum([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_sum([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
|
||||||
|
# print(compute_product([1,2]))
|
||||||
|
|
||||||
|
# print(compute_product([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_product([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
# print(compute_sum([1,2,3]))
|
||||||
|
# print(compute_sum([-1,-2,-3]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
# print(compute_product([1,2,3]))
|
||||||
|
# print(compute_product([-1,-2,-3]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
value = compute_sum([0])
|
||||||
|
# print(value)
|
||||||
|
value = compute_sum([1,2,3])
|
||||||
|
# print(value)
|
||||||
|
value = compute_sum([-1,-2,-3])
|
||||||
|
# print(value)
|
||||||
|
|
||||||
|
# main()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,2]))
|
||||||
|
|
||||||
|
# print(compute_sum([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_sum([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
|
||||||
|
# print(compute_product([1,2]))
|
||||||
|
|
||||||
|
# print(compute_product([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_product([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
123
Lab 1 - Group Work/lab1_files/autograde/nzuze/__graded_nzuze.py
Normal file
123
Lab 1 - Group Work/lab1_files/autograde/nzuze/__graded_nzuze.py
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0,0,0]))
|
||||||
|
# print(compute_sum([1,2,3,4,5]))
|
||||||
|
# print(compute_sum([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_sum([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0,0,0]))
|
||||||
|
# print(compute_product([1,2,3,4,5]))
|
||||||
|
# print(compute_product([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_product([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_product([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# print(compute_sum([0,0,0]))
|
||||||
|
# print(compute_sum([1,2,3,4,5]))
|
||||||
|
# print(compute_sum([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_sum([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
# print(compute_product([0,0,0]))
|
||||||
|
# print(compute_product([1,2,3,4,5]))
|
||||||
|
# print(compute_product([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_product([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_product([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
# main()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0,0,0]))
|
||||||
|
# print(compute_sum([1,2,3,4,5]))
|
||||||
|
# print(compute_sum([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_sum([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0,0,0]))
|
||||||
|
# print(compute_product([1,2,3,4,5]))
|
||||||
|
# print(compute_product([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_product([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_product([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# print(compute_sum([0,0,0]))
|
||||||
|
# print(compute_sum([1,2,3,4,5]))
|
||||||
|
# print(compute_sum([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_sum([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
# print(compute_product([0,0,0]))
|
||||||
|
# print(compute_product([1,2,3,4,5]))
|
||||||
|
# print(compute_product([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_product([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_product([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
# main()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0,0,0]))
|
||||||
|
# print(compute_sum([1,2,3,4,5]))
|
||||||
|
# print(compute_sum([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_sum([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0,0,0]))
|
||||||
|
# print(compute_product([1,2,3,4,5]))
|
||||||
|
# print(compute_product([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_product([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_product([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# print(compute_sum([0,0,0]))
|
||||||
|
# print(compute_sum([1,2,3,4,5]))
|
||||||
|
# print(compute_sum([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_sum([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
# print(compute_product([0,0,0]))
|
||||||
|
# print(compute_product([1,2,3,4,5]))
|
||||||
|
# print(compute_product([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_product([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_product([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
# main()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0,0,0]))
|
||||||
|
# print(compute_sum([1,2,3,4,5]))
|
||||||
|
# print(compute_sum([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_sum([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0,0,0]))
|
||||||
|
# print(compute_product([1,2,3,4,5]))
|
||||||
|
# print(compute_product([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_product([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_product([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# print(compute_sum([0,0,0]))
|
||||||
|
# print(compute_sum([1,2,3,4,5]))
|
||||||
|
# print(compute_sum([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_sum([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
# print(compute_product([0,0,0]))
|
||||||
|
# print(compute_product([1,2,3,4,5]))
|
||||||
|
# print(compute_product([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_product([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_product([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
# main()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
# print(compute_sum([1,2,3]))
|
||||||
|
# print(compute_sum([-1,-2,-3]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
# print(compute_product([1,2,3]))
|
||||||
|
# print(compute_product([-1,-2,-3]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
value = compute_sum([0])
|
||||||
|
# print(value)
|
||||||
|
value = compute_sum([1,2,3])
|
||||||
|
# print(value)
|
||||||
|
value = compute_sum([-1,-2,-3])
|
||||||
|
# print(value)
|
||||||
|
|
||||||
|
# main()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
# print(compute_sum([1,2,3]))
|
||||||
|
# print(compute_sum([-1,-2,-3]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
# print(compute_product([1,2,3]))
|
||||||
|
# print(compute_product([-1,-2,-3]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
value = compute_sum([0])
|
||||||
|
# print(value)
|
||||||
|
value = compute_sum([1,2,3])
|
||||||
|
# print(value)
|
||||||
|
value = compute_sum([-1,-2,-3])
|
||||||
|
# print(value)
|
||||||
|
|
||||||
|
# main()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
110
Lab 1 - Group Work/lab1_files/autograde/srice/__graded_srice.py
Normal file
110
Lab 1 - Group Work/lab1_files/autograde/srice/__graded_srice.py
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,2]))
|
||||||
|
|
||||||
|
# print(compute_sum([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_sum([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
|
||||||
|
# print(compute_product([1,2]))
|
||||||
|
|
||||||
|
# print(compute_product([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_product([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
# print(compute_sum([1,2,3]))
|
||||||
|
# print(compute_sum([-1,-2,-3]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
# print(compute_product([1,2,3]))
|
||||||
|
# print(compute_product([-1,-2,-3]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
value = compute_sum([0])
|
||||||
|
# print(value)
|
||||||
|
value = compute_sum([1,2,3])
|
||||||
|
# print(value)
|
||||||
|
value = compute_sum([-1,-2,-3])
|
||||||
|
# print(value)
|
||||||
|
|
||||||
|
# main()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,2]))
|
||||||
|
|
||||||
|
# print(compute_sum([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_sum([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0]))
|
||||||
|
|
||||||
|
# print(compute_product([1,2]))
|
||||||
|
|
||||||
|
# print(compute_product([3,4,5,6,7]))
|
||||||
|
|
||||||
|
# print(compute_product([-3,4,5,6,7]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
123
Lab 1 - Group Work/lab1_files/autograde/zali/__graded_zali.py
Normal file
123
Lab 1 - Group Work/lab1_files/autograde/zali/__graded_zali.py
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
def compute_sum(list_: list[int]) -> int:
|
||||||
|
''' function to compute the sum of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the integer sum of the list of integers
|
||||||
|
'''
|
||||||
|
sum_ = 0
|
||||||
|
for i in list_:
|
||||||
|
sum_ += i
|
||||||
|
return sum_
|
||||||
|
|
||||||
|
# print(compute_sum([0,0,0]))
|
||||||
|
# print(compute_sum([1,2,3,4,5]))
|
||||||
|
# print(compute_sum([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_sum([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
def compute_product(list_: list[int]) -> int | None:
|
||||||
|
''' function to compute the product of a list of integers
|
||||||
|
Parameters:
|
||||||
|
list_: a list of integers
|
||||||
|
Returns:
|
||||||
|
the product sum of the list of integers; if the list is
|
||||||
|
empty, we return None
|
||||||
|
'''
|
||||||
|
if len(list_) == 0: return None
|
||||||
|
product = 1
|
||||||
|
for i in list_:
|
||||||
|
product *= i
|
||||||
|
return product
|
||||||
|
|
||||||
|
# print(compute_product([0,0,0]))
|
||||||
|
# print(compute_product([1,2,3,4,5]))
|
||||||
|
# print(compute_product([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_product([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_product([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# print(compute_sum([0,0,0]))
|
||||||
|
# print(compute_sum([1,2,3,4,5]))
|
||||||
|
# print(compute_sum([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_sum([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_sum([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
# print(compute_product([0,0,0]))
|
||||||
|
# print(compute_product([1,2,3,4,5]))
|
||||||
|
# print(compute_product([-1,-2,-3,-4,-5]))
|
||||||
|
|
||||||
|
# print(compute_product([1,1,1,1,1,1,1]))
|
||||||
|
# print(compute_product([1,2,3,4,5,4,3]))
|
||||||
|
|
||||||
|
# main()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
from typing import Callable
|
||||||
|
def testHarness(fcn: Callable, arg: str, expected: str | list) -> int:
|
||||||
|
''' function to help test an arbitrary function having one argument
|
||||||
|
Parameters:
|
||||||
|
fcn: the actual function being tested (pass without calling)
|
||||||
|
arg: the argument being passed to the tested function
|
||||||
|
expected: the expected result, either str or list in the context here
|
||||||
|
Returns:
|
||||||
|
None -- just prints
|
||||||
|
'''
|
||||||
|
result = fcn(arg) # call the student's function, passing the given argument
|
||||||
|
|
||||||
|
# see https://unicode-table.com/en/sets/check/
|
||||||
|
# replace these as you see fit
|
||||||
|
mark = "✓" if result == expected else "✗"
|
||||||
|
print(f"Testing {fcn.__name__}({repr(arg)}):")
|
||||||
|
print(f"\t {mark} result = {result}")
|
||||||
|
print(f"\t expected = {expected}")
|
||||||
|
|
||||||
|
if result == expected:
|
||||||
|
return 1 # correct +1
|
||||||
|
return 0 # incorrect +0
|
||||||
|
|
||||||
|
###################
|
||||||
|
def main_grading():
|
||||||
|
count = 0
|
||||||
|
tests = 0
|
||||||
|
|
||||||
|
arg = []; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = -2; tests += 1
|
||||||
|
count += testHarness(compute_sum, arg, expected)
|
||||||
|
|
||||||
|
|
||||||
|
arg = []; expected = None; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [1,2,3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,2,-3]; expected = 6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3]; expected = -6; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
arg = [-1,-2,-3,0]; expected = 0; tests += 1
|
||||||
|
count += testHarness(compute_product, arg, expected)
|
||||||
|
|
||||||
|
print('-' * 30)
|
||||||
|
print(f"Total tests passed: {count} / {tests}")
|
||||||
|
print('-' * 30)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_grading()
|
||||||
Reference in New Issue
Block a user