gotunitsosidays2011 111121093234-phpapp02

44
Got units? Bengaluru, 20-22 November 2011

Upload: opensourceindia

Post on 18-May-2015

894 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Gotunitsosidays2011 111121093234-phpapp02

Got units?Bengaluru, 20-22 November 2011

Page 2: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

TDD

Page 3: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

REDadd a test, it won't pass

Page 4: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

GREENimplement the necessary code to make the test pass

Page 5: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

REFACTORpolish the code

Page 6: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

TDD-ing Dijkstra'sshortest path algorithm

in PHP

Page 7: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Page 8: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Page 9: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Page 10: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Page 11: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Page 12: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Page 13: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Page 14: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Page 15: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Page 16: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

github.com/odino/osidays

Page 17: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

git checkout $step

Page 18: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 0/1● create the directory structure● add Symfony2 classloader as submodule● init and update submodule● (optional) create an empty class

Page 19: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 2● write the test with the smallest

amount of code you think it'snecessary

Page 20: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 3● add the Vertex class● add the Graph class● add an empty solve() method

for the algorithm class

Page 21: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 4● implement the solve method

Page 22: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 5● added all the methods

needed by the Dijkstra::solve()● need to implement Graph::calculatePotentials()

Page 23: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 6● a test is added for the Graph class

Page 24: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 7● calculatePotentials() is tested● half of our test-suite passes● switch back to the Dijkstra's test

Page 25: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 8● minor tweaks to make all the tests pass

Page 26: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 9● potentials are assigned in the Graph class

but they should belong to the algorithm,what about refactoring the code?

● since we move the only tested method of Graphinto Dijkstra's class, we can delete the GraphTest

Page 27: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 10● since we like to be OO, we can connect

vertices through objects, and notarrays anymore

Page 28: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 11● we now need to fix the code which

uses vertices' connections as arrays

Page 29: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 12● the library seems pretty complete● PHPDoc is added

Page 30: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 13● Oooops, we forgot to test a scenario:

in Dijkstra's algorithm we need verticesconnected by positive distance

● a test is added, verifying an exceptionis raised through annotations

Page 31: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 14● implementation

Page 32: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 15● enter Mocking objects

Page 33: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 16● Dijkstra::getGraph() seems to be useless

so we probably don't need any Graph class

Page 34: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 17● removed Graph class

Page 35: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 18● some tests rely on it, so we need to

eliminate old references to Graph

Page 36: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 19● enter Data Providers

Page 37: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 20● what about calculating the path between

not-connected vertices?It should return null, so code is refactored

Page 38: Gotunitsosidays2011 111121093234-phpapp02

Bengaluru, 20-22 November 2011

Step 21● Dijkstra::solve() seems to do too

much things, so we split the method● first demand potentials' calculation● second demand path finding● third demand raising the negative-potentials'

exception● enter phploc● enter code-coverage

Page 39: Gotunitsosidays2011 111121093234-phpapp02

Alessandro Nadalin

Bengaluru, 20-22 November 2011

Page 40: Gotunitsosidays2011 111121093234-phpapp02

odino.org

Bengaluru, 20-22 November 2011

Page 41: Gotunitsosidays2011 111121093234-phpapp02

a

Bengaluru, 20-22 November 2011

Page 42: Gotunitsosidays2011 111121093234-phpapp02

a

Bengaluru, 20-22 November 2011

@_odino_ #osidays

Page 43: Gotunitsosidays2011 111121093234-phpapp02

a

Bengaluru, 20-22 November 2011

REST in peace: tomorrow, 12.45

Page 44: Gotunitsosidays2011 111121093234-phpapp02

a

Bengaluru, 20-22 November 2011

@_odino_

Thank YOU!