Skip to content

amansingh1720/Farrari-Racing-Cars

Repository files navigation

One Car, Two Car, Fast Car, Slow Car

Install, run, and test by simply following the instructions in the given README.

The program is built using object-oriented programming principles in python.

Description

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)

Installation

  1. Unzip the file called brain_corp_project.zip
  2. Install Python 3.x on your machine if you haven't already. My local environment was running Python 3.9.7.
  3. Load the project into a code editor such as Visual Studio Code.
  4. Navigate to the project directory in the terminal, which should be brain_corp_project.
  5. Install the required packages
    • pip install pytest - to run tests/test_race.py

Directory Structure

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

Usage

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().

Functions/Contributing/Additions

  1. To add or edit features of an average car, you can make changes inside the file base_car.py

  2. base_car.py contains 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
  3. 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.

  4. fast_car.py contains the following:

    • Class FastCar:
      • init()
      • gearchange() - check that gear cannot change to "Reverse"
      • race() - simulate race conditions
  5. fancy_car.py contains the following:

    • Class FancyCar:
      • init()
      • horn() - toggle horn
      • gearchange() - change gears
      • race() - simulate race conditions
  6. slow_car.py contains the following:

    • Class SlowCar:
      • init()
      • gearchange() - check that gear cannot change to "Reverse"
      • race() - simulate race conditions
  7. To make changes to the race events, you can edit the code inside main() inside main.py.

  8. main.py contains the following:

    • main() - define race events
  9. Make sure to test code inside /tests/test_race.py, by adding tests for the additional or edited features.

  10. test_race.py contains 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()

Testing

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.

About

This project is simulating a car race between three different types of cars on the Infinitely Long Road (ILR). Each car has customizable attributes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages