def overlap_test(): """ Test case for question A: Your goal for this question is to write a program that accepts two lines (x1,x2) and (x3,x4) on the x-axis and returns whether they overlap. As an example, (1,5) and (2,6) overlaps but not (1,5) and (6,8). :return: """ success = True if check_overlap(1, 2, 3, 4): success = False print('expected ' + str(False) + ' but got ' + str((check_overlap(1, 2, 3, 4)))) if not check_overlap(1, 3, 2, 4): success = False print('expected ' + str(True) + ' but got ' + str((check_overlap(1, 3, 2, 4)))) if check_overlap(3, 4, 1, 2): success = False print('expected ' + str(False) + ' but got ' + str((check_overlap(3, 4, 1, 2)))) if not check_overlap(2, 4, 1, 3): success = False print('expected ' + str(True) + ' but got ' + str((check_overlap(2, 4, 1, 3)))) if not check_overlap(2, 3, 1, 4): success = False print('expected ' + str(True) + ' but got ' + str((check_overlap(2, 3, 1, 4)))) if not check_overlap(1, 4, 2, 3): success = False print('expected ' + str(True) + ' but got ' + str((check_overlap(1, 4, 2, 3)))) if not check_overlap(1, 3, 1, 2): success = False print('expected ' + str(True) + ' but got ' + str((check_overlap(1, 3, 1, 2)))) if not check_overlap(1, 4, 2, 4): success = False print('expected ' + str(True) + ' but got ' + str((check_overlap(1, 4, 2, 4)))) if success: print('All overlapping tests successfully performed.\n') else: print('All overlapping tests performed. (With errors)\n')
def test_no_overlap(self): line1 = (1, 5) line2 = (6, 8) self.assertFalse(overlap.check_overlap(line1, line2))
def test_overlap(self): line1 = (1, 5) line2 = (2, 6) line3 = (6, 8) self.assertTrue(check_overlap(line1, line2)) self.assertFalse(check_overlap(line1, line3))
def test_negative_overlap(self): line1 = (-5, -10) line2 = (-6, -9) self.assertTrue(overlap.check_overlap(line1, line2))
def test_float_overlap(self): line1 = (5.7, 10.2) line2 = (6.4, 9.8) self.assertTrue(overlap.check_overlap(line1, line2))
def test_positive_overlap_inverted(self): line1 = (10, 5) line2 = (9, 6) self.assertTrue(overlap.check_overlap(line1, line2))
def test_positive_overlap_x1x2_equals_x3x4(self): line1 = (5, 10) line2 = (5, 10) self.assertTrue(overlap.check_overlap(line1, line2))
def test_positive_overlap_x3x4_in_x1x2(self): line1 = (5, 10) line2 = (6, 9) self.assertTrue(overlap.check_overlap(line1, line2))
def test_positive_overlap_x2_in_x3x4(self): line1 = (5, 10) line2 = (2, 7) self.assertTrue(overlap.check_overlap(line1, line2))
def test_positive_overlap(self): line1 = (1, 5) line2 = (2, 6) self.assertTrue(overlap.check_overlap(line1, line2))