Parking Lot Problem

Design a parking lot system which supports multiple features. It uses OOPS concepts and TDD approach.

Parking Lot Problem

GitHub license GitHub last commit Snyk Vulnerabilities for GitHub Repo Travis (.org)

About Problem

To design a parking lot system with ability to find:

Parking Lot

Pre requisites

GitHub top language GitHub code size in bytes CodeFactor Grade

The source code for this project is written using Node.js. Make sure you have Node.js installed on your computer before running this application, if not please install Node.js from here.

To check if you have Node.js and NPM installed by running simple commands to see what version of each is installed:

Note: Node installer installs both Node.js and npm on your system.

How to run?

This is a console application written in Node.js. This can be run in two modes:

  1. Interactive Mode: An interactive terminal based shell where commands can be typed in to perform different actions.

  2. File Mode: It accepts a filename as a parameter at the terminal and read the commands from that file.

Quick Start

Proceed to the steps below only if you’ve Node.js installed. If not, please refer pre requisites section.

For Interactive Mode

Open terminal and navigate (cd) to this folder and type the following commands:

1. npm install
2. npm start

For File Mode

Open terminal and type node src/index.js data/input.txt.

node src/index.js <path_to_file.txt>

Note: You can find a few sample input files inside data/ folder.

Explained

STEP 1: npm install or npm i will download all the dependencies defined in package.json file and generate a node_modules/ folder with the installed modules. Learn more here.

STEP 2: npm start or npm run start will start the application. It is equivalent to node src/index.js

Console Application

Navigate to bin/ folder and open parking_lot with double click. It’ll open a terminal where different commands can be typed in. You may face permission related issues, please allow opening applications from unauthorized developers as it’s blocked due to security reasons. If you’re using macOS catalina, you’ll be prompted security warning as this binary is not notarized. Learn more about Notarization here.

If you’re still facing issues, please build the console application locally. Kindly refer Build Script section to build locally.

List of User Commands

Users can interact with the Parking Lot system via a following simple set of commands which produce a specific output:

Slot No.  Registration No Color
1         KA-01-HH-1234  White
2         KA-01-HH-9999  Red
3         KA-01-BB-0001  White
5         KA-01-HH-2701  Black
6         KA-01-HH-3141  Black

NOTE: Any commands which are not mentioned above will throw an error: <INPUT> is an invalid command

To view all the commands in terminal, please run npm run help

Modules - OOPS Approach

CodeFactor Codacy Badge

There are two classes defined:

ParkingLot(): It is the main class which is used to initialize a parking lot. In each parking lot there is maximum number of slots and an array of slots that will be occupied by the car. It has following methods:

Car()

Note: I’ve made an assumption that the registration number for two cars can never be same.

Test Scripts

Tests are written using Mocha and can be run using npm test

Unit tests

Unit tests are written for the methods of ParkingLot class.

System tests

System tests mainly include repository structure tests. It tests for the following:

Repository must contain:

package.json

.gitignore must contain build/, dist/, out/, node_modules/ folders.

Lint tests

npm run test-lint is used to run JavaScript lint tests. It detects the coding style issues. ESLint rules are defined in .eslintrc.js file.

node_modules/eslint/bin/eslint.js --fix src/ can be run to fix lint errors.

Code Coverage

To see code coverage report, run npm run test.

The current code coverage for the tests are following:

Type Percentage
Statement 91.48
Branch 69.57
Function 89.53
Lines 91.25

NOTE: Code coverage is added to the mocha tests (npm run test) using nyc. You can see the code-coverage report in terminal as well as detailed HTML report inside coverage/ folder. Go to coverage/ folder and open index.html.

Build Script

npm run build will build the executable(console application) inside bin/ folder which can be opened by double clicking on it. Make sure you’ve already done with npm install, if not, please install dependencies first. Please refer this section for the same.

Note: pkg is used to package the Node.js application into an executable. Learn more here.

Documentation

Writing code is easy but maintaining isn’t? One can read one’s code but it’s difficult for others to read. With this spirit, I’ve added JSDoc comments in code.

Go to out/ folder and open global.html. You’ll find the documentation for the source code there.

To generates the docs locally, open terminal and run npm run create-docs.

Dependencies Used

Dev dependencies

Screenshots

Please go to screenshots/ folder to find screenshots of running Parking Lot console application.

Click here to view e2e working demo video.

TL; DR

Here’s the cheat sheet for you!

Open terminal and type the following:

  1. cd parking_lot : Navigates to the parking_lot root folder.

  2. npm install : Installs all the dependencies.

  3. npm run start : Starts the console application in interactive mode.

  4. npm run test : Runs all the tests.

  5. npm run test-unit : Runs all the unit tests.

  6. npm run test-system : Runs system tests.

  7. npm run test-lint : Runs lint test.

  8. npm run build : Builds the application in bin/ directory.

  9. npm run create-docs : Creates documentation inside out/ folder.

  10. npm run help : Displays all supported user commands.

  11. node src/index.js data/input.txt : Runs the application in file mode.

Need help?

Twitter URL GitHub stars

Feel free to reach out to me via email. Shoot your doubts at vinitshahdeo@gmail.com.

Glad to see you here! Show some ❤️ by starring this repository.

Author

Vinit Shahdeo

Twitter Badge GitHub followers



if (isAwesome) {
    // thanks in advance :p
    starThisRepository();
}



  _____ _                 _     __   __          
 |_   _| |__   __ _ _ __ | | __ \ \ / /__  _   _ 
   | | | '_ \ / _` | '_ \| |/ /  \ V / _ \| | | |
   | | | | | | (_| | | | |   <    | | (_) | |_| |
   |_| |_| |_|\__,_|_| |_|_|\_\   |_|\___/ \__,_|
                                                 


NETFLIX SMILE BUILT WITH LOVE