aboutsummaryrefslogtreecommitdiffstats
path: root/csci1913/Python
diff options
context:
space:
mode:
authorMatthew Strapp <msattr@gmail.com>2019-09-25 14:49:08 -0500
committerMatthew Strapp <msattr@gmail.com>2019-09-25 14:49:08 -0500
commitab58806e6d20663b1569d147c6b9ceab6ec69fae (patch)
tree06d7e8110f8470b1d7f97e71f23151dba4c203e8 /csci1913/Python
parentMerge branch 'master' of github.com:RosstheRoss/TestingFun (diff)
downloadhomework-ab58806e6d20663b1569d147c6b9ceab6ec69fae.tar
homework-ab58806e6d20663b1569d147c6b9ceab6ec69fae.tar.gz
homework-ab58806e6d20663b1569d147c6b9ceab6ec69fae.tar.bz2
homework-ab58806e6d20663b1569d147c6b9ceab6ec69fae.tar.lz
homework-ab58806e6d20663b1569d147c6b9ceab6ec69fae.tar.xz
homework-ab58806e6d20663b1569d147c6b9ceab6ec69fae.tar.zst
homework-ab58806e6d20663b1569d147c6b9ceab6ec69fae.zip
Start Lab
Diffstat (limited to 'csci1913/Python')
-rw-r--r--csci1913/Python/lab3_strap012.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/csci1913/Python/lab3_strap012.py b/csci1913/Python/lab3_strap012.py
new file mode 100644
index 0000000..ea6bdf0
--- /dev/null
+++ b/csci1913/Python/lab3_strap012.py
@@ -0,0 +1,63 @@
+#"New" functions
+def Reduce(F,S):
+ if len(S)==0:
+ return -999
+ else:
+ return F(S[0],Reduce(F,S[1:]))
+def filter(P,S):
+ if len(S)==0:
+ return ()
+ elif P(S[0]):
+ return (S[0]) + filter(P,S[1:])
+ else:
+ return filter(P,S[1:])
+
+def returnGreater(a,b):
+ if a > b:
+ return a
+ return b
+
+#Implementation from Lab
+def Sort(T):
+ return None
+def Maximum(T):
+ return Reduce(returnGreater,T)
+def Remove(T,E):
+ return None
+
+
+
+#
+# TESTS. Tests for CSci 1913 Lab 3.
+#
+# James Moen
+# 11 Feb 19
+#
+# Each test is worth 2 points, for 40 points total. Comments show what must be
+# printed to receive credit. Note that your function SORT must work for tuples
+# with negative elements.
+#
+
+print(Maximum((1,))) # 1 2 pt.
+print(Maximum((-2, -1))) # -1 2 pt.
+print(Maximum((1, 1))) # 1 2 pt.
+print(Maximum((1, 2, 3))) # 3 2 pt.
+
+print(Remove((), 1)) # () 2 pt.
+print(Remove((1,), 1)) # () 2 pt.
+print(Remove((0, 1), 0)) # (1,) 2 pt.
+print(Remove((0, 1, 2, 1, 3), 1)) # (0, 2, 1, 3) 2 pt.
+print(Remove((0, 1, 2, 1, 3), 2)) # (0, 1, 1, 3) 2 pt.
+print(Remove((1, 2, 3), 3)) # (1, 2) 2 pt.
+
+print(Sort(())) # () 2 pt.
+print(Sort((0,))) # (0,) 2 pt.
+print(Sort((0, -1))) # (-1, 0) 2 pt.
+print(Sort((1, 0))) # (0, 1) 2 pt.
+print(Sort((0, 0, 1))) # (0, 0, 1) 2 pt.
+print(Sort((0, -1, 0))) # (-1, 0, 0) 2 pt.
+print(Sort((0, 0, 1))) # (0, 0, 1) 2 pt.
+
+print(Sort((9, 8, 7, 6, 5, 4, 3, 2, 1))) # (1, 2, 3, 4, 5, 6, 7, 8, 9) 2 pt.
+print(Sort((1, 2, 3, 4, 5, 6, 7, 8, 9))) # (1, 2, 3, 4, 5, 6, 7, 8, 9) 2 pt.
+print(Sort((1, 2, 1, 4, 2, 5, 4, 5, 3))) # (1, 1, 2, 2, 3, 4, 4, 5, 5) 2 pt.