replaced line 79 for debugging

This commit is contained in:
2026-02-09 12:13:21 -05:00
parent 6b5511d45b
commit 96b1616b0a
54 changed files with 3808 additions and 1 deletions

View 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()

View File

@@ -3,3 +3,10 @@ DCS 211: Lab 1
Name: Reed, Andrew
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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View File

@@ -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 ----

View 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 ----

View 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()

View 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()

View 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,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()

View 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()

View 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,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()

View 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()

View 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,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()

View 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()

View 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()

View 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()

View 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,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()

View 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()

View 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()

View 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,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()

View 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()

View 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()

View 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()

View 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()

View 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()

View 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,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()

View 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,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()

View 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()

View 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,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()

View 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()

View 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()