Giter Site home page Giter Site logo

tripplanner's Introduction

TripPlanner

Given a stack of boarding cards for various transportations that will take you from a point A to point B via several stops on the way. All of the boarding cards are out of order and don't know where your journey starts, nor where it ends. So TripPlanner sort those trips.

Setup

To setup one need to have composer and run composer install. Composer is only being used for auto-loading purpose and installing one dependency that is phpspec.

Also run composer dump-autoload.

Usage

Card Format

Card will be available as Associative Array, following is a sample format:

[
    'from' => 'Barcelona',
    'to' => 'Gerona Airport',
    'transport' => [
        'medium' => 'AirportBus',
        'seat' => 'No seat assignment'
    ]
]

Transport can have more or different attributes depends on medium. Here medium specifies different transport types.

API Usage

You can get Trip Description in sorted order using following code, please note that usage.php is example of this API's usage.

$trip = new Trip;
$sortedCards = $trip->sortCards($cards);

$cardManager = new CardManager;
$tripDescription = $trip->getTripDescriptionFromCards($cardManager, $sortedCards);

Here $cards contains array of unsorted cards.

Adding more Transport Types

Any type of Transport implementation must implement Transport interface and provide implementation for:

public function getBoardingCardInfo($card);

and this method should return boarding card info.

In order to adding more transport types, you will also need to add more or different attributes in card's transport associative array. And medium property in transport associative array must have same name as new Transport Class name.

##Tests We are using phpspec for testing purpose which was installed with composer. To run tests use following command: vendor/bin/phpspec run and it will run all tests in specs directory. As tests are unit tests so dependencies are mocked.

##Further More Other than that code can be found in src directory and Tests can be found in spec directory.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.