From: Erik M. Bray Date: Sat, 1 Dec 2012 23:18:08 +0000 (-1000) Subject: Add the little 'scan' sample program X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=refs%2Fheads%2Ftest-thw-bray;p=swc-testing-nose.git Add the little 'scan' sample program --- diff --git a/4-SoftwareEngineering/Testing/scan.py b/4-SoftwareEngineering/Testing/scan.py new file mode 100644 index 0000000..eb04d5a --- /dev/null +++ b/4-SoftwareEngineering/Testing/scan.py @@ -0,0 +1,15 @@ +def scan(lst): + if len(lst) == 0: + return 0 + total = 0 + last = None + for item in lst: + if last is None or last < item: + total += item + last = item + elif last > item: + total = 0 + last = None + else: + pass + return total diff --git a/4-SoftwareEngineering/Testing/test_scan.py b/4-SoftwareEngineering/Testing/test_scan.py new file mode 100644 index 0000000..36764c0 --- /dev/null +++ b/4-SoftwareEngineering/Testing/test_scan.py @@ -0,0 +1,31 @@ +def scan(lst): + if len(lst) == 0: + return 0 + total = 0 + last = None + for item in lst: + if last is None or last < item: + total += item + last = item + elif last > item: + total = 0 + last = None + else: + pass + return total + +assert scan([]) == 0 +assert scan([1, 2, 3, 4]) == 10 +assert scan([2, 3, 4, 5]) == 14 +assert scan([1, 1, 1, 1]) == 1 +assert scan([3, 2, 5, 4]) == 0 +assert scan([4, 3, 2, 1]) == 0 +assert scan([3, 4, 5, 1]) == 0 +assert scan([1, 2, 3, 5, 4]) == 0 +assert scan([1, 2, 3, 3]) == 6 +assert scan([1, 2, 4, 4]) == 7 +assert scan([1, 2, 4, 4, 5]) == 12 +assert scan([-3, -2, -1]) == -6 +assert scan([-1, -2, -3]) == -3 +assert scan([-1, -2, -3, -2, -1]) == -6 +assert scan([3, 2, 1, 2, 3]) == 6