GraphWalker / graphwalker-project

This is the repo for the Model-based testing tool GraphWalker.

Home Page:http://graphwalker.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The A* path generator does not work as expected when used in combination with other generators

KristianKarl-zz opened this issue · comments

The documentation states:

a_star( a stop condition that names a vertex or an edge )
Will generate the shortest path to a specific vertex or edge.

When used alone there's no problem, for example like this:

java -jar graphwalker-cli-4.0.0-SNAPSHOT.jar offline "a_star(reached_edge(e_someEdge))"

But when used after another generator, like this:

java -jar graphwalker-cli-4.0.0-SNAPSHOT.jar offline "random(edge_coverage(100)) a_star(reached_edge(e_someEdge))"

the actual result is that the a_star will halt immediately. Always.

The expected result, when reading our documentation, would be a generated path from wherever the current element happens to be, to the edge e_someEdge.

Below a suggested test, that would verify the expected behavior:

  @Test
  public void generatePath() {
    Vertex v1 = new Vertex().setName("v1");
    Vertex v2 = new Vertex().setName("v2");
    Vertex v3 = new Vertex().setName("v3");
    Edge e1 = new Edge().setName("e1").setSourceVertex(v1).setTargetVertex(v2);
    Edge e2 = new Edge().setName("e2").setSourceVertex(v2).setTargetVertex(v3);
    Edge e3 = new Edge().setName("e3").setSourceVertex(v3).setTargetVertex(v1);
    Model model = new Model()
      .addEdge(e1)
      .addEdge(e2)
      .addEdge(e3);

    CombinedPath combinedPath = new CombinedPath();
    combinedPath.addPathGenerator(new RandomPath(new EdgeCoverage(100)));
    combinedPath.addPathGenerator(new AStarPath(new ReachedEdge("e2")));

    Context context = new TestExecutionContext(model, combinedPath).setCurrentElement(v1.build());
    Machine machine = new SimpleMachine(context);
    while (machine.hasNextStep()) {
      machine.getNextStep();
    }
    List<Element> expectedPath = Arrays.<Element>asList(
      e1.build(),
      v2.build(),
      e2.build(),
      v3.build(),
      e3.build(),
      v1.build(),

      // This is where the A* generates a path from v1 to e2
      e1.build(),
      v2.build(),
      e2.build()
    );
    Collections.reverse(expectedPath);
    assertArrayEquals(expectedPath.toArray(), context.getProfiler().getPath().toArray());
  }

Fixed by PR #156