jeudi 1 novembre 2018

Junit testing with nodes and edges objects

I am trying to run a junit testing for the methods "addNode" "addEdge" and "findPaths" but I am not sure yet how exactly to do such a thing. I created a class called MultiGraphTest in which i will be implementing the tests. Can anyone help with for example the addNodeTest method? Explain to me how to start implementing such a method and what I need to do? Thank you

public class MultiGraph implements IMultiGraph {

private Set<Edge> edges; // the set of edges
private Set<Node> nodes; // the set of nodes
private Map<Node, Set<Edge>> nodeToEdges; // mapping of nodes to their edges

MultiGraph () {
    edges = new HashSet<Edge>();
    nodes = new HashSet<Node>();
    nodeToEdges = new HashMap<Node, Set<Edge>>();
}

// requires: n != null
// modifies: this
//  effects: n in Nodes? && if n !in Nodes return true, else return false
@Override
public boolean addNode(Node n) {
    if (nodes.add(n)) { // n was not in the set already
        Set<Edge> nodeEdges = new HashSet<Edge>();
        nodeToEdges.put(n, nodeEdges);
        return true;
    } 
    return false;
}

class MultiGraphTest {

@BeforeAll
static void setUpBeforeClass() throws Exception {
}

@AfterAll
static void tearDownAfterClass() throws Exception {
}

@BeforeEach
void setUp() throws Exception {
}

@AfterEach
void tearDown() throws Exception {
}

@Test
void testAddNode() {


}

@Test
void testAddEdge() {
    fail("Not yet implemented");
}

@Test
void testFindPath() {
    fail("Not yet implemented");
}

}

Aucun commentaire:

Enregistrer un commentaire