### Question:
SequenceBuilder { public FromCount count(int count) { return new FromCount(count, initialState); }  static VertexLabel proxyLabelFor(VertexLabel label); SequenceBuilder<T> withInitialState(Vertex<?, ?> vertex); SequenceBuilder<T> named(String sequenceName); SequenceBuilder<T> withInitialState(VertexLabel label, Vertex<?, ?> vertex); SequenceBuilder<T> withInitialState(VertexDictionary initialState); SequenceBuilder<T> withTransitionMapping(Map<VertexLabel, VertexLabel> transitionMapping); FromCount count(int count); FromIterator fromIterator(Iterator<T> iterator); FromIterator fromIterator(Iterator<T> iterator, int sizeHint); static VertexLabel getUnscopedLabel(VertexLabel proxyLabel, boolean hasSequenceName);  }### Answer:
@Test public void buildSequenceFromCount_Size() { int n = 100; Sequence sequence = new SequenceBuilder() .count(n) .withFactory(item -> { }) .build(); assertEquals(n, sequence.size()); }
@Test public void buildSequenceFromCount_Contents() { int n = 100; VertexLabel vertexName = new VertexLabel("vertexName"); Sequence sequence = new SequenceBuilder<>() .count(n) .withFactory((item) -> item.add(vertexName, new BernoulliVertex(0.5))) .build(); sequence.asList().forEach(item -> { assertNotNull(item.get(vertexName)); }); }
@Test(expected = IllegalArgumentException.class) public void youCannotAddTheSameLabelTwiceIntoOneSequenceItem() { new SequenceBuilder<Integer>() .count(10) .withFactory((item) -> { VertexLabel label = new VertexLabel("x"); DoubleVertex vertex1 = ConstantVertex.of(1.); DoubleVertex vertex2 = ConstantVertex.of(1.); item.add(label, vertex1); item.add(label, vertex2); }) .build(); }
@Test public void youCanCreateASequenceWithACommonParameterFromACount() { GaussianVertex commonTheta = new GaussianVertex(0.5, 0.01); VertexLabel label = new VertexLabel("flip"); Sequence sequence = new SequenceBuilder<Bean>() .count(10) .withFactory((item) -> { BooleanVertex flip = new BernoulliVertex(commonTheta); flip.observe(false); item.add(label, flip); }) .build(); for (SequenceItem item : sequence) { Vertex<DoubleTensor, ?> flip = item.get(label); assertThat(flip.getParents(), contains(commonTheta)); } }
@Test public void youCanPutTheSequenceIntoABayesNet() { GaussianVertex commonTheta = new GaussianVertex(0.5, 0.01); VertexLabel label = new VertexLabel("flip"); Sequence sequence = new SequenceBuilder<Bean>() .count(10) .withFactory((item) -> { BooleanVertex flip = new BernoulliVertex(commonTheta); flip.observe(false); item.add(label, flip); }) .build(); new BayesianNetwork(commonTheta.getConnectedGraph()); }
@Test public void youCanPutTheSameVertexIntoMultipleSequenceItems() { VertexLabel thetaLabel = new VertexLabel("theta"); VertexLabel flipLabel = new VertexLabel("flip"); GaussianVertex commonTheta = new GaussianVertex(0.5, 0.01); new SequenceBuilder<Bean>() .count(10) .withFactory((item) -> { BooleanVertex flip = new BernoulliVertex(commonTheta); flip.observe(false); item.add(thetaLabel, commonTheta); item.add(flipLabel, flip); }) .build(); new BayesianNetwork(commonTheta.getConnectedGraph()); }