Created
July 22, 2016 15:06
-
-
Save serhii-shnurenko/062788a65515189d6733d17f4246a155 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 1 | |
0 2 | |
1 0 | |
1 2 | |
1 5 | |
1 10 | |
2 1 | |
2 4 | |
2 5 | |
2 10 | |
2 13 | |
3 12 | |
3 1 | |
3 0 | |
3 10 | |
4 3 | |
4 6 | |
4 9 | |
5 1 | |
5 10 | |
5 12 | |
5 11 | |
5 13 | |
6 1 | |
6 12 | |
6 13 | |
7 10 | |
7 1 | |
7 3 | |
7 4 | |
7 6 | |
8 2 | |
8 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sherlock Holmes 0 | |
John Smith 1 | |
Andrew Ng 2 | |
Clark Kent 3 | |
Bruce Wayne 4 | |
Arnold Schwarzenegger 5 | |
David Copperfield 6 | |
Roger Federer 7 | |
Socrates 8 | |
Paul McCartney 9 | |
Confucius 10 | |
Steven Spielberg 11 | |
Nikola Tesla 12 | |
George Lucas 13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package graph; | |
import org.junit.Before; | |
import org.junit.Test; | |
import java.io.File; | |
import java.io.IOException; | |
import java.util.List; | |
import static org.junit.Assert.*; | |
/** | |
* Created by Сергій Шнуренко on 22.07.2016. | |
*/ | |
public class UndirectedGraphReadTest { | |
//region Private fields | |
private static String testcase1 = new File("").getAbsolutePath()+"\\src\\test\\resources\\testcase1"; | |
UndirectedGraph<String> g1; | |
String[] shouldContainArray = {"Sherlock Holmes", "John Smith", "Andrew Ng", "Clark Kent", "Bruce Wayne", | |
"Arnold Schwarzenegger", "David Copperfield", "Roger Federer", "Socrates", "Paul McCartney", | |
"Confucius", "Steven Spielberg", "Nikola Tesla", "George Lucas"}; | |
//endregion | |
@Before | |
public void setUp() throws IOException{ | |
g1 = new UndirectedGraph<String>(); | |
g1.readFromFile(testcase1); | |
} | |
@Test | |
public void containsAllNodesTest(){ | |
List<String> vertices = g1.getAllVertices(); | |
if(vertices.size()!=14) | |
fail("Testcase#1 number of vertices should be equal 14"); | |
for(String shouldContain:shouldContainArray){ | |
assertTrue("There must be "+shouldContain+" node in graph.",vertices.contains(shouldContain)); | |
} | |
} | |
@Test | |
public void containsConnectionsTest(){ | |
assertTrue("Sherlock Holmes must know John Smith",g1.getAdjacent("Sherlock Holmes").contains("John Smith")); | |
assertTrue("Sherlock Holmes must know John Smith",g1.getAdjacent("Sherlock Holmes").contains("Andrew Ng")); | |
assertTrue("Sherlock Holmes must know John Smith",g1.getAdjacent("Sherlock Holmes").contains("Clark Kent")); | |
assertEquals("Sherlock Holmes should know only 3 persons",3,g1.getAdjacent("Sherlock Holmes").size()); | |
assertEquals("Arnold Schwarzenegger should know only 6 persons",6,g1.getAdjacent("Arnold Schwarzenegger").size()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment