]> git.friedersdorff.com Git - max/python_unittesting.git/commitdiff
Add incorrect ackermann implementation and tests
authorMaximilian Friedersdorff <max@friedersdorff.com>
Mon, 4 Mar 2019 20:47:01 +0000 (20:47 +0000)
committerMaximilian Friedersdorff <max@friedersdorff.com>
Mon, 4 Mar 2019 20:47:01 +0000 (20:47 +0000)
2_troubleshooting.py [new file with mode: 0644]
ackermann_attempt.py [new file with mode: 0644]

diff --git a/2_troubleshooting.py b/2_troubleshooting.py
new file mode 100644 (file)
index 0000000..e4b91c6
--- /dev/null
@@ -0,0 +1,17 @@
+from ackermann_attempt import incorrect_ackermann
+
+
+def test_ackermann_3_3():
+    assert incorrect_ackermann(3, 3) == 61
+
+def test_ackermann_0_0():
+    assert incorrect_ackermann(0, 0) == 1
+
+def test_ackermann_4_0():
+    assert incorrect_ackermann(4, 0) == 13
+
+def test_ackermann_0_4():
+    assert incorrect_ackermann(0, 4) == 5
+
+def test_ackermann_3_5():
+    assert incorrect_ackermann(3, 5) == 253
diff --git a/ackermann_attempt.py b/ackermann_attempt.py
new file mode 100644 (file)
index 0000000..3c2ba73
--- /dev/null
@@ -0,0 +1,13 @@
+def incorrect_ackermann(m, n):
+    if m == 0:
+        return m + 1
+    elif m > 0 and n == 0:
+        return incorrect_ackermann(m - 1, 1)
+    else:
+        return incorrect_ackermann(m - 1, incorrect_ackermann(m - 1, n - 1))
+
+
+
+# if m == 0            ->  n+1
+# if m > 0 and n == 0  ->  A(m-1, 1)
+# otherwise            ->  A(m-1, A(m, n - 1)