SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
16.
github.com/odino/osidays
Bengaluru, 20-22 November 2011
17.
git checkout $step
Bengaluru, 20-22 November 2011
18.
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
19.
Step 2
● write the test with the smallest
amount of code you think it's
necessary
Bengaluru, 20-22 November 2011
20.
Step 3
● add the Vertex class
● add the Graph class
● add an empty solve() method
for the algorithm class
Bengaluru, 20-22 November 2011
21.
Step 4
● implement the solve method
Bengaluru, 20-22 November 2011
22.
Step 5
● added all the methods
needed by the Dijkstra::solve()
● need to implement Graph::calculatePotentials()
Bengaluru, 20-22 November 2011
23.
Step 6
● a test is added for the Graph class
Bengaluru, 20-22 November 2011
24.
Step 7
● calculatePotentials() is tested
● half of our test-suite passes
● switch back to the Dijkstra's test
Bengaluru, 20-22 November 2011
25.
Step 8
● minor tweaks to make all the tests pass
Bengaluru, 20-22 November 2011
26.
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 Graph
into Dijkstra's class, we can delete the GraphTest
Bengaluru, 20-22 November 2011
27.
Step 10
● since we like to be OO, we can connect
vertices through objects, and not
arrays anymore
Bengaluru, 20-22 November 2011
28.
Step 11
● we now need to fix the code which
uses vertices' connections as arrays
Bengaluru, 20-22 November 2011
29.
Step 12
● the library seems pretty complete
● PHPDoc is added
Bengaluru, 20-22 November 2011
30.
Step 13
● Oooops, we forgot to test a scenario:
in Dijkstra's algorithm we need vertices
connected by positive distance
● a test is added, verifying an exception
is raised through annotations
Bengaluru, 20-22 November 2011
31.
Step 14
● implementation
Bengaluru, 20-22 November 2011
32.
Step 15
● enter Mocking objects
Bengaluru, 20-22 November 2011
33.
Step 16
● Dijkstra::getGraph() seems to be useless
so we probably don't need any Graph class
Bengaluru, 20-22 November 2011
34.
Step 17
● removed Graph class
Bengaluru, 20-22 November 2011
35.
Step 18
● some tests rely on it, so we need to
eliminate old references to Graph
Bengaluru, 20-22 November 2011
36.
Step 19
● enter Data Providers
Bengaluru, 20-22 November 2011
37.
Step 20
● what about calculating the path between
not-connected vertices?
It should return null, so code is refactored
Bengaluru, 20-22 November 2011
38.
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
Bengaluru, 20-22 November 2011
39.
Alessandro Nadalin
Bengaluru, 20-22 November 2011