### Question:
BayesianNetwork { public Vertex getVertexByLabel(VertexLabel label) { Preconditions.checkArgument(vertexLabels.containsKey(label), String.format("Vertex with label %s was not found in BayesianNetwork.", label)); return vertexLabels.get(label); } BayesianNetwork(Set<? extends Vertex> vertices);  BayesianNetwork(Collection<? extends Vertex> vertices); Vertex getVertexByLabel(VertexLabel label); List<Vertex> getVerticesInNamespace(String... namespace); List<Vertex> getVerticesIgnoringNamespace(String innerNamespace); int getVertexCount(); double getAverageVertexDegree(); void setState(NetworkState state); List<Vertex> getAllVertices(); List<? extends Vertex> getVertices(); List<Vertex> getLatentOrObservedVertices(); List<Vertex> getTopLevelLatentOrObservedVertices(); List<Vertex> getLatentVertices(); List<Vertex> getTopLevelLatentVertices(); List<Vertex> getObservedVertices(); List<Vertex> getTopLevelObservedVertices(); double getLogOfMasterP(); void cascadeObservations(); void probeForNonZeroProbability(int attempts); void probeForNonZeroProbability(int attempts, KeanuRandom random); boolean isInImpossibleState(); static void setFromSampleAndCascade(List<? extends Vertex> vertices); static void setFromSampleAndCascade(List<? extends Vertex> vertices, KeanuRandom random); List<DoubleVertex> getContinuousLatentVertices(); List<Vertex> getDiscreteLatentVertices(); int getIndentation(); void incrementIndentation(); void save(NetworkSaver networkSaver); void saveValues(NetworkSaver networkSaver); Set<Vertex> getSubgraph(Vertex vertex, int degree);  }### Answer:
@Test public void youCanLabelVertices() { BooleanVertex a = new BernoulliVertex(0.5); BooleanVertex b = new BernoulliVertex(0.5); BooleanVertex ored = a.or(b); BooleanVertex unlabelled = ored.or(a); Vertex retrieved; VertexLabel labelA = new VertexLabel(LABEL_A); VertexLabel labelB = new VertexLabel(LABEL_B); VertexLabel labelOr = new VertexLabel(LABEL_ORED); a.setLabel(labelA); b.setLabel(labelB); ored.setLabel(labelOr); BayesianNetwork net = new BayesianNetwork(a.getConnectedGraph()); retrieved = net.getVertexByLabel(labelA); assertThat(retrieved, is(a)); retrieved = net.getVertexByLabel(labelB); assertThat(retrieved, is(b)); retrieved = net.getVertexByLabel(labelOr); assertThat(retrieved, is(ored)); }
@Test public void throwsIfVertexWithLabelIsNotInBayesianNetwork() { BooleanVertex vertexInNetwork = new BernoulliVertex(0.5).setLabel(LABEL_A); BayesianNetwork network = new BayesianNetwork(vertexInNetwork.getConnectedGraph()); BooleanVertex vertexNotInNetwork = new BernoulliVertex(0.5).setLabel(LABEL_B); thrown.expect(IllegalArgumentException.class); thrown.expectMessage(String.format("Vertex with label %s was not found in BayesianNetwork", LABEL_B)); network.getVertexByLabel(new VertexLabel(LABEL_B)); }