|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "from gofer.ok import check" |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "markdown", |
| 14 | + "metadata": {}, |
| 15 | + "source": [ |
| 16 | + "# Gofer Grader Demo\n", |
| 17 | + " \n", |
| 18 | + "Gofer uses the ok test format to autograde notebook solutions. Below is the test file for this notebook, located in `tests/demo.ok`. In short, the test file contains python code to test the value of certain variables. More details are in the documentation, in `ok-test-format.ok`." |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "markdown", |
| 23 | + "metadata": {}, |
| 24 | + "source": [ |
| 25 | + "```\n", |
| 26 | + "test = {\n", |
| 27 | + " 'name': 'Gofer Grader Demo',\n", |
| 28 | + " 'suites': [\n", |
| 29 | + " {\n", |
| 30 | + " 'cases': [\n", |
| 31 | + " {\n", |
| 32 | + " 'code': r\"\"\"\n", |
| 33 | + " >>> # It looks like you didn't give anything the name\n", |
| 34 | + " >>> # seconds_in_a_decade. Maybe there's a typo?\n", |
| 35 | + " >>> 'seconds_in_a_decade' in vars()\n", |
| 36 | + " True\n", |
| 37 | + " \"\"\"\n", |
| 38 | + " },\n", |
| 39 | + " {\n", |
| 40 | + " 'code': r\"\"\"\n", |
| 41 | + " >>> # The number of seconds you computed is too low by at least\n", |
| 42 | + " >>> # a factor of 5.\n", |
| 43 | + " >>> # There are 10 years, some number of days in a year, some\n", |
| 44 | + " >>> # number of hours per day, minutes per hour, and seconds\n", |
| 45 | + " >>> # per minute. For example, this is almost right:\n", |
| 46 | + " >>> # seconds_in_a_decade = 10*365*24*60*60\n", |
| 47 | + " >>> seconds_in_a_decade > 60000000\n", |
| 48 | + " True\n", |
| 49 | + " \"\"\"\n", |
| 50 | + " },\n", |
| 51 | + " {\n", |
| 52 | + " 'code': r\"\"\"\n", |
| 53 | + " >>> # You're close! Perhaps you didn't account for leap years correctly.\n", |
| 54 | + " >>> # There were 2 leap years and 8 non-leap years in this period.\n", |
| 55 | + " >>> # Leap years have 366 days instead of 365.\n", |
| 56 | + " >>> 315360000 < seconds_in_a_decade < 331344000\n", |
| 57 | + " True\n", |
| 58 | + " \"\"\"\n", |
| 59 | + " },\n", |
| 60 | + " {\n", |
| 61 | + " 'code': r\"\"\"\n", |
| 62 | + " >>> seconds_in_a_decade == 315532800\n", |
| 63 | + " True\n", |
| 64 | + " \"\"\"\n", |
| 65 | + " }\n", |
| 66 | + " ]\n", |
| 67 | + " }\n", |
| 68 | + " ]\n", |
| 69 | + "}\n", |
| 70 | + "```" |
| 71 | + ] |
| 72 | + }, |
| 73 | + { |
| 74 | + "cell_type": "markdown", |
| 75 | + "metadata": {}, |
| 76 | + "source": [ |
| 77 | + "Here's a sample question, with a corresponding check.\n", |
| 78 | + " \n", |
| 79 | + "Compute the number of seconds in a decade." |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + "cell_type": "code", |
| 84 | + "execution_count": null, |
| 85 | + "metadata": {}, |
| 86 | + "outputs": [], |
| 87 | + "source": [ |
| 88 | + "seconds_in_a_decade = 1" |
| 89 | + ] |
| 90 | + }, |
| 91 | + { |
| 92 | + "cell_type": "markdown", |
| 93 | + "metadata": {}, |
| 94 | + "source": [ |
| 95 | + "Below is an example of what happens when tests fail. Observe that the comments are printed as well, to give the students feedback on their error." |
| 96 | + ] |
| 97 | + }, |
| 98 | + { |
| 99 | + "cell_type": "code", |
| 100 | + "execution_count": null, |
| 101 | + "metadata": { |
| 102 | + "scrolled": true |
| 103 | + }, |
| 104 | + "outputs": [], |
| 105 | + "source": [ |
| 106 | + "check('tests/demo.ok')" |
| 107 | + ] |
| 108 | + }, |
| 109 | + { |
| 110 | + "cell_type": "markdown", |
| 111 | + "metadata": {}, |
| 112 | + "source": [ |
| 113 | + "Now let's set the correct answer." |
| 114 | + ] |
| 115 | + }, |
| 116 | + { |
| 117 | + "cell_type": "code", |
| 118 | + "execution_count": null, |
| 119 | + "metadata": {}, |
| 120 | + "outputs": [], |
| 121 | + "source": [ |
| 122 | + "seconds_in_a_decade = (365*8 + 366*2) * 24 * 60 * 60" |
| 123 | + ] |
| 124 | + }, |
| 125 | + { |
| 126 | + "cell_type": "markdown", |
| 127 | + "metadata": {}, |
| 128 | + "source": [ |
| 129 | + "Here is an example of a successful test." |
| 130 | + ] |
| 131 | + }, |
| 132 | + { |
| 133 | + "cell_type": "code", |
| 134 | + "execution_count": null, |
| 135 | + "metadata": {}, |
| 136 | + "outputs": [], |
| 137 | + "source": [ |
| 138 | + "check('tests/demo.ok')" |
| 139 | + ] |
| 140 | + }, |
| 141 | + { |
| 142 | + "cell_type": "markdown", |
| 143 | + "metadata": {}, |
| 144 | + "source": [ |
| 145 | + "Feel free to edit `demo.ok` file and add more tests. You can find it in the `tests/` folder in the Jupyter directory. " |
| 146 | + ] |
| 147 | + } |
| 148 | + ], |
| 149 | + "metadata": { |
| 150 | + "kernelspec": { |
| 151 | + "display_name": "Python 3", |
| 152 | + "language": "python", |
| 153 | + "name": "python3" |
| 154 | + }, |
| 155 | + "language_info": { |
| 156 | + "codemirror_mode": { |
| 157 | + "name": "ipython", |
| 158 | + "version": 3 |
| 159 | + }, |
| 160 | + "file_extension": ".py", |
| 161 | + "mimetype": "text/x-python", |
| 162 | + "name": "python", |
| 163 | + "nbconvert_exporter": "python", |
| 164 | + "pygments_lexer": "ipython3", |
| 165 | + "version": "3.7.1" |
| 166 | + } |
| 167 | + }, |
| 168 | + "nbformat": 4, |
| 169 | + "nbformat_minor": 2 |
| 170 | +} |
0 commit comments