Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/limit-size.yml
Original file line number Diff line number Diff line change
@@ -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
Binary file added __pycache__/alerts.cpython-38.pyc
Binary file not shown.
Binary file added __pycache__/statistics.cpython-38.pyc
Binary file not shown.
31 changes: 31 additions & 0 deletions alerts.py
Original file line number Diff line number Diff line change
@@ -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
17 changes: 16 additions & 1 deletion statistics.py
Original file line number Diff line number Diff line change
@@ -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
16 changes: 13 additions & 3 deletions statistics.test.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test added 👍

# 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)
Expand Down