def test_five_chain(self): line_length = 3 line_length_sqr = line_length * line_length graph = self.create_chain_graph(line_count=5, line_length=line_length) betweenness = array.array( 'f', [0]) * 5 # Fastest way of allocating arrays of array.array-type node_counts = array.array('I', [0]) * 5 total_depths = array.array('f', [0]) * 5 pstalgo.FastSegmentBetweenness(graph_handle=graph, distance_type=DistanceType.STEPS, weigh_by_length=True, radius=pstalgo.Radii(steps=4), out_betweenness=betweenness, out_node_count=node_counts, out_total_depth=total_depths) pstalgo.FreeSegmentGraph(graph) self.assertEqual( betweenness, array.array('f', [ 0, 3 * line_length_sqr, 4 * line_length_sqr, 3 * line_length_sqr, 0 ])) self.assertEqual(node_counts, array.array('I', [5, 5, 5, 5, 5])) self.assertEqual(total_depths, array.array('f', [0, 0, 0, 0, 0]))
def test_split2(self): graph = self.create_split_graph2() betweenness = array.array('f', [0])*6 # Fastest way of allocating arrays of array.array-type pstalgo.SegmentBetweenness( graph_handle = graph, distance_type = DistanceType.ANGULAR, radius = pstalgo.Radii(angular=45), out_betweenness = betweenness) pstalgo.FreeGraph(graph) self.assertEqual(betweenness, array.array('f', [0, 1, 1, 2, 2, 0]))
def test_five_chain(self): graph = self.create_chain_graph(5) betweenness = array.array('f', [0])*5 # Fastest way of allocating arrays of array.array-type pstalgo.SegmentBetweenness( graph_handle = graph, distance_type = DistanceType.STEPS, radius = pstalgo.Radii(steps=4), out_betweenness = betweenness) pstalgo.FreeGraph(graph) self.assertEqual(betweenness, array.array('f', [0, 3, 4, 3, 0]))
def test_split2(self): graph = self.create_split_graph2() betweenness = array.array( 'f', [0]) * 6 # Fastest way of allocating arrays of array.array-type node_counts = array.array('I', [0]) * 6 total_depths = array.array('f', [0]) * 6 pstalgo.FastSegmentBetweenness(graph_handle=graph, distance_type=DistanceType.ANGULAR, weigh_by_length=False, radius=pstalgo.Radii(angular=45), out_betweenness=betweenness, out_node_count=node_counts, out_total_depth=total_depths) pstalgo.FreeSegmentGraph(graph) self.assertEqual(betweenness, array.array('f', [0, 1, 1, 3, 3, 0])) self.assertEqual(node_counts, array.array('I', [6, 6, 6, 6, 6, 6])) self.assertTrue( IsArrayRoughlyEqual(total_depths, [0.26, 4.24, 4.24, 3.87, 3.87, 0.26], 0.02))