Got units? Bengaluru, 20-22 November 2011
May 08, 2015
Got units?Bengaluru, 20-22 November 2011
Bengaluru, 20-22 November 2011
TDD
Bengaluru, 20-22 November 2011
REDadd a test, it won't pass
Bengaluru, 20-22 November 2011
GREENimplement the necessary code to make the test pass
Bengaluru, 20-22 November 2011
REFACTORpolish the code
Bengaluru, 20-22 November 2011
TDD-ing Dijkstra'sshortest path algorithm
in PHP
Bengaluru, 20-22 November 2011
Bengaluru, 20-22 November 2011
Bengaluru, 20-22 November 2011
Bengaluru, 20-22 November 2011
Bengaluru, 20-22 November 2011
Bengaluru, 20-22 November 2011
Bengaluru, 20-22 November 2011
Bengaluru, 20-22 November 2011
Bengaluru, 20-22 November 2011
Bengaluru, 20-22 November 2011
github.com/odino/osidays
Bengaluru, 20-22 November 2011
git checkout $step
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
Bengaluru, 20-22 November 2011
Step 2● write the test with the smallest
amount of code you think it'snecessary
Bengaluru, 20-22 November 2011
Step 3● add the Vertex class● add the Graph class● add an empty solve() method
for the algorithm class
Bengaluru, 20-22 November 2011
Step 4● implement the solve method
Bengaluru, 20-22 November 2011
Step 5● added all the methods
needed by the Dijkstra::solve()● need to implement Graph::calculatePotentials()
Bengaluru, 20-22 November 2011
Step 6● a test is added for the Graph class
Bengaluru, 20-22 November 2011
Step 7● calculatePotentials() is tested● half of our test-suite passes● switch back to the Dijkstra's test
Bengaluru, 20-22 November 2011
Step 8● minor tweaks to make all the tests pass
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
Bengaluru, 20-22 November 2011
Step 10● since we like to be OO, we can connect
vertices through objects, and notarrays anymore
Bengaluru, 20-22 November 2011
Step 11● we now need to fix the code which
uses vertices' connections as arrays
Bengaluru, 20-22 November 2011
Step 12● the library seems pretty complete● PHPDoc is added
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
Bengaluru, 20-22 November 2011
Step 14● implementation
Bengaluru, 20-22 November 2011
Step 15● enter Mocking objects
Bengaluru, 20-22 November 2011
Step 16● Dijkstra::getGraph() seems to be useless
so we probably don't need any Graph class
Bengaluru, 20-22 November 2011
Step 17● removed Graph class
Bengaluru, 20-22 November 2011
Step 18● some tests rely on it, so we need to
eliminate old references to Graph
Bengaluru, 20-22 November 2011
Step 19● enter Data Providers
Bengaluru, 20-22 November 2011
Step 20● what about calculating the path between
not-connected vertices?It should return null, so code is refactored
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
Alessandro Nadalin
Bengaluru, 20-22 November 2011
odino.org
Bengaluru, 20-22 November 2011
a
Bengaluru, 20-22 November 2011
a
Bengaluru, 20-22 November 2011
@_odino_ #osidays
a
Bengaluru, 20-22 November 2011
REST in peace: tomorrow, 12.45
a
Bengaluru, 20-22 November 2011
@_odino_
Thank YOU!