Files
learn-python3/notebooks/beginner/exercises/08_testing1_exercise.ipynb
Jerry Pussinen fb4b0e6be9 Add numbering and regenerate html
Also fixed some ipytest things
2023-04-19 10:22:59 +03:00

82 lines
1.8 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Required boilerplate\n",
"import sys\n",
"\n",
"!{sys.executable} -m pip install pytest\n",
"!{sys.executable} -m pip install ipytest\n",
"\n",
"import ipytest.magics\n",
"import pytest\n",
"\n",
"__file__ = \"testing1_exercise.ipynb\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 1. Creating your first test case\n",
"There is an implementation for `get_divisible_by_five` function in the cell below. Your task is to create a test case for this function to verify that it works correctly.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"editable": false
},
"outputs": [],
"source": [
"def get_divisible_by_five(numbers):\n",
" \"\"\"Returns a list of numbers which are divisible by five in the list got as an argument\"\"\"\n",
" result = []\n",
" for num in numbers:\n",
" if not num % 5:\n",
" result.append(num)\n",
"\n",
" return result"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%run_pytest[clean]\n",
"\n",
"def test_get_divisible_by_five():\n",
" # Your implementation here\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}