# Return Function Tests

Each example assumes the students file name is `example#.py` replacing # with the actual example number.  You can call the functions by importing the student file name of your choice.&#x20;

## Example 1 - Add Five

Students write an function named `add_five()` that takes an integer as a parameter and returns 5 plus the parameter value.&#x20;

#### **Grading Tests:**

```java
import unittest

class CodingRoomsUnitTests(unittest.TestCase):

    def test_default_case(self):
        import example1
        self.assertEqual(10, example1.add_five(5))
        self.assertEqual(5, example1.add_five(0))
        self.assertEqual(11, example1.add_five(6))
```

#### Sample Solution:

{% code title="example1.py" %}

```python
def add_five(number):
    number += 5
    return number
```

{% endcode %}

## Example 2 - Average

Students write a function that takes 5 values as parameters and returns the average value of the 5 values.  The function must be named `average()` and it must have 5 parameters.&#x20;

Example: Calling `average(1, 5, 7, 4, 10)` would return `5.4`.

Note: Almost Equal assertion is used with a delta value as tolerance when comparing values.

#### **Grading Tests:**

```python
import unittest
import sys, io

class CodingRoomsUnitTests(unittest.TestCase):

    def test_default_case(self):
        import example2
        self.assertAlmostEqual(5.4, example2.average(1, 5, 7, 4, 10), delta=0.001)
        self.assertAlmostEqual(9.6, example2.average(5, 9, 24, 6, 4), delta=0.001)
       
if __name__ == '__main__':
    unittest.main()
```

#### Sample Solution:

{% code title="example2.py" %}

```python
def average(a, b, c, d, e):
    sum = a + b + c + d + e
    return sum / 5
```

{% endcode %}

## Example 3 - Repeats

Students write a function that takes a parameter. If the String parameter has a double letter (i.e. contains the same letter twice in a row) then it should return true. Otherwise, it should return false.

This function must be named `has_repeat()` and have a parameter. This function must return a `boolean`.

#### **Grading Tests:**

```python
import unittest
import sys, io

class CodingRoomsUnitTests(unittest.TestCase):

    def test_default_case(self):
        import example3
        self.assertTrue(example3.has_repeat("mississippi"))
        self.assertFalse(example3.has_repeat("capsized"))
        self.assertTrue(example3.has_repeat("mazzone"))
        self.assertFalse(example3.has_repeat("this"))
       
if __name__ == '__main__':
    unittest.main()
```

#### Sample Solution:

{% code title="example3.py" %}

```python
def has_repeat(word):
    count = 0
    for letter in word:
        if letter == word[count-1]:
            return True
        count += 1
    return False
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://auto-grade.joemazzone.net/python/return-functions-tests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
