Install, run, and test by simply following the instructions in the given README.
This project is simulating a car race between three different types of cars on the Infinitely Long Road (ILR), which are fast car, slow car, and fancy car. All of the cars can only travel in a straight line on the ILR. All of these cars also have the same base as a basic/average car, however, they have different attributes such as acceleration, max speed, and break efficiency. Users can customize the car's attributes such as break efficiency, acceleration, and max speed. The cars can access their engine status, headlights status, current speed, distance from home, total distance travelled in the current trip, and current gear by checking their dashboard.
(Slow car feeling lonely and driving out into the infinite nothingness made me tear up)
- Unzip the file called
brain_corp_project.zip - Install Python 3.x on your machine if you haven't already. My local environment was running Python 3.9.7.
- Load the project into a code editor such as Visual Studio Code.
- Navigate to the project directory in the terminal, which should be
brain_corp_project. - Install the required packages
pip install pytest- to run tests/test_race.py
This is the file hierarchy for this project. Please maintain this file hierarchy for the project and commands to work as intended.
- brain_corp_project
- main.py
- base_car.py
- fast_car.py
- fancy_car.py
- slow_car.py
- README.md
- Internship_Take_Home_Test.md
- tests/
- test_race.py
Inside the file main.py, and inside the main() function is where the race events are described.
To start the race between Fancy Car, Fast Car, and Slow Car, run the following code in the terminal while inside the brain_corp_project directory.
python main.py
Once the race starts, the statistics of each car will be printed in the terminal, whenever 'x'_car.check_dashboard() is called during the race inside main().
-
To add or edit features of an average car, you can make changes inside the file
base_car.py -
base_car.pycontains the following:- Class Car:
- init()
- turn_on() - turn on engine
- turn_off() - turn off engine
- gas() - accelerates for n seconds
- drive() - drives at speed for n seconds
- brake() - decelerates for n seconds
- fullstop() - sets speed to 0
- headlights() - toggle headlights
- check_dashboard() - display car stats
- Class Car:
-
To make changes to the features of each particular type of car, you can modify code inside
fast_car.py, slow_car.py, fancy_car.py. -
fast_car.pycontains the following:- Class FastCar:
- init()
- gearchange() - check that gear cannot change to "Reverse"
- race() - simulate race conditions
- Class FastCar:
-
fancy_car.pycontains the following:- Class FancyCar:
- init()
- horn() - toggle horn
- gearchange() - change gears
- race() - simulate race conditions
- Class FancyCar:
-
slow_car.pycontains the following:- Class SlowCar:
- init()
- gearchange() - check that gear cannot change to "Reverse"
- race() - simulate race conditions
- Class SlowCar:
-
To make changes to the race events, you can edit the code inside
main()insidemain.py. -
main.pycontains the following:- main() - define race events
-
Make sure to test code inside
/tests/test_race.py, by adding tests for the additional or edited features. -
test_race.pycontains the following:- test_invalid_sgear_change()
- test_invalid_engine_off()
- test_move_not_in_gear()
- test_headlight_on_with_engine_off()
- test_max_speed()
- test_speed_gear_change()
- test_valid_gear_change()
- test_reverse_positive_speed()
- test_car_race()
Use tests/test_race.py file to check that the cars features are working as intended, and to test the different edge cases such as changing gears when speed is not 0, or turning off the car when speed is not 0, no reverse gear for fast car and slow car, and asserting that the race conditions are accurate.
Make sure that you have already have pytest installed, or if not then run pip install pytest.
then when inside the root directory of the project, which is /brain_corp_project, run the following command:
pytest tests/test_race.py
This should run pytest on test_race.py which will check for the conditions mentioned in Average Car Features and Stats as well as additional car features, and should return if test cases passed or failed.