def test_get_start_positions(indexed_interval): positions = [ obg.Position(10, 7), obg.Position(11, 5), obg.Position(-11, 5), obg.Position(13, 2) ] linear_filter = LinearFilter(positions, indexed_interval) start_positions = linear_filter.find_start_positions() assert start_positions == {"+": [2, 10, 17], "-": [10]}
def setUp(self): self.snarl_map = LinearSnarlMap.from_snarl_graph(snarl_graph2, graph) self.graph_positions = [obg.Position(5, 4), obg.Position(3, 4), obg.Position(12, 4), obg.Position(13, 4)] self.linear_positions = [4, 31/20*4, 10+21/20*4, 14] self.linear_positions = [p for p in self.linear_positions] self.graph_interval = obg.DirectedInterval(self.graph_positions[0], self.graph_positions[2])
def get_start_and_end_positions(self): positions = [] for node, starts_and_ends in self.areas.items(): n_starts_ends = len(starts_and_ends) for start in starts_and_ends[range(0, n_starts_ends, 2)]: if self._is_start_position(node, start): positions.append(obg.Position(node, start)) for end in starts_and_ends[range(1, n_starts_ends, 2)]: if self._is_end_position(node, end): positions.append(obg.Position(node, end - 1)) # Correct to non-inclusive end, since this may be interpreted as a start return positions
def get_start_positions(self): start_positions = [ obg.Position(-node_id, self.graph.node_size(node_id)-offset) for node_id, offset in self.starts.items()] node_ids = list(self.full_areas.keys()) + [ -node_id for node_id in self.full_areas] previous_nodes_list = [ self.graph.reverse_adj_list[-node_id] for node_id in node_ids] def filter_my_nodes(node_list): return [node_id for node_id in node_list if abs(node_id) in self.full_areas or node_id in self.starts] previous_nodes_list = [filter_my_nodes(prev_nodes) for prev_nodes in previous_nodes_list] full_starts = [obg.Position(node_id, 0) for node_id, prev_nodes in zip(node_ids, previous_nodes_list) if not prev_nodes] return start_positions + full_starts
def to_obg(self): return offsetbasedgraph.Position(self.node_id, self.offset)
def indexed_interval(): start = obg.Position(10, 5) end = obg.Position(13, 5) return obg.IndexedInterval(start, end, [10, 11, 13], graph=graph())
def test_translate(self): position = Position(10, 20, False) obg_position = offsetbasedgraph.Position(10, 20) trans_position = position.to_obg() self.assertEqual(trans_position, obg_position)
def _generate_start_positon(self): rp = random.choice(list(self._graph.blocks.keys())) offset = random.randint(0, self._graph.node_size(rp)-1) return obg.Position(rp, offset)