From faa0a7a2d31bf9de9f1d8f678c657f7b14cdcce7 Mon Sep 17 00:00:00 2001 From: Steve Davis Date: Sat, 16 Jul 2016 11:54:25 -0400 Subject: [PATCH] Add my_ratio function. --- sprint_tutorial/compute.py | 5 +++++ sprint_tutorial/tests/test_compute.py | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/sprint_tutorial/compute.py b/sprint_tutorial/compute.py index 1e6cdf8..0628206 100644 --- a/sprint_tutorial/compute.py +++ b/sprint_tutorial/compute.py @@ -20,3 +20,8 @@ def my_root(a, n=2): """ Compute the nth root of a """ res = a**(1.0/n) return res + +def my_ratio(x, y): + """Compute the ratio of two numbers. + """ + return float(x) / float(y) diff --git a/sprint_tutorial/tests/test_compute.py b/sprint_tutorial/tests/test_compute.py index 3b38971..20efca0 100644 --- a/sprint_tutorial/tests/test_compute.py +++ b/sprint_tutorial/tests/test_compute.py @@ -1,7 +1,7 @@ """ Tests for the compute module """ -from sprint_tutorial.compute import my_sum, my_power +from sprint_tutorial.compute import my_sum, my_power, my_ratio import pytest def test_my_sum(): @@ -18,3 +18,7 @@ def test_my_root(): assert my_root(4) == 2.0 assert my_power(8, 2) == 2.0 +def test_my_ratio(): + assert my_ratio(4, 2) == 2.0 + assert my_ratio(2, 4) == 0.5 +