MathStep extends ScalarMapStep<S, Double> implements ByModulating, TraversalParent, Scoping, PathProcessor { protected static final Set<String> getVariables(final String equation) { final Matcher matcher = VARIABLE_PATTERN.matcher(equation); final Set<String> variables = new LinkedHashSet<>(); while (matcher.find()) { variables.add(matcher.group()); } return variables; } MathStep(final Traversal.Admin traversal, final String equation); @Override void modulateBy(final Traversal.Admin<?, ?> selectTraversal); @Override ElementRequirement getMaxRequirement(); @Override String toString(); @Override int hashCode(); @Override List<Traversal.Admin<S, Number>> getLocalChildren(); @Override void reset(); @Override MathStep<S> clone(); @Override void setTraversal(final Traversal.Admin<?, ?> parentTraversal); @Override Set<TraverserRequirement> getRequirements(); @Override Set<String> getScopeKeys(); @Override void setKeepLabels(final Set<String> labels); @Override Set<String> getKeepLabels();  }
@Test public void shouldParseVariablesCorrectly() { assertEquals(Collections.emptyList(), new ArrayList<>(MathStep.getVariables("1 + 2"))); assertEquals(Arrays.asList("a", "b"), new ArrayList<>(MathStep.getVariables("a + b / 2"))); assertEquals(Arrays.asList("a", "b"), new ArrayList<>(MathStep.getVariables("a + b / sin 2"))); assertEquals(Arrays.asList("a", "b"), new ArrayList<>(MathStep.getVariables("a + b / sin (2 + 6.67e−11)"))); assertEquals(Arrays.asList("a", "b", "_", "x", "z"), new ArrayList<>(MathStep.getVariables("(a + b / _) + log2 (x^3)^z"))); assertEquals(Arrays.asList("a", "b", "_", "x", "z"), new ArrayList<>(MathStep.getVariables("(a + b / _) + log2 (x^3)^z + b + a"))); assertEquals(Arrays.asList("a_ASDF", "b", "_", "x", "z", "a"), new ArrayList<>(MathStep.getVariables("(a_ASDF + b / _) + log2 (x^3)^z + b + a"))); assertEquals(Arrays.asList("a_ASDF", "bzz_", "_", "x", "z", "a_var", "d"), new ArrayList<>(MathStep.getVariables("((a_ASDF + bzz_ / _) + log2 (x^3)^z + bzz_ + (sinh (a_var + 10))) / (2.0265 * d)"))); assertEquals(Arrays.asList("ac", "b", "_", "x", "z2"), new ArrayList<>(MathStep.getVariables("(ac + b / _) + log2 (x^3)^z2 + b + (tan (log10 ac / sqrt b))"))); }