@Test public void record_stats_information_from_simple_vertices() { VertexStatsRecorder recorder = new VertexStatsRecorder(); Vertex simple = VertexFactory.makeSimpleVertex(); Vertex simple2 = VertexFactory.makeSimpleVertex(); Vertex simple3 = VertexFactory.makeSimpleVertex(); Vertex simple4 = VertexFactory.makeSimpleVertex(); simple.addNeighbour(simple2).addNeighbour(simple3).addNeighbour(simple4); simple2.addNeighbour(simple3).addNeighbour(simple4); simple3.addNeighbour(simple4); simple.publishYourStatsOn(recorder); simple2.publishYourStatsOn(recorder); simple3.publishYourStatsOn(recorder); simple4.publishYourStatsOn(recorder); Map<PlainTextStatsComponents, Integer> expected = new HashMap<PlainTextStatsComponents, Integer>(); expected.put(PlainTextStatsComponents.NOfVertices, 4); expected.put(PlainTextStatsComponents.NOfEdges, 6); expected.put(PlainTextStatsComponents.NOfSources, 1); expected.put(PlainTextStatsComponents.NOfSinks, 1); expected.put(PlainTextStatsComponents.NOfWhites, 2); Assert.assertTrue(recorder.isSimpleVerticesVotesEquals(expected)); Assert.assertFalse( recorder.isSimpleVerticesVotesEquals(new HashMap<PlainTextStatsComponents, Integer>())); }
@Test public void check_consistency_for_simple_vertices_votes() { VertexStatsRecorder recorder = new VertexStatsRecorder(); Vertex simple = VertexFactory.makeSimpleVertex(); Vertex simple2 = VertexFactory.makeSimpleVertex(); Vertex simple3 = VertexFactory.makeSimpleVertex(); Vertex simple4 = VertexFactory.makeSimpleVertex(); simple.addNeighbour(simple2).addNeighbour(simple3).addNeighbour(simple4); simple2.addNeighbour(simple3).addNeighbour(simple4); simple3.addNeighbour(simple4); simple.publishYourStatsOn(recorder); simple2.publishYourStatsOn(recorder); simple3.publishYourStatsOn(recorder); simple4.publishYourStatsOn(recorder); Assert.assertTrue(recorder.isSimpleVerticesVoteAccepterConsistent()); }
@Test public void record_average_with_two_model_stats_information_from_simple_vertices_should_change() { VertexStatsRecorder recorder = new VertexStatsRecorder(); Vertex simple = VertexFactory.makeSimpleVertex(); Vertex simple2 = VertexFactory.makeSimpleVertex(); Vertex simple3 = VertexFactory.makeSimpleVertex(); Vertex simple4 = VertexFactory.makeSimpleVertex(); simple.addNeighbour(simple2).addNeighbour(simple3).addNeighbour(simple4); simple2.addNeighbour(simple3).addNeighbour(simple4); simple3.addNeighbour(simple4); simple.publishYourStatsOn(recorder); simple2.publishYourStatsOn(recorder); simple3.publishYourStatsOn(recorder); simple4.publishYourStatsOn(recorder); Map<PlainTextStatsComponents, Integer> expected = new HashMap<PlainTextStatsComponents, Integer>(); int counter = 2; expected.put( PlainTextStatsComponents.NOfVertices, VertexVoteAccepter.DivideAndRound(4, counter)); expected.put(PlainTextStatsComponents.NOfEdges, VertexVoteAccepter.DivideAndRound(6, counter)); expected.put( PlainTextStatsComponents.NOfSources, VertexVoteAccepter.DivideAndRound(1, counter)); expected.put(PlainTextStatsComponents.NOfSinks, VertexVoteAccepter.DivideAndRound(1, counter)); expected.put(PlainTextStatsComponents.NOfWhites, VertexVoteAccepter.DivideAndRound(2, counter)); Assert.assertTrue(recorder.average(counter).isSimpleVerticesVotesEquals(expected)); Assert.assertFalse( recorder .average(counter) .isSimpleVerticesVotesEquals(new HashMap<PlainTextStatsComponents, Integer>())); }
@Test public void check_consistency_for_connected_components_vertices_votes() { VertexStatsRecorder recorder = new VertexStatsRecorder(); ConnectedComponentWrapperVertex simple = VertexFactory.makeConnectedComponentWrapperVertex(); ConnectedComponentWrapperVertex simple2 = VertexFactory.makeConnectedComponentWrapperVertex(); ConnectedComponentWrapperVertex simple3 = VertexFactory.makeConnectedComponentWrapperVertex(); ConnectedComponentWrapperVertex simple4 = VertexFactory.makeConnectedComponentWrapperVertex(); simple.includeMember(VertexFactory.makeSimpleVertex()); simple.includeMember(VertexFactory.makeSimpleVertex()); simple.includeMember(VertexFactory.makeSimpleVertex()); simple.addNeighbour(simple2); simple2.includeMember(VertexFactory.makeSimpleVertex()); simple2.addNeighbour(simple3).addNeighbour(simple4); simple3.includeMember(VertexFactory.makeSimpleVertex()); simple3.includeMember(VertexFactory.makeSimpleVertex()); simple3.addNeighbour(simple4); simple4.includeMember(VertexFactory.makeSimpleVertex()); simple4.includeMember(VertexFactory.makeSimpleVertex()); simple4.includeMember(VertexFactory.makeSimpleVertex()); simple.publishYourStatsOn(recorder); simple2.publishYourStatsOn(recorder); simple3.publishYourStatsOn(recorder); simple4.publishYourStatsOn(recorder); Assert.assertTrue(recorder.isConnectedComponentsVoteAccepterConsistent()); }
@Test public void record_stats_information_from_connected_components() { VertexStatsRecorder recorder = new VertexStatsRecorder(); ConnectedComponentWrapperVertex simple = VertexFactory.makeConnectedComponentWrapperVertex(); ConnectedComponentWrapperVertex simple2 = VertexFactory.makeConnectedComponentWrapperVertex(); ConnectedComponentWrapperVertex simple3 = VertexFactory.makeConnectedComponentWrapperVertex(); ConnectedComponentWrapperVertex simple4 = VertexFactory.makeConnectedComponentWrapperVertex(); simple.includeMember(VertexFactory.makeSimpleVertex()); simple.includeMember(VertexFactory.makeSimpleVertex()); simple.includeMember(VertexFactory.makeSimpleVertex()); simple.addNeighbour(simple2); simple2.includeMember(VertexFactory.makeSimpleVertex()); simple2.addNeighbour(simple3).addNeighbour(simple4); simple3.includeMember(VertexFactory.makeSimpleVertex()); simple3.includeMember(VertexFactory.makeSimpleVertex()); simple3.addNeighbour(simple4); simple4.includeMember(VertexFactory.makeSimpleVertex()); simple4.includeMember(VertexFactory.makeSimpleVertex()); simple4.includeMember(VertexFactory.makeSimpleVertex()); simple.publishYourStatsOn(recorder); simple2.publishYourStatsOn(recorder); simple3.publishYourStatsOn(recorder); simple4.publishYourStatsOn(recorder); Map<PlainTextStatsComponents, Integer> expectedFor3members = new HashMap<PlainTextStatsComponents, Integer>(); expectedFor3members.put(PlainTextStatsComponents.NOfComponents, 2); expectedFor3members.put(PlainTextStatsComponents.NOfSources, 1); expectedFor3members.put(PlainTextStatsComponents.NOfSinks, 1); expectedFor3members.put(PlainTextStatsComponents.NOfWhites, 0); expectedFor3members.put(PlainTextStatsComponents.NOfEdges, 1); Map<PlainTextStatsComponents, Integer> expectedFor2members = new HashMap<PlainTextStatsComponents, Integer>(); expectedFor2members.put(PlainTextStatsComponents.NOfComponents, 1); expectedFor2members.put(PlainTextStatsComponents.NOfSources, 0); expectedFor2members.put(PlainTextStatsComponents.NOfSinks, 0); expectedFor2members.put(PlainTextStatsComponents.NOfWhites, 1); expectedFor2members.put(PlainTextStatsComponents.NOfEdges, 1); Map<PlainTextStatsComponents, Integer> expectedFor1members = new HashMap<PlainTextStatsComponents, Integer>(); expectedFor1members.put(PlainTextStatsComponents.NOfComponents, 1); expectedFor1members.put(PlainTextStatsComponents.NOfSources, 0); expectedFor1members.put(PlainTextStatsComponents.NOfSinks, 0); expectedFor1members.put(PlainTextStatsComponents.NOfWhites, 1); expectedFor1members.put(PlainTextStatsComponents.NOfEdges, 2); Assert.assertTrue(recorder.isComponentsVotesEquals(3, expectedFor3members)); Assert.assertTrue(recorder.isComponentsVotesEquals(2, expectedFor2members)); Assert.assertTrue(recorder.isComponentsVotesEquals(1, expectedFor1members)); }
@Test public void record_average_with_two_model_stats_information_from_connected_components() { VertexStatsRecorder recorder = new VertexStatsRecorder(); ConnectedComponentWrapperVertex simple = VertexFactory.makeConnectedComponentWrapperVertex(); ConnectedComponentWrapperVertex simple2 = VertexFactory.makeConnectedComponentWrapperVertex(); ConnectedComponentWrapperVertex simple3 = VertexFactory.makeConnectedComponentWrapperVertex(); ConnectedComponentWrapperVertex simple4 = VertexFactory.makeConnectedComponentWrapperVertex(); simple.includeMember(VertexFactory.makeSimpleVertex()); simple.includeMember(VertexFactory.makeSimpleVertex()); simple.includeMember(VertexFactory.makeSimpleVertex()); simple.addNeighbour(simple2); simple2.includeMember(VertexFactory.makeSimpleVertex()); simple2.addNeighbour(simple3).addNeighbour(simple4); simple3.includeMember(VertexFactory.makeSimpleVertex()); simple3.includeMember(VertexFactory.makeSimpleVertex()); simple3.addNeighbour(simple4); simple4.includeMember(VertexFactory.makeSimpleVertex()); simple4.includeMember(VertexFactory.makeSimpleVertex()); simple4.includeMember(VertexFactory.makeSimpleVertex()); simple.publishYourStatsOn(recorder); simple2.publishYourStatsOn(recorder); simple3.publishYourStatsOn(recorder); simple4.publishYourStatsOn(recorder); int counter = 1; Map<PlainTextStatsComponents, Integer> expectedFor3members = new HashMap<PlainTextStatsComponents, Integer>(); expectedFor3members.put( PlainTextStatsComponents.NOfComponents, VertexVoteAccepter.DivideAndRound(2, counter)); expectedFor3members.put( PlainTextStatsComponents.NOfSources, VertexVoteAccepter.DivideAndRound(1, counter)); expectedFor3members.put( PlainTextStatsComponents.NOfSinks, VertexVoteAccepter.DivideAndRound(1, counter)); expectedFor3members.put( PlainTextStatsComponents.NOfWhites, VertexVoteAccepter.DivideAndRound(0, counter)); expectedFor3members.put( PlainTextStatsComponents.NOfEdges, VertexVoteAccepter.DivideAndRound(1, counter)); Map<PlainTextStatsComponents, Integer> expectedFor2members = new HashMap<PlainTextStatsComponents, Integer>(); expectedFor2members.put( PlainTextStatsComponents.NOfComponents, VertexVoteAccepter.DivideAndRound(1, counter)); expectedFor2members.put( PlainTextStatsComponents.NOfSources, VertexVoteAccepter.DivideAndRound(0, counter)); expectedFor2members.put( PlainTextStatsComponents.NOfSinks, VertexVoteAccepter.DivideAndRound(0, counter)); expectedFor2members.put( PlainTextStatsComponents.NOfWhites, VertexVoteAccepter.DivideAndRound(1, counter)); expectedFor2members.put( PlainTextStatsComponents.NOfEdges, VertexVoteAccepter.DivideAndRound(1, counter)); Map<PlainTextStatsComponents, Integer> expectedFor1members = new HashMap<PlainTextStatsComponents, Integer>(); expectedFor1members.put( PlainTextStatsComponents.NOfComponents, VertexVoteAccepter.DivideAndRound(1, counter)); expectedFor1members.put( PlainTextStatsComponents.NOfSources, VertexVoteAccepter.DivideAndRound(0, counter)); expectedFor1members.put( PlainTextStatsComponents.NOfSinks, VertexVoteAccepter.DivideAndRound(0, counter)); expectedFor1members.put( PlainTextStatsComponents.NOfWhites, VertexVoteAccepter.DivideAndRound(1, counter)); expectedFor1members.put( PlainTextStatsComponents.NOfEdges, VertexVoteAccepter.DivideAndRound(2, counter)); Assert.assertTrue(recorder.average(counter).isComponentsVotesEquals(3, expectedFor3members)); Assert.assertTrue(recorder.average(counter).isComponentsVotesEquals(2, expectedFor2members)); Assert.assertTrue(recorder.average(counter).isComponentsVotesEquals(1, expectedFor1members)); }