diff --git a/challenges/week_1/Readme.md b/challenges/week_1/Readme.md new file mode 100644 index 0000000..430ab42 --- /dev/null +++ b/challenges/week_1/Readme.md @@ -0,0 +1,31 @@ +# Bus Fare Challenge - Week 1 + +## Challenge + +Write a program that does the following: + +1. gets today's date and stores it in a variable `'date'` +2. uses today's date to get the name on the day of the week written in short form with the first letter capitalized eg. `'Fri'` if today were Friday and assigns it a variable `'day'` +3. uses if statements to determine the today's fare following these bus fare schedule: + + - monday - friday --> 100 + - saturday --> 60 + - sunday --> 80 +4. Prints the results in this format + >Date: 2021-01-05 + >Day: Tue + >Fare: 100 + +## Evaluation + +Run the [Checker](checker.py) file to evaluate your code. If all tests pass, your code will be the correct solution. If any fail, check the error messages and make changes to your code and repeat. + +## Note + +1. Your solution must be written in the [bus_fare_challenge](bus_fare_challenge.py) file and its name should never be changed. +2. Your program must make use of the following variable names: + - `'date'` + - `'day'` + - `'fare'` +*Failure to which all your tests will fail.* +3. The **Checker** file should **never** be **altered** at any cost. diff --git a/challenges/week_1/bus_fare_challenge.py b/challenges/week_1/bus_fare_challenge.py new file mode 100644 index 0000000..0b90aa0 --- /dev/null +++ b/challenges/week_1/bus_fare_challenge.py @@ -0,0 +1 @@ +# WRITE YOUR CODE SOLUTION HERE diff --git a/challenges/week_1/checker.py b/challenges/week_1/checker.py new file mode 100644 index 0000000..50020fc --- /dev/null +++ b/challenges/week_1/checker.py @@ -0,0 +1,55 @@ +import bus_fare_challenge +import datetime +import unittest + + +class TestBusFareChallenge(unittest.TestCase): + def setUp(self) -> None: + self.date = datetime.datetime.now().date() + self.day = self.date.strftime("%a") + self.charts = { + "Mon": 100, + "Tue": 100, + "Wed": 100, + "Thu": 100, + "Thu": 100, + "Sat": 60, + "Sun": 80, + } + + def test_date(self) -> None: + """ + Tests whether the date returned by the program is correct. + """ + actual = self.date + given = bus_fare_challenge.date + self.assertEqual(actual, given, f"Today's date is Wrong by {given - actual}!") + + def test_day(self) -> None: + """ + Tests whether the day returned by the program is correct. + """ + actual = self.day + given = bus_fare_challenge.day + self.assertEqual( + actual, given, f"Today is wrong, expexted {actual} but got {given}!" + ) + + def test_fare(self) -> None: + """ + Tests whether the fare returned by the program is correct. + """ + actual = self.charts[self.day] + given = bus_fare_challenge.fare + self.assertEqual( + actual, given, f"Fare is wrong, expected {actual} but got {given}!" + ) + + +if __name__ == "__main__": + print("=========================================================================") + print("=========================================================================") + print("===== Start: Checking Return Values For Today's Date, Day and Fare =====") + unittest.main(exit=False) + print("===== End: Checking Return Values For Today's Date, Day and Fare =======") + print("=========================================================================")