diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..55eea97 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +*~ +.pytest_cache diff --git a/broken_python.py b/broken_python.py index 8f0f730..c229722 100644 --- a/broken_python.py +++ b/broken_python.py @@ -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) diff --git a/test.py b/test.py index c839c1d..4344435 100644 --- a/test.py +++ b/test.py @@ -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