{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import math" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# a more general form of the function \n", "def sector_area(radius1, radius2, angle_deg):\n", " angle_rad = (2 * math.pi / 360) * angle_deg # changing degrees to radians\n", " area = 0.5 * (radius1**2 - radius2**2) * angle_rad\n", " return area" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def test_gt0():\n", " for rad1, rad2, ang in [(2, 1, 30), (10, 5, 270)]:\n", " assert sector_area(rad1, rad2, ang) > 0" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def test_angle0():\n", " assert sector_area(5, 1, 0) == 0" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def test_full():\n", " assert sector_area(5, 0, 360) == math.pi * 25" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [], "source": [ "test_gt0()\n", "test_angle0()\n", "test_full()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "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.2" } }, "nbformat": 4, "nbformat_minor": 1 }