Search in sources :

Example 6 with SimpleEntry

use of java.util.AbstractMap.SimpleEntry in project cucumber-jvm by cucumber.

the class RerunFormatterTest method should_use_scenario_location_when_after_hook_fails.

@Test
public void should_use_scenario_location_when_after_hook_fails() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given first step\n" + "    When second step\n" + "    Then third step\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("first step", result("passed"));
    stepsToResult.put("second step", result("passed"));
    stepsToResult.put("third step", result("passed"));
    List<SimpleEntry<String, Result>> hooks = new ArrayList<SimpleEntry<String, Result>>();
    hooks.add(TestHelper.hookEntry("after", result("failed")));
    String formatterOutput = runFeatureWithRerunFormatter(feature, stepsToResult, hooks);
    assertEquals("path/test.feature:2", formatterOutput);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) SimpleEntry(java.util.AbstractMap.SimpleEntry) ArrayList(java.util.ArrayList) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 7 with SimpleEntry

use of java.util.AbstractMap.SimpleEntry in project cucumber-jvm by cucumber.

the class RerunFormatterTest method should_use_scenario_location_when_before_hook_fails.

@Test
public void should_use_scenario_location_when_before_hook_fails() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given first step\n" + "    When second step\n" + "    Then third step\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("first step", result("passed"));
    stepsToResult.put("second step", result("passed"));
    stepsToResult.put("third step", result("passed"));
    List<SimpleEntry<String, Result>> hooks = new ArrayList<SimpleEntry<String, Result>>();
    hooks.add(TestHelper.hookEntry("before", result("failed")));
    String formatterOutput = runFeatureWithRerunFormatter(feature, stepsToResult, hooks);
    assertEquals("path/test.feature:2", formatterOutput);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) SimpleEntry(java.util.AbstractMap.SimpleEntry) ArrayList(java.util.ArrayList) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 8 with SimpleEntry

use of java.util.AbstractMap.SimpleEntry in project cucumber-jvm by cucumber.

the class JUnitFormatterTest method should_handle_failure_in_after_hook.

@Test
public void should_handle_failure_in_after_hook() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given first step\n" + "    When second step\n" + "    Then third step\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("first step", result("passed"));
    stepsToResult.put("second step", result("passed"));
    stepsToResult.put("third step", result("passed"));
    List<SimpleEntry<String, Result>> hooks = new ArrayList<SimpleEntry<String, Result>>();
    hooks.add(TestHelper.hookEntry("after", result("failed")));
    long stepHookDuration = milliSeconds(1);
    String formatterOutput = runFeatureWithJUnitFormatter(feature, stepsToResult, hooks, stepHookDuration);
    String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testsuite failures=\"1\" name=\"cucumber.runtime.formatter.JUnitFormatter\" skipped=\"0\" tests=\"1\" time=\"0.004\">\n" + "    <testcase classname=\"feature name\" name=\"scenario name\" time=\"0.004\">\n" + "        <failure message=\"the stack trace\"><![CDATA[" + "Given first step............................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "\n" + "StackTrace:\n" + "the stack trace" + "]]></failure>\n" + "    </testcase>\n" + "</testsuite>\n";
    assertXmlEqual(expected, formatterOutput);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) SimpleEntry(java.util.AbstractMap.SimpleEntry) ArrayList(java.util.ArrayList) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 9 with SimpleEntry

use of java.util.AbstractMap.SimpleEntry in project cucumber-jvm by cucumber.

the class JUnitFormatterTest method should_handle_pending_in_before_hook.

@Test
public void should_handle_pending_in_before_hook() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given first step\n" + "    When second step\n" + "    Then third step\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("first step", result("skipped"));
    stepsToResult.put("second step", result("skipped"));
    stepsToResult.put("third step", result("skipped"));
    List<SimpleEntry<String, Result>> hooks = new ArrayList<SimpleEntry<String, Result>>();
    hooks.add(TestHelper.hookEntry("before", result("pending")));
    long stepHookDuration = milliSeconds(1);
    String formatterOutput = runFeatureWithJUnitFormatter(feature, stepsToResult, hooks, stepHookDuration);
    String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testsuite failures=\"0\" name=\"cucumber.runtime.formatter.JUnitFormatter\" skipped=\"1\" tests=\"1\" time=\"0.001\">\n" + "    <testcase classname=\"feature name\" name=\"scenario name\" time=\"0.001\">\n" + "        <skipped><![CDATA[" + "Given first step............................................................skipped\n" + "When second step............................................................skipped\n" + "Then third step.............................................................skipped\n" + "]]></skipped>\n" + "    </testcase>\n" + "</testsuite>\n";
    assertXmlEqual(expected, formatterOutput);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) SimpleEntry(java.util.AbstractMap.SimpleEntry) ArrayList(java.util.ArrayList) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 10 with SimpleEntry

use of java.util.AbstractMap.SimpleEntry in project aerosolve by airbnb.

the class LocalitySensitiveHashSparseFeatureDictionary method getKNearestNeighbors.

@Override
public FeatureVector getKNearestNeighbors(KNearestNeighborsOptions options, FeatureVector featureVector) {
    FeatureVector result = new FeatureVector();
    Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
    if (stringFeatures == null) {
        return result;
    }
    String featureKey = options.getFeatureKey();
    Set<String> keys = stringFeatures.get(featureKey);
    if (keys == null) {
        return result;
    }
    if (!haveLSH) {
        buildHashTable(featureKey);
    }
    String idKey = options.getIdKey();
    PriorityQueue<SimpleEntry<String, Double>> pq = new PriorityQueue<>(options.getNumNearest() + 1, new EntryComparator());
    Map<String, Map<String, Double>> floatFeatures = new HashMap<>();
    String myId = featureVector.getStringFeatures().get(idKey).iterator().next();
    Set<Integer> candidates = getCandidates(keys);
    for (Integer candidate : candidates) {
        FeatureVector supportVector = dictionaryList.get(candidate);
        double sim = similarity(featureVector, supportVector, featureKey);
        Set<String> idSet = supportVector.getStringFeatures().get(idKey);
        String id = idSet.iterator().next();
        if (id == myId) {
            continue;
        }
        SimpleEntry<String, Double> entry = new SimpleEntry<String, Double>(id, sim);
        pq.add(entry);
        if (pq.size() > options.getNumNearest()) {
            pq.poll();
        }
    }
    HashMap<String, Double> newFeature = new HashMap<>();
    while (pq.peek() != null) {
        SimpleEntry<String, Double> entry = pq.poll();
        newFeature.put(entry.getKey(), entry.getValue());
    }
    floatFeatures.put(options.getOutputKey(), newFeature);
    result.setFloatFeatures(floatFeatures);
    return result;
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) SimpleEntry(java.util.AbstractMap.SimpleEntry)

Aggregations

SimpleEntry (java.util.AbstractMap.SimpleEntry)47 Test (org.junit.Test)24 ArrayList (java.util.ArrayList)21 HashMap (java.util.HashMap)15 CucumberFeature (cucumber.runtime.model.CucumberFeature)10 Result (gherkin.formatter.model.Result)10 Entry (java.util.Map.Entry)10 HashSet (java.util.HashSet)9 Map (java.util.Map)8 Metacard (ddf.catalog.data.Metacard)7 Serializable (java.io.Serializable)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 List (java.util.List)6 UpdateRequest (ddf.catalog.operation.UpdateRequest)5 Set (java.util.Set)5 Configuration (org.apache.commons.configuration.Configuration)5 ZookeeperConfigurationProvider (com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationProvider)4 LinkedList (java.util.LinkedList)4 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)3