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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations