def test_convert_pos_one_to_one(self): mapping = {} for x in range(0, 10): s = x * 10 + 1 mapping[Interval(s, s + 9)] = Interval(s, s + 9) for pos in range(1, 101): assert Interval.convert_pos(mapping, pos) == pos
def test_generate_interval_mapping_outside_range_error(self): temp = [ Interval(48556470, 48556646), Interval(48573290, 48573665), Interval(48575056, 48575078) ] mapping = generate_interval_mapping(input_intervals=temp, target_width=431.39453125, ratio=20, min_width=14, buffer_length=None, end=None, start=None, min_inter_width=10) st = min([x.start for x in temp]) end = min([x.end for x in temp]) Interval.convert_pos(mapping, st) Interval.convert_pos(mapping, end)
def test_convert_pos(self): mapping = {(1, 10): (101, 110), (21, 30): (201, 210), (41, 50): (301, 310)} self.assertEqual(105, Interval.convert_pos(mapping, 5)) self.assertEqual(101, Interval.convert_pos(mapping, 1)) self.assertEqual(310, Interval.convert_pos(mapping, 50)) with self.assertRaises(IndexError): Interval.convert_pos(mapping, 15) with self.assertRaises(IndexError): Interval.convert_pos(mapping, 0) with self.assertRaises(IndexError): Interval.convert_pos(mapping, 80)
def test_convert_pos_input_errors(self): # test input errors with self.assertRaises(AttributeError): # unequal length Interval.convert_pos({(1, 10): (4, 5)}, 3) with self.assertRaises(AttributeError): # overlapping ranges Interval.convert_pos({(1, 10): (11, 20), (5, 14): (21, 30)}, 6) with self.assertRaises(AttributeError): # range not increasing or decreasing mapping = {(1, 2): (1, 2), (3, 4): (4, 5), (5, 6): (3, 3)} Interval.convert_pos(mapping, 10) with self.assertRaises(AttributeError): # range not increasing or decreasing mapping = {(1, 2): (4, 5), (3, 4): (1, 2), (5, 6): (3, 3)} Interval.convert_pos(mapping, 10)
def test_convert_pos(self): mapping = { (1, 10): (101, 110), (21, 30): (201, 210), (41, 50): (301, 310) } assert Interval.convert_pos(mapping, 5) == 105 assert Interval.convert_pos(mapping, 1) == 101 assert Interval.convert_pos(mapping, 50) == 310 with pytest.raises(IndexError): Interval.convert_pos(mapping, 15) with pytest.raises(IndexError): Interval.convert_pos(mapping, 0) with pytest.raises(IndexError): Interval.convert_pos(mapping, 80)
def test_convert_pos_forward_to_reverse(self): mapping = { (41, 50): (101, 110), (21, 30): (201, 210), (1, 10): (301, 310) } assert Interval.convert_pos(mapping, 5) == 306 assert Interval.convert_pos(mapping, 41) == 110 assert Interval.convert_pos(mapping, 21) == 210 assert Interval.convert_pos(mapping, 1) == 310 assert Interval.convert_pos(mapping, 2) == 309 with pytest.raises(IndexError): Interval.convert_pos(mapping, 15) with pytest.raises(IndexError): Interval.convert_pos(mapping, 51) with pytest.raises(IndexError): Interval.convert_pos(mapping, 0) with pytest.raises(IndexError): Interval.convert_pos(mapping, 31)
def test_convert_pos_forward_to_reverse(self): mapping = {(41, 50): (101, 110), (21, 30): (201, 210), (1, 10): (301, 310)} self.assertEqual(306, Interval.convert_pos(mapping, 5)) self.assertEqual(110, Interval.convert_pos(mapping, 41)) self.assertEqual(210, Interval.convert_pos(mapping, 21)) self.assertEqual(310, Interval.convert_pos(mapping, 1)) self.assertEqual(309, Interval.convert_pos(mapping, 2)) with self.assertRaises(IndexError): Interval.convert_pos(mapping, 15) with self.assertRaises(IndexError): Interval.convert_pos(mapping, 51) with self.assertRaises(IndexError): Interval.convert_pos(mapping, 0) with self.assertRaises(IndexError): Interval.convert_pos(mapping, 31)