samedi 23 mai 2020

Junit Test _ java.lang.AssertionError

I am new to Junit testing. I wrote a test class to check a function which reverse an input graph. I hard coded two graphs the original and reversed one to check the function reverseGraph() in the postDominatorTree class.

import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import slicer.util.cfg.Node;
import slicer.util.cfg.ProgramGraph;

class PostDominatorTreeTest {

    @Test
    void test_reverseGraph() {
        final ProgramGraph pg = new ProgramGraph();
        final Node n1 = new Node("n1");
        final Node n2 = new Node("n2");
        final Node n3 = new Node("n3");
        final Node n4 = new Node("n4");

        pg.addNode(n1);
        pg.addNode(n2);
        pg.addNode(n3);
        pg.addNode(n4);
        pg.addEdge(n1, n2);
        pg.addEdge(n2, n3);
        pg.addEdge(n3, n4);

        final ProgramGraph pg_reversed_expected = new ProgramGraph();

        pg_reversed_expected.addNode(n1);
        pg_reversed_expected.addNode(n2);
        pg_reversed_expected.addNode(n3);
        pg_reversed_expected.addNode(n4);
        pg_reversed_expected.addEdge(n2, n1);
        pg_reversed_expected.addEdge(n3, n2);
        pg_reversed_expected.addEdge(n4, n3);

        PostDominatorTree PostDominatorGraph = new PostDominatorTree(pg);
        final ProgramGraph pg_reversed = PostDominatorGraph.reverseGraph(pg);

        assertEquals(pg_reversed,pg_reversed_expected);


    }

}

I got a failure

java.lang.AssertionError: expected: slicer.util.cfg.ProgramGraph<digraph cfg{
"n2"->"n1"
"n3"->"n2"
"n4"->"n3"
}> but was: slicer.util.cfg.ProgramGraph<digraph cfg{
"n2"->"n1"
"n3"->"n2"
"n4"->"n3"
}>

I see that both graphs are equal! can anybody shows me what I missed here?

Aucun commentaire:

Enregistrer un commentaire