From 54c97fc832a825267661a491c02e45d49800e675 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Thu, 18 Oct 2018 12:07:08 +0200 Subject: [PATCH] Do stuff. --- h2/tmptest.py | 72 +++++++++++++++------------------------------------ 1 file changed, 21 insertions(+), 51 deletions(-) diff --git a/h2/tmptest.py b/h2/tmptest.py index 7764f5d..a2c74a3 100644 --- a/h2/tmptest.py +++ b/h2/tmptest.py @@ -44,14 +44,12 @@ def write_to_log(file, data): def do_square_tests(amount_of_points): points_square = {util.gen_point(0, 100) for _ in range(amount_of_points)} - - results = [] - amount_of_points = str(amount_of_points) - results.append(TimedResult("graham", amount_of_points, time_it(graham_scan, args=(points_square,)))) - results.append(TimedResult("gift", amount_of_points, time_it(rapper, args=(points_square,)))) - results.append(TimedResult("quick", amount_of_points, time_it(quick_hull, args=(points_square,)))) - results.append(TimedResult("mbch", amount_of_points, time_it(mbc, args=(points_square,)))) + + results = [TimedResult("graham", amount_of_points, time_it(graham_scan, args=(points_square,))), + TimedResult("gift", amount_of_points, time_it(rapper, args=(points_square,))), + TimedResult("quick", amount_of_points, time_it(quick_hull, args=(points_square,))), + TimedResult("mbch", amount_of_points, time_it(mbc, args=(points_square,)))] write_to_log("square_tests.log", results) @@ -59,12 +57,10 @@ def do_square_tests(amount_of_points): def do_circular_tests(amount_of_points): points_circular = {util.gen_point(0, 100) for _ in range(amount_of_points)} - results = [] - - results.append(TimedResult("graham", amount_of_points, time_it(graham_scan, args=(points_circular,)))) - results.append(TimedResult("gift", amount_of_points, time_it(rapper, args=(points_circular,)))) - results.append(TimedResult("quick", amount_of_points, time_it(quick_hull, args=(points_circular,)))) - results.append(TimedResult("mbc", amount_of_points, time_it(mbc, args=(points_circular,)))) + results = [TimedResult("graham", amount_of_points, time_it(graham_scan, args=(points_circular,))), + TimedResult("gift", amount_of_points, time_it(rapper, args=(points_circular,))), + TimedResult("quick", amount_of_points, time_it(quick_hull, args=(points_circular,))), + TimedResult("mbc", amount_of_points, time_it(mbc, args=(points_circular,)))] write_to_log("circular_tests.log", results) @@ -73,12 +69,10 @@ def do_triangular_tests(amount_of_points): left, right, top = util.Point(1,1), util.Point(51,1), util.Point(26,40) points = {util.gen_triangular_point(left, right, top) for _ in range(amount_of_points)} - results = [] - - results.append(TimedResult("graham", amount_of_points, time_it(graham_scan, args=(points,)))) - results.append(TimedResult("gift", amount_of_points, time_it(rapper, args=(points,)))) - results.append(TimedResult("quick", amount_of_points, time_it(quick_hull, args=(points,)))) - results.append(TimedResult("mbc", amount_of_points, time_it(mbc, args=(points,)))) + results = [TimedResult("graham", amount_of_points, time_it(graham_scan, args=(points,))), + TimedResult("gift", amount_of_points, time_it(rapper, args=(points,))), + TimedResult("quick", amount_of_points, time_it(quick_hull, args=(points,))), + TimedResult("mbc", amount_of_points, time_it(mbc, args=(points,)))] write_to_log("triangular_tests.log", results) @@ -86,48 +80,24 @@ def do_triangular_tests(amount_of_points): def do_quadratic_tests(amount_of_points): points = {util.gen_weird_point(-10, 10) for _ in range(amount_of_points)} - results = [] - - results.append(TimedResult("graham", amount_of_points, time_it(graham_scan, args=(points,)))) - results.append(TimedResult("gift", amount_of_points, time_it(rapper, args=(points,)))) - results.append(TimedResult("quick", amount_of_points, time_it(quick_hull, args=(points,)))) - results.append(TimedResult("mbc", amount_of_points, time_it(mbc, args=(points,)))) + results = [TimedResult("graham", amount_of_points, time_it(graham_scan, args=(points,))), + TimedResult("gift", amount_of_points, time_it(rapper, args=(points,))), + TimedResult("quick", amount_of_points, time_it(quick_hull, args=(points,))), + TimedResult("mbc", amount_of_points, time_it(mbc, args=(points,)))] write_to_log("quadratic_tests.log", results) -""" -while True: -#for _ in range(1): - print("="*100) - points = {util.gen_point(1, 50) for i in range(10)} - #points = {util.Point(x=1.8814659430990304, y=85.47422952454252), util.Point(x=1.2175949045538488, y=-11.268797645030133), - # util.Point(x=-84.51422984381209, y=34.408366109887965), util.Point(x=10.200690892110572, y=-37.03966055144956), - # util.Point(x=16.52833187640779, y=-71.52321980457693)} - - # Sanity check +def sanity_check(): + points = {util.gen_point(1, 50) for i in range(100)} graham = set(graham_scan(points)) gift = set(rapper(points)) quick = quick_hull(points) mbch = set.union(mbc(points)) + assert gift == graham == quick == mbch - print("graham:", sorted(graham)) - print("gift :", sorted(gift)) - print("quick :", sorted(quick)) - print("mbch :", sorted(mbch)) - - if not gift == graham == quick == mbch: - print("Pppooooiiinnntttss",points) - util.display(points=points, hull=mbch) - break - - -print("graham:", time_it(graham_scan, args=(points,))) -print("gift:", time_it(rapper, args=(points,))) -print("quick:", time_it(quick_hull, args=(points,))) -print("mbch:", time_it(mbc, args=(points,))) -""" if __name__ == '__main__': + sanity_check() for i in range(50, 1000, 50): do_square_tests(i)