Exemplo n.º 1
0
 def test_with_one_segment_of_different_start_and_end(self):
     segments = \
     [
         Segment(0, 1)
     ]
     points = optimal_points(segments)
     self.assertEqual(1, len(points))
     self.assertEqual(1, points[0])
Exemplo n.º 2
0
 def test_with_two_overlapping_segments(self):
     segments = \
     [
         Segment(0, 2),
         Segment(1, 3)
     ]
     points = optimal_points(segments)
     self.assertEqual(1, len(points))
     self.assertEqual(2, points[0])
Exemplo n.º 3
0
 def test_with_two_continuous_segments(self):
     segments = \
     [
         Segment(0, 1),
         Segment(1, 2)
     ]
     points = optimal_points(segments)
     self.assertEqual(1, len(points))
     self.assertEqual(1, points[0])
Exemplo n.º 4
0
 def test_with_three_segments(self):
     segments = \
     [
         Segment(1, 3),
         Segment(2, 5),
         Segment(3, 6)
     ]
     points = optimal_points(segments)
     self.assertEqual(1, len(points))
     self.assertEqual(3, points[0])
Exemplo n.º 5
0
 def test_with_two_disjoint_segments(self):
     segments = \
     [
         Segment(0, 1),
         Segment(2, 3)
     ]
     points = optimal_points(segments)
     self.assertEqual(2, len(points))
     self.assertEqual(1, points[0])
     self.assertEqual(3, points[1])
Exemplo n.º 6
0
 def test_with_four_segments(self):
     segments = \
     [
         Segment(4, 7),
         Segment(1, 3),
         Segment(2, 5),
         Segment(5, 6)
     ]
     points = optimal_points(segments)
     self.assertEqual(2, len(points))
     self.assertEqual(3, points[0])
     self.assertEqual(6, points[1])
Exemplo n.º 7
0
 def test_with_four_segments_of_large_numbers(self):
     segments = \
     [
         Segment(4000, 7000),
         Segment(1000, 3000),
         Segment(2000, 5000),
         Segment(5000, int(math.pow(10, 9)))
     ]
     points = optimal_points(segments)
     self.assertEqual(2, len(points))
     self.assertEqual(3000, points[0])
     self.assertEqual(7000, points[1])
Exemplo n.º 8
0
 def test_with_start_bigger_than_end(self):
     segments = [Segment(1, 0)]
     optimal_points(segments)
Exemplo n.º 9
0
 def test_with_preceeding_lower_bound_of_end_among_elements(self):
     segments = [Segment(0, 0), Segment(0, -1), Segment(1, 1)]
     optimal_points(segments)
Exemplo n.º 10
0
 def test_with_preceeding_lower_bound_of_end(self):
     segments = [Segment(0, -1)]
     optimal_points(segments)
Exemplo n.º 11
0
 def test_with_preceeding_lower_bound_of_start(self):
     segments = [Segment(-1, 0)]
     optimal_points(segments)
Exemplo n.º 12
0
 def test_with_empty_segments(self):
     optimal_points([])
Exemplo n.º 13
0
 def test_sample_1(self):
     self.assertEqual([3], optimal_points([Segment(1, 3), Segment(2, 5), Segment(3, 6)]))
Exemplo n.º 14
0
 def test_sample_2(self):
     self.assertEqual([3, 6], optimal_points([Segment(4, 7), Segment(1, 3), Segment(2, 5), Segment(5, 6)]))
def test_optimal_points(segments, expected):
    assert optimal_points(segments) == expected
Exemplo n.º 16
0
2 5
3 6
Output:
1
3
In this sample, we have three segments: [1,3],[2,5],[3,6] (of length 2,3,3 respectively). All of them contain the point with coordinate 3: 1 ≤ 3 ≤ 3, 2 ≤ 3 ≤ 5, 3 ≤ 3 ≤ 6.

Sample 2.
Input:
4
4 7
1 3
2 5
5 6
Output:
2
3 6
The second and the third segments contain the point with coordinate 3 while the first and the fourth segments contain the point with coordinate 6. All the four segments cannot be covered by a single point, since the segments [1, 3] and [5, 6] are disjoint.
"""

assert_equal([3], optimal_points([Segment(1, 3),
                                  Segment(2, 5),
                                  Segment(3, 6)]), "sample 1")
assert_equal([3, 6],
             optimal_points(
                 [Segment(4, 7),
                  Segment(1, 3),
                  Segment(2, 5),
                  Segment(5, 6)]), "sample 2")
assert_equal(output3, optimal_points(sample3), "sample 3")