### Question:
TraceHeight implements ModelRunner { public static int calculate(Graph graph) { TraceTraversal<Vertex, Comparable> maxHeight = graph.traversal(TraceTraversalSource.class).V() .repeat(__.in()).emit().path().count(Scope.local).max(); List<Integer> heights = maxHeight.toStream() .map(height -> Integer.valueOf(height.toString())) .collect(toList()); return heights.size() > 0 ? heights.get(0) - 1 : 0; }  void runWithMetrics(Graph graph); static int calculate(Graph graph);  }### Answer:
@Test public void calculateEmpty() { int height = TraceHeight.calculate(GraphCreator.create(new Trace())); Assert.assertEquals(0, height); }
@Test public void calculateOnlyRoot() { Span root = Util.newTrace("root", "root"); root.serviceName = "root"; Trace trace = new Trace(); trace.spans = Arrays.asList(root); Graph graph = GraphCreator.create(trace); int height = TraceHeight.calculate(graph); Assert.assertEquals(0, height); }
@Test public void calculate() { Span root = Util.newTrace("root", "root"); Span child = Util.newChild("child", "child", root); Span child2 = Util.newChild("child2", "child2", root); Span childChild = Util.newChild("childChild", "childChild", child); Trace trace = new Trace(); trace.spans = Arrays.asList(root, child, child2, childChild); Graph graph = GraphCreator.create(trace); int height = TraceHeight.calculate(graph); Assert.assertEquals(2, height); }