def test_random(self): num = 1 while num < 100000: print(num) num += 1 n = randint(0, 10) m = randint(1, 10) starts = [] ends = [] for i in range(n): point = randint(-10, 1000) starts.append(point) ends.append(point + randint(0, 100)) points = [] for _ in range(m): points.append(randint(-15, 1005)) myanswer = points_cover(starts, ends, points) naiveanswer = points_cover_naive(starts, ends, points) if myanswer != naiveanswer: print(len(myanswer), len(naiveanswer)) print(starts) print(ends) print(points) print(list(zip(myanswer, naiveanswer))) self.assertEqual(points_cover(starts, ends, points), points_cover_naive(starts, ends, points)) break
def test_small(self): for starts, ends, points in [ ([0, 7], [5, 10], [1, 6, 11]), ([1, -10], [3, 10], [-100, 100, 0]) ]: self.assertEqual(points_cover(list(starts), list(ends), list(points)), points_cover_naive(starts, ends, points))
def test_small(self): for starts, ends, points in [ ([0, 7], [5, 10], [1, 6, 11]), type here ]: self.assertEqual(points_cover(list(starts), list(ends), list(points)), points_cover_naive(starts, ends, points))
def test_random(self): for starts, ends, points in [([9, 10, 11, 2, 3], [30, 40, 16, 4, 5], [7, 2, 13, 15, 10, 33, 19])]: self.assertEqual( points_cover(list(starts), list(ends), list(points)), points_cover_naive(starts, ends, points))
def test_large(self): for (starts, ends, points, answer) in [ ([0] * 50000, [1] * 50000, list(range(2,40002)), [0]*40000) ]: self.assertEqual( points_cover(list(starts), list(ends), list(points)), answer )
def test_small(self): for starts, ends, points in [([0, 7], [5, 10], [1, 6, 11]), ([0, 5, 2, 3, 10], [3, 8, 6, 7, 11], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])]: self.assertEqual( points_cover(list(starts), list(ends), list(points)), points_cover_naive(starts, ends, points))
def test_large(self): for i in [5000]: data = [randint(0, i) for _ in range(i)] starts = [s - randint(0, i // 2) for s in data] ends = [e + randint(0, i // 2) for e in data] points = [randint(-i, i) for _ in range(i)] self.assertEqual(points_cover(starts, ends, points), fast_count_segments(starts, ends, points))
def test_small(self): for starts, ends, points in [ # ([0, 7], [5, 10], [1, 6, 11]), # ([4, 2], [10, 6], [5, 8, 3]), ([3, 3], [4, 4], [3, 3]) ]: self.assertEqual( points_cover(list(starts), list(ends), list(points)), points_cover_naive(starts, ends, points))
def test_random(self): for i in [10]: for times in range(1000000): data = [randint(-i, i) for _ in range(i)] starts = [s - randint(0, 10 * i) for s in data] ends = [e + randint(0, 10 * i) for e in data] points = [randint(-100 * i, 100 * i) for _ in range(i)] self.assertEqual(points_cover_naive(starts, ends, points), points_cover(starts, ends, points))
from test_helper import run_common_tests, failed, passed, check_tests_pass from organizing_lottery import points_cover, points_cover_naive from random import randint if __name__ == '__main__': run_common_tests() check_tests_pass("organizing_lottery_unit_tests.py") all_tests_passed = True for n in (3, 4, 5, 10, 100): for m in (3, 4, 100, 200): points = [randint(-10, 10) for _ in range(m)] starts = [randint(-5, 0) for _ in range(n)] ends = [randint(0, 5) for _ in range(n)] if points_cover(starts, ends, points) != points_cover_naive( starts, ends, points): all_tests_passed = False failed("Wrong answer for starts={}, ends={}, points={}".format( starts, ends, points)) break if all_tests_passed: passed()