package org.graphwalker.core.generator;

/*
 * #%L
 * GraphWalker Core
 * %%
 * Copyright (C) 2005 - 2014 GraphWalker
 * %%
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * #L%
 */

import org.graphwalker.core.algorithm.AlgorithmException;
import org.graphwalker.core.condition.VertexCoverage;
import org.graphwalker.core.machine.Context;
import org.graphwalker.core.machine.TestExecutionContext;
import org.graphwalker.core.model.Edge;
import org.graphwalker.core.model.Model;
import org.graphwalker.core.model.Vertex;
import org.junit.Assert;
import org.junit.Test;

/**
 * @author Kristian Karl
 */
public class QuickRandomPathTest {

  private final Vertex source = new Vertex();
  private final Vertex target = new Vertex();
  private final Edge edge = new Edge().setSourceVertex(source).setTargetVertex(target);
  private final Model model = new Model().addEdge(edge);

  @Test
  public void simpleTest() {
    Context context = new TestExecutionContext().setModel(model.build()).setNextElement(source);
    PathGenerator generator = new QuickRandomPath(new VertexCoverage(100));
    context.setPathGenerator(generator);
    context.setCurrentElement(source.build());
    Assert.assertEquals(context.getCurrentElement(), source.build());
    Assert.assertEquals(generator.getNextStep().getCurrentElement(), edge.build());
    Assert.assertEquals(generator.getNextStep().getCurrentElement(), target.build());
  }

  @Test(expected = AlgorithmException.class)
  public void failTest() {
    Context context = new TestExecutionContext().setModel(model.build()).setNextElement(source);
    PathGenerator generator = new QuickRandomPath(new VertexCoverage(100));
    context.setPathGenerator(generator);
    context.setCurrentElement(source.build());
    Assert.assertEquals(context.getCurrentElement(), source.build());
    Assert.assertEquals(generator.getNextStep().getCurrentElement(), edge.build());
    Assert.assertEquals(generator.getNextStep().getCurrentElement(), target.build());
    context.getPathGenerator().getNextStep(); // should fail
  }
}

@@ -1541,16 +1541,65 @@
 Vertex;%0A
+import org.graphwalker.core.statistics.Profiler;%0A
 import o
@@ -1615,16 +1615,16 @@
 Assert;%0A
-
 import o
@@ -2484,16 +2484,65 @@
 ild());%0A
+    Assert.assertFalse(generator.hasNextStep());%0A
   %7D%0A%0A  @
@@ -2775,32 +2775,73 @@
 Coverage(100));%0A
+    context.setProfiler(new Profiler());%0A
     context.setP
@@ -3148,24 +3148,24 @@
 t.build());%0A
-
     context.
@@ -3216,11 +3216,510 @@
 fail%0A  %7D
+%0A%0A  @Test(expected = NoPathFoundException.class)%0A  public void emptyModel() %7B%0A    Context context = new TestExecutionContext().setModel(new Model().addVertex(source).build()).setNextElement(source);%0A    PathGenerator generator = new QuickRandomPath(new VertexCoverage(100));%0A    context.setProfiler(new Profiler());%0A    context.setPathGenerator(generator);%0A    context.setCurrentElement(source.build());%0A    Assert.assertTrue(generator.hasNextStep());%0A    generator.getNextStep(); // should fail%0A  %7D
 %0A%7D%0A

Add test