diff --git a/.github/workflows/limit-size.yml b/.github/workflows/limit-size.yml new file mode 100644 index 0000000..be15436 --- /dev/null +++ b/.github/workflows/limit-size.yml @@ -0,0 +1,16 @@ +name: Limit complexity + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Install lizard + run: pip install lizard + + - name: Limit complexity + run: $HOME/.local/bin/lizard --CCN 3 \ No newline at end of file diff --git a/__pycache__/alerts.cpython-38.pyc b/__pycache__/alerts.cpython-38.pyc new file mode 100644 index 0000000..5c988ca Binary files /dev/null and b/__pycache__/alerts.cpython-38.pyc differ diff --git a/__pycache__/statistics.cpython-38.pyc b/__pycache__/statistics.cpython-38.pyc new file mode 100644 index 0000000..209607b Binary files /dev/null and b/__pycache__/statistics.cpython-38.pyc differ diff --git a/alerts.py b/alerts.py new file mode 100644 index 0000000..6ba8d67 --- /dev/null +++ b/alerts.py @@ -0,0 +1,31 @@ +import statistics + +# below: alerts tests + +class EmailAlert: + + def __init__(self): + self.emailSent = False # by default + +class LEDAlert: + + def __init__(self): + self.ledGlows = False # by default + +class StatsAlerter: + + def __init__(self, maxThresh, alertArrs): + + self.maxThresh = maxThresh + self.alertArrs = alertArrs + self.emailAlert = self.alertArrs[0] + self.ledAlert = self.alertArrs[1] + + def checkAndAlert(self, numbers): + + stats = statistics.calculateStats(numbers) + + if stats["max"] > self.maxThresh: + + self.emailAlert.emailSent = True + self.ledAlert.ledGlows = True \ No newline at end of file diff --git a/statistics.py b/statistics.py index fda1724..fe03d04 100644 --- a/statistics.py +++ b/statistics.py @@ -1,3 +1,18 @@ +import math +from turtle import st def calculateStats(numbers): - return None + + stats = dict(zip(["avg", "max", "min"], [math.nan, math.nan, math.nan])) + + if type(numbers) != list: + + return None + + if len(numbers) != 0: + + stats["avg"] = round((sum(numbers) / len(numbers)), 3) + stats["max"] = max(numbers) + stats["min"] = min(numbers) # min_max_report test + + return stats \ No newline at end of file diff --git a/statistics.test.py b/statistics.test.py index cb914d6..6babe61 100644 --- a/statistics.test.py +++ b/statistics.test.py @@ -1,5 +1,7 @@ +from cmath import isnan import unittest import statistics +import alerts class StatsTest(unittest.TestCase): def test_report_min_max_avg(self): @@ -15,12 +17,20 @@ def test_avg_is_nan_for_empty_input(self): # nan (not-a-number), as defined in the math package # Design the assert here. # Use nan and isnan in https://docs.python.org/3/library/math.html + self.assertTrue(isnan(computedStats["avg"])) + self.assertTrue(isnan(computedStats["max"])) + self.assertTrue(isnan(computedStats["min"])) + + def test_invalid_arg_returns_None(self): + # tests if calculateStats returns None on receiving non-array argument for 'numbers' + computedStats = statistics.calculateStats("a string") + self.assertTrue((computedStats == None), None) def test_raise_alerts_when_max_above_threshold(self): - emailAlert = EmailAlert() - ledAlert = LEDAlert() + emailAlert = alerts.EmailAlert() # added statistics module identifier for class instantiation + ledAlert = alerts.LEDAlert() maxThreshold = 10.5 - statsAlerter = StatsAlerter(maxThreshold, [emailAlert, ledAlert]) + statsAlerter = alerts.StatsAlerter(maxThreshold, [emailAlert, ledAlert]) statsAlerter.checkAndAlert([22.6, 12.5, 3.7]) self.assertTrue(emailAlert.emailSent) self.assertTrue(ledAlert.ledGlows)