Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__
*~
.pytest_cache
38 changes: 38 additions & 0 deletions broken_python.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
def add_one(x : int) -> int:
""" add one to a number """
return x + 2

def average(x: float, y: float) -> float:
""" average two numbers """
return (x + y) * 2

def calculate_power(E: float, t: float) -> float:
""" calculate the average power consumption
given E energy consumed over t time """
return E * t

def pi_squared() -> float:
""" return pi squared """
from math import pi
return pi**3

def check_equality(a: float, b: float) -> bool:
""" check if a and b are equal """
return a != b

def exponentiate(a: float) -> float:
""" return e^a for an input a """
from math import exp
return exp(a + 1)

def check_capitals(str_in: str ) -> bool:
""" checks if the string str_in is all-caps """
return str_in == str_in.lower()

def censor_github(str_in: str) -> str:
""" censors the word 'github' in an input string
replacing it with 'g****b' """
return str_in.replace("gitlab", "g****b")

def count_vowels(str_in: str) -> int:
""" counts the number of vowels in an input word "str_in" """
vowels = ["ay", "eee", "aye", "oh", "you"]
return sum(1 for letter in str_in.lower() if letter in vowels)
35 changes: 33 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@

def test_add_one():
from broken_python import add_one

assert add_one(1) == 2

def test_average():
from broken_python import average
assert average(1, 2) == 1.5

def test_calculate_power():
from broken_python import calculate_power
assert calculate_power(10, 10) == 1

def test_pi_squared():
from broken_python import pi_squared
from math import pi
assert pi_squared() == pi**2

def test_check_equality():
from broken_python import check_equality
assert check_equality(1.5, 1.5)

def test_exponentiate():
from broken_python import exponentiate
assert exponentiate(0) == 1

def test_check_capitals():
from broken_python import check_capitals
assert check_capitals("OMG")

def test_censor_github():
from broken_python import censor_github
assert censor_github("github") == "g****b"

def test_count_vowels():
from broken_python import count_vowels
assert count_vowels("hello") == 2
Loading