Skip to content

Instantly share code, notes, and snippets.

@jonaed1230
Last active September 8, 2018 15:27
Show Gist options
  • Save jonaed1230/bae8efca32ad96a126dbdd37cd82ab12 to your computer and use it in GitHub Desktop.
Save jonaed1230/bae8efca32ad96a126dbdd37cd82ab12 to your computer and use it in GitHub Desktop.
Making average of different types input
def average(L):
if not L:
return None
return sum(L)/len(L)
def test_average():
test_cases = [
{
"name": "simple case 1",
"input": [1, 2, 3],
"expected": 2.0
},
{
"name": "simple case 2",
"input": [1, 2, 3, 4],
"expected": 2.0
},
{
"name": "list with one item",
"input": [100],
"expected": 100.0
},
{
"name": "empty list",
"input": [],
"expected": None
}
]
for test_case in test_cases:
assert test_case["expected"] == average(test_case["input"]), test_case["name"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment