{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "nbsphinx": "hidden"
   },
   "outputs": [],
   "source": [
    "#Please execute this cell\n",
    "import sys;\n",
    "sys.path.append('../../../'); \n",
    "import jupman;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Exam _JM_{exam.date_human}\n",
    "\n",
    "**_JM_{conf.jm.course} - _JM_{conf.jm.degree}**\n",
    "\n",
    "\n",
    "## [Download exercises and solutions](../../../_static/generated/_JM_{conf.jm.filename}-_JM_{exam.date}-exam.zip) \n",
    "\n",
    "(This obviously should only be shown when after the exam is published)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Introduction\n",
    "\n",
    "* **Taking part to this exam erases any vote you had before**\n",
    "\n",
    "![](img/mountains.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "### Grading\n",
    "\n",
    "\n",
    "* **Lab grade:** The grade of this lab part will range from 0 to 30. Total grade for the module will be given by the average with the theory part of Alberto Montresor.\n",
    "* **Correct implementations**: Correct implementations with the required complexity grant you full grade.\n",
    "* **Partial implementations**: Partial implementations _might_ still give you a few points. If you just can't solve an exercise,  try to solve it at least for some subcase (i.e. array of fixed size 2) commenting why you did so. \n",
    "* **Bonus point**: One bonus point can be earned by writing stylish code. You got style if you:\n",
    "\n",
    "    - do not infringe the [Commandments](../../index.ipynb#Commandments)\n",
    "    - write [pythonic code](http://docs.python-guide.org/en/latest/writing/style)\n",
    "    - avoid convoluted code like i.e.\n",
    "\n",
    "        ```\n",
    "        if x > 5:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "        ```\n",
    "\n",
    "        when you could write just\n",
    "\n",
    "        ```\n",
    "        return x > 5\n",
    "        ```       \n",
    "\n",
    "### Valid code"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "scrolled": true
   },
   "source": [
    "<div class=\"alert alert-warning\">\n",
    "\n",
    "**WARNING**: MAKE SURE ALL EXERCISE FILES AT LEAST COMPILE !!! \n",
    "10 MINS BEFORE THE END OF THE EXAM I WILL ASK YOU TO DO A FINAL CLEAN UP OF THE CODE \n",
    "</div>\n",
    "\n",
    "\n",
    "\n",
    "<div class=\"alert alert-warning\">\n",
    "\n",
    "**WARNING**: _ONLY_ IMPLEMENTATIONS OF THE PROVIDED FUNCTION SIGNATURES WILL BE EVALUATED !!!!!!!!! <br/>    \n",
    "\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "For example, if you are given to implement: \n",
    "\n",
    "```python\n",
    "    def f(x):\n",
    "        raise Exception(\"TODO implement me\")\n",
    "```\n",
    "\n",
    "and you ship this code:\n",
    "\n",
    "``` python\n",
    "def my_f(x):\n",
    "    # a super fast, correct and stylish implementation\n",
    "\n",
    "def f(x):\n",
    "    raise Exception(\"TODO implement me\")\n",
    "```\n",
    "\n",
    "We will assess only the latter one `f(x)`, and conclude it doesn't work at all :P   !!!!!!!\n",
    "\n",
    "**Helper functions**\n",
    "\n",
    "Still, you are allowed to define any extra helper function you might need. If your `f(x)` implementation calls some other function you defined like `my_f` here, it is ok:\n",
    "\n",
    "```python\n",
    "# Not called by f, will get ignored:\n",
    "def my_g(x):\n",
    "    # bla\n",
    "\n",
    "# Called by f, will be graded:\n",
    "def my_f(y,z):\n",
    "    # bla\n",
    "\n",
    "def f(x):\n",
    "    my_f(x,5)\n",
    "    \n",
    "\n",
    "```\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "<div class=\"alert alert-info\">\n",
    "\n",
    "**IMPORTANT**: Pay close attention to the comments of the functions.\n",
    "</div>\n",
    "\n",
    "<div class=\"alert alert-warning\">\n",
    "\n",
    "**WARNING**: _DON'T_ modify function signatures! Just provide the implementation.\n",
    "</div>\n",
    "\n",
    "<div class=\"alert alert-warning\">\n",
    "\n",
    "**WARNING**: <i>DON'T</i> change the existing test methods, just add new ones !!!  You can add as many as you want.\n",
    "</div>\n",
    "\n",
    "<div class=\"alert alert-warning\">\n",
    "\n",
    "**WARNING**: _DON'T_ create other files. If you still do it, they won't be evaluated.\n",
    "</div>\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Debugging \n",
    "\n",
    "If you need to print some debugging information, you are allowed to put extra <code>print</code>\n",
    "    statements in the function bodies."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "<div class=\"alert alert-warning\">\n",
    "\n",
    "**WARNING:** even if print statements are allowed, be careful with prints that might\n",
    "     break your function! \n",
    "</div>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For example, avoid stuff like this: \n",
    "\n",
    "```python\n",
    "x = 0\n",
    "print(1/x)\n",
    "```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### What to do\n",
    "\n",
    "1) Download  `_JM_{conf.jm.filename}-_JM_{exam.date}-exam.zip` and extract it <b>on your desktop</b>. Folder content should be like this:\n",
    "\n",
    "```\n",
    "_JM_{conf.jm.filename}-_JM_{exam.date}-FIRSTNAME-LASTNAME-ID\n",
    "   exam-_JM_{exam.date}.ipynb   \n",
    "   lists.py\n",
    "   lists_test.py\n",
    "   trees.py\n",
    "   trees_test.py\n",
    "   jupman.py\n",
    "            \n",
    "```\n",
    "\n",
    "2) Rename `_JM_{conf.jm.filename}-_JM_{exam.date}-FIRSTNAME-LASTNAME-ID` folder: put your name, lastname an id number, like `_JM_{conf.jm.filename}-_JM_{exam.date}-john-doe-432432`\n",
    "\n",
    "From now on, you will be editing the files in that folder. At the end of the exam, that is what will be evaluated.\n",
    "\n",
    "3) Edit the files following the instructions in this worksheet for each exercise. Every exercise should take max 25 mins. If it takes longer, leave it and try another exercise.\n",
    " \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Part A\n",
    "\n",
    "Open Jupyter and start editing this notebook `exam-_JM_{exam.date}-exercise.ipynb`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A.1 rev\n",
    "\n",
    "Implement rev, which takes a list and RETURN the reverse"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def rev(lst):\n",
    "    #jupman-raise\n",
    "    return list(reversed(lst))\n",
    "    #/jupman-raise\n",
    "    \n",
    "assert rev(['a','c','b']) == ['b','c','a']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A.2 bla\n",
    "\n",
    "Implement function `bla`, which prints 'bla'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def bla():\n",
    "    #jupman-raise\n",
    "    print('bla')\n",
    "    #/jupman-raise"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Part B \n",
    "\n",
    "To edit the files for this part, you can use any editor of your choice,  you can find them under _Applications->Programming_:\n",
    "\n",
    "* **Visual Studio Code**\n",
    "* Editra is easy to use, you can find it under _Applications->Programming->Editra_.\n",
    "* Others could be _GEdit_ (simpler), or _PyCharm_ (more complex).\n",
    "\n",
    "To run the tests, use **the Terminal** which can be found in _Accessories -> Terminal_ "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## B.1 `do_something`\n",
    "\n",
    "Open the file `lists.py` and implement the method `do_something`:\n",
    "\n",
    "```python\n",
    "\n",
    "    def do_something(self):\n",
    "        \"\"\" Does something \"\"\"\n",
    "        \n",
    "     \n",
    "```\n",
    "\n",
    "**Testing** `python3 -m unittest lists_test.DoSomething`\n",
    "\n",
    "**Example**: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "from lists_sol import *\n",
    "\n",
    "mc = MyClass()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## B.2 `draw`\n",
    "\n",
    "Open the file trees and implement the method `draw`:\n",
    "\n",
    "```python\n",
    "\n",
    "    def draw(self):\n",
    "        \"\"\" Does something \"\"\"     \n",
    "     \n",
    "```\n",
    "\n",
    "**Testing** `python3 -m unittest trees_test.DoSomething`\n",
    "\n",
    "**Example**:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I'm drawing an amazing tree\n"
     ]
    }
   ],
   "source": [
    "from trees_sol import draw\n",
    "\n",
    "draw()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "nbsphinx": "hidden"
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "..\n",
      "----------------------------------------------------------------------\n",
      "Ran 2 tests in 0.002s\n",
      "\n",
      "OK\n",
      "."
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Doing something else\n",
      "Doing something\n",
      "I'm drawing an amazing tree\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n",
      "----------------------------------------------------------------------\n",
      "Ran 1 test in 0.001s\n",
      "\n",
      "OK\n"
     ]
    }
   ],
   "source": [
    "import lists_test\n",
    "import trees_test\n",
    "jupman.run(lists_test)\n",
    "jupman.run(trees_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "celltoolbar": "Edit Metadata",
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.7.13"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
