Skip to content

Commit

Permalink
Fixes to make the functions more specific and add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
barbarer committed Aug 26, 2024
1 parent 7214c8b commit a377310
Showing 1 changed file with 63 additions and 39 deletions.
102 changes: 63 additions & 39 deletions _sources/functions/funcGAI-hw1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ Function1 takes a list of numbers and outputs a number as shown below:
Input Output
function1([10, 80, 100]) 90.0
function1([50, 70, 90]) 80.0
function1([70, 50 90]) 80.0
function1([2, 4, 6, 8]) 6.0
To check that you understand what the function is doing please enter the expected output for the following input:

.. fillintheblank:: function1_test1

What is the expected output from ``function1([20, 80])``?
What is the expected output from ``function1([80, 20])``?

- :80|80\.0|eighty: Correct
:.*: Look at the examples above. How is the result different from just an average?
Expand All @@ -52,7 +52,7 @@ To check that you understand what the function is doing please enter the expecte
Input Output
function1([10, 80, 100]) 90.0
function1([50, 70, 90]) 80.0
function1([70, 50, 90]) 80.0
function1([2, 4, 6, 8]) 6.0
~~~~

Expand All @@ -64,10 +64,16 @@ To check that you understand what the function is doing please enter the expecte

def testOne(self):
self.assertAlmostEqual(function1([10, 80, 100]), 90.0, 2, "function1([10, 80, 100])")
self.assertAlmostEqual(function1([50, 70, 90]), 80.0, 2, "function1([50, 70, 90])")
self.assertAlmostEqual(function1([70, 50, 90]), 80.0, 2, "function1([70, 50, 90])")
self.assertAlmostEqual(function1([2, 4, 6, 8]), 6.0, 2, "function1([2, 4, 6, 8])")
self.assertAlmostEqual(function1([20, 80]), 80.0, 2, "function1([20, 80])")
self.assertAlmostEqual(function1([80, 20]), 80.0, 2, "function1([80, 20])")
self.assertAlmostEqual(function1([0, 100, 80]), 90.0, 2, "function1([0, 100, 80])")
self.assertAlmostEqual(function1([10, 80, 10]), 45.0, 2, "function1([10, 80, 10])")
self.assertAlmostEqual(function1([85, 10, 70]), 77.5, 2, "function1([85, 10, 70])")
self.assertAlmostEqual(function1([10, 90]), 90.0, 2, "function1([10, 90])")
self.assertAlmostEqual(function1([70, 40, 10, 90]), 66.67, 2, "function1([70, 40, 10, 90])")
self.assertAlmostEqual(function1([75, 45, 85, 55]), 71.67, 2, "function1([75, 45, 85, 55])")


myTests().main()

Expand All @@ -79,9 +85,9 @@ Function 2 takes a list of numbers and outputs a number as shown below:
.. code-block:: python
Input Output
function2([1, 3, 5, 4]) 3
function2([2, 4, 6]) 0
function2([1, 2, 3, 5]) 3
function2([1, 3, 5, 4]) 1
function2([2, 4, 6]) 3
function2([4, 1, 6, 13]) 2
To check that you understand what the function is doing please enter the expected output for the following input:
Expand All @@ -91,14 +97,14 @@ To check that you understand what the function is doing please enter the expecte
What is the expected output from ``function2([1, 2])``?

- :1|one: Correct
:.*: Look at the examples above. What do the numbers 1, 3, and 5 have in common?
:.*: Look at the examples above. What do the numbers 2, 4, and 6 have in common?

.. fillintheblank:: function2_test2

What is the expected output from ``function2([0, 1, 3])``?
What is the expected output from ``function2([3, 1, 0])``?

- :2|two: Correct
:.*: Look at the examples above. What do the numbers 1, 3, and 5 have in common?
- :1|one: Correct
:.*: Look at the examples above. What do the numbers 2, 4, and 6 have in common?

.. shortanswer:: fuction2_sa

Expand All @@ -112,9 +118,9 @@ To check that you understand what the function is doing please enter the expecte
.. code-block:: python
Input Output
function2([1, 3, 5, 4]) 3
function2([2, 4, 6]) 0
function2([1, 2, 3, 5]) 3
function2([1, 3, 5, 4]) 1
function2([2, 4, 6]) 3
function2([4, 1, 6, 13]) 2
~~~~
====

Expand All @@ -123,11 +129,19 @@ To check that you understand what the function is doing please enter the expecte
class myTests(TestCaseGui):

def testOne(self):
self.assertEqual(function2([1, 3, 5, 4]), 3, "function2([1, 3, 5, 4])")
self.assertEqual(function2([2, 4, 6]), 0, "function2([2, 4, 6])")
self.assertEqual(function2([1, 2, 3, 5]), 3, "function2([1, 2, 3, 5])")
self.assertEqual(function2([1, 3, 5, 4]), 1, "function2([1, 3, 5, 4])")
self.assertEqual(function2([2, 4, 6]), 3, "function2([2, 4, 6])")
self.assertEqual(function2([ 4, 1, 6, 13]), 2, "function2([ 4, 1, 6, 13])")
self.assertEqual(function2([1, 2]), 1, "function2([1, 2])")
self.assertEqual(function2([0, 1, 3]), 2, "function2([0, 1, 3])")
self.assertEqual(function2([3, 1, 0]), 1, "function2([3, 1, 0])")
self.assertEqual(function2([-3, -1, -5]), 0, "function2([-3, -1, -5])")
self.assertEqual(function2([12]), 1, "function2([12])")
self.assertEqual(function2([11]), 0, "function2([11])")
self.assertEqual(function2([3, -8, 12, 16, 18]), 4, "function2([3, -8, 12, 16, 18])")
self.assertEqual(function2([13, 4, 17]), 1, "function2([13, 4, 17])")




myTests().main()

Expand All @@ -152,9 +166,9 @@ To check that you understand what the function is doing please enter the expecte

.. fillintheblank:: function3_test1

What is the expected output from ``function3(3)``?
What is the expected output from ``function3(19)``?

- :"?child"?: Correct
- :"?teen"?: Correct
:.*: Look at the examples above. What category do you think the input should be in?

.. fillintheblank:: function3_test2
Expand Down Expand Up @@ -198,7 +212,7 @@ To check that you understand what the function is doing please enter the expecte
self.assertEqual(function3(13), "teen", "function3(13)")
self.assertEqual(function3(17), "teen", "function3(17)")
self.assertEqual(function3(20), "adult", "function3(20)")
self.assertEqual(function3(3), "child", "function3(3)")
self.assertEqual(function3(19), "teen", "function3(19)")
self.assertEqual(function3(30), "adult", "function3(30)")
self.assertEqual(function3(10), "tween", "function3(10)")
self.assertEqual(function3(15), "teen", "function3(15)")
Expand All @@ -212,10 +226,10 @@ Function 4 takes a list of numbers and outputs a list of numbers as shown below:

.. code-block:: python
Input Output
Input Output
function4([1, 3, -2, 5]) [1, 3, 0, 5]
function4([0, 2, 4, -3]) [0, 2, 4, 0]
function4([1, 3, 5) [1, 3, 5]
function4([-8, 2, 4, -1]) [-8, 2, 4, 0]
function4([0, 3, 5]) [0, 3, 5]
To check that you understand what the function is doing please enter the expected output for the following input:
Expand All @@ -224,14 +238,14 @@ To check that you understand what the function is doing please enter the expecte

What is the expected output from ``function4([1, 2])``?

- :\[1, 2\]|one: Correct
- :\[1, 2\]|\[1,2\]: Correct
:.*: Look at the examples above. How does the list change?

.. fillintheblank:: function4_test2

What is the expected output from ``function4([-5, 1, 3])``?

- :\[0, 1, 3\]|two: Correct
- :\[0, 1, 3\]|\[0,1,3\]: Correct
:.*: Look at the examples above. How does the list change?

.. shortanswer:: fuction4_sa
Expand All @@ -247,8 +261,8 @@ To check that you understand what the function is doing please enter the expecte
Input Output
function4([1, 3, -2, 5]) [1, 3, 0, 5]
function4([0, 2, 4, -3]) [0, 2, 4, 0]
function4([1, 3, 5) [1, 3, 5]
function4([-8, 2, 4, -1]) [-8, 2, 4, 0]
function4([0, 3, 5]) [0, 3, 5]
~~~~
====
Expand All @@ -259,10 +273,15 @@ To check that you understand what the function is doing please enter the expecte

def testOne(self):
self.assertEqual(function4([1, 3, -2, 5]), [1, 3, 0, 5], "function4([1, 3, -2, 5])")
self.assertEqual(function4([0, 2, 4, -3]), [0, 2, 4, 0], "function4([0, 2, 4, -3])")
self.assertEqual(function4([1, 3, 5]), [1, 3, 5], "function4([1, 3, 5])")
self.assertEqual(function4([-8, 2, 4, -1]), [0, 2, 4, 0], "function4([-8, 2, 4, -1])")
self.assertEqual(function4([0, 3, 5]), [0, 3, 5], "function4([0, 3, 5])")
self.assertEqual(function4([1, 2]), [1, 2], "function4([1, 2])")
self.assertEqual(function4([-5, 1, 3]), [0, 1, 3], "function4([-5, 1, 3])")
self.assertEqual(function4([0, 0, 0]), [0, 0, 0], "function4([0, 0, 0])")
self.assertEqual(function4([-13]), [0], "function4([-13])")
self.assertEqual(function4([7, 5, 3, 1]), [7, 5, 3, 1], "function4([7, 5, 3, 1])")
self.assertEqual(function4([33, -23]), [33, 0], "function4([33, -23])")
self.assertEqual(function4([1, 2, 3, 4, 5]), [1, 2, 3, 4, 5], "function4([1, 2, 3, 4, 5])")


myTests().main()
Expand All @@ -277,8 +296,8 @@ Function 5 takes a string and returns a string as shown below:
.. code-block:: python
Input Output
function5("Walk this way") "Wathwa"
function5("Run Away") "Ruaw"
function5("Walk This Way") "Wathwa"
function5("run away") "Ruaw"
function5("I love puppies") "Ilopu"
Expand Down Expand Up @@ -311,8 +330,8 @@ To check that you understand what the function is doing please enter the expecte
Input Output
function5("Walk this way") "Wathwa"
function5("Run Away") "Ruaw"
function5("Walk This Way") "Wathwa"
function5("run away") "Ruaw"
function5("I love puppies") "Ilopu"
~~~~
====
Expand All @@ -322,12 +341,17 @@ To check that you understand what the function is doing please enter the expecte
class myTests(TestCaseGui):

def testOne(self):
self.assertEqual(function5("Walk this way"), "Wathwa" , "function4('Walk this way')")
self.assertEqual(function5_ac("Run Away"), "Ruaw", "function4('Run Away')")
self.assertEqual(function5("Walk This Way"), "Wathwa" , "function4('Walk This Way')")
self.assertEqual(function5("run away"), "Ruaw", "function4('run away')")
self.assertEqual(function5("I love puppies"), "Ilopu", "function4('I love puppies')")
self.assertEqual(function5("A long time ago"), "Alotiag", "function4('A long time ago')")
self.assertEqual(function5("It was a fish"), "Itwaafi", "function4('It was a fish')")
self.assertEqual(function5("Trust Me"), "Trme", "function4('Trust Me')")
self.assertEqual(function5("I am a fish"), "Iamafi", "function4('I am a fish')")
self.assertEqual(function5("over and under"), "Ovanun", "function4('over and under')")
self.assertEqual(function5("Where am I"), "Whami", "function4('Where am I')")
self.assertEqual(function5("I am an old fish"), "Iamanolfi", "function4('I am an old fish')")
self.assertEqual(function5("with love"), "Wilo", "function4('with love')")

myTests().main()

If you worked in a group, you can copy the answers from this page to the other group members. Select the group members below and click the button to share the answers.
Expand Down

0 comments on commit a377310

Please sign in to comment.