From 5cc3f76c6ae8855bda2d0fde95fad3de866fd1ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Fri, 14 Sep 2018 11:03:19 +0100 Subject: [PATCH 01/25] Stuff as I got it from the previous postdoc --- fields_overlap/overlap.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 fields_overlap/overlap.py diff --git a/fields_overlap/overlap.py b/fields_overlap/overlap.py new file mode 100644 index 0000000..f31d0b4 --- /dev/null +++ b/fields_overlap/overlap.py @@ -0,0 +1,32 @@ +import matplotlib.pyplot as plt +from matplotlib.path import Path +import matplotlib.patches as patches + +def sf(f1, f2): + def vertices(L,B,R,T): + verts = [(L,B),(L,T),(R,T),(R,B),(L,B)] + return verts + codes = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY] + p1 = Path(vertices(*f1), codes) + p2 = Path(vertices(*f2), codes) + fig = plt.figure() + ax = fig.add_subplot(111) + pa1 = patches.PathPatch(p1, facecolor='orange', lw=2) + pa2 = patches.PathPatch(p2, facecolor='blue', lw=2) + ax.add_patch(pa1) + ax.add_patch(pa2) + ax.set_xlim(0,5) + ax.set_ylim(0,5) + fig.show() + + +def oa(f1, f2): + L1, B1, T1, R1 = f1 + L2, B2, T2, R2 = f2 + overL = max(L1, L2) + overB = max(B1, B2) + overR = min(R1, R2) + overT = min(T1, T2) + overH = (overT-overB) + overW = (overR-overL) + return overH*overW From 74aa837e73cf5c44c1b2aa841d3d2f02beb82c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Fri, 14 Sep 2018 11:50:06 +0100 Subject: [PATCH 02/25] Include a regression test This is the example we've been told that it works --- fields_overlap/test_overlap.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 fields_overlap/test_overlap.py diff --git a/fields_overlap/test_overlap.py b/fields_overlap/test_overlap.py new file mode 100644 index 0000000..dc95d2f --- /dev/null +++ b/fields_overlap/test_overlap.py @@ -0,0 +1,7 @@ +from overlap import oa + +def test_basic(): + ''' Tests that basic example works ''' + big_field = (1, 1, 4, 4) + inner_field = (2, 2, 3, 3) + assert oa(big_field, inner_field) == 1 From e34d2ec9fa0b1ca34dc8fe30d39bc94bde5c2bc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Fri, 14 Sep 2018 14:19:43 +0100 Subject: [PATCH 03/25] meaningful variable names --- fields_overlap/overlap.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/fields_overlap/overlap.py b/fields_overlap/overlap.py index f31d0b4..0452f6e 100644 --- a/fields_overlap/overlap.py +++ b/fields_overlap/overlap.py @@ -2,31 +2,32 @@ from matplotlib.path import Path import matplotlib.patches as patches -def sf(f1, f2): - def vertices(L,B,R,T): - verts = [(L,B),(L,T),(R,T),(R,B),(L,B)] +def show_fields(field1, field2): + def vertices(left, bottom, right, top): + verts = [(left, bottom), (left, top), (right, top), (right, bottom), (left, bottom)] return verts + codes = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY] - p1 = Path(vertices(*f1), codes) - p2 = Path(vertices(*f2), codes) + path1 = Path(vertices(*field1), codes) + path2 = Path(vertices(*field2), codes) fig = plt.figure() ax = fig.add_subplot(111) - pa1 = patches.PathPatch(p1, facecolor='orange', lw=2) - pa2 = patches.PathPatch(p2, facecolor='blue', lw=2) - ax.add_patch(pa1) - ax.add_patch(pa2) + patch1 = patches.PathPatch(path1, facecolor='orange', lw=2) + patch2 = patches.PathPatch(path2, facecolor='blue', lw=2) + ax.add_patch(patch1) + ax.add_patch(patch2) ax.set_xlim(0,5) ax.set_ylim(0,5) fig.show() -def oa(f1, f2): - L1, B1, T1, R1 = f1 - L2, B2, T2, R2 = f2 - overL = max(L1, L2) - overB = max(B1, B2) - overR = min(R1, R2) - overT = min(T1, T2) - overH = (overT-overB) - overW = (overR-overL) - return overH*overW +def overlap_area(field1, field2): + left1, bottom1, top1, right1 = field1 + left2, bottom2, top2, right2 = field2 + overlap_left = max(left1, left2) + overlap_bottom = max(bottom1, bottom2) + overlap_right = min(right1, right2) + overlap_top = min(top1, top2) + overlap_height = (overlap_top - overlap_bottom) + overlap_width = (overlap_right - overlap_left) + return overlap_height * overlap_width From 4627da87924644dadf4d3a1db18b6b93dc68b291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Fri, 14 Sep 2018 14:20:06 +0100 Subject: [PATCH 04/25] Update test to the new function name --- fields_overlap/test_overlap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fields_overlap/test_overlap.py b/fields_overlap/test_overlap.py index dc95d2f..63922bd 100644 --- a/fields_overlap/test_overlap.py +++ b/fields_overlap/test_overlap.py @@ -1,7 +1,7 @@ -from overlap import oa +from overlap import overlap_area def test_basic(): ''' Tests that basic example works ''' big_field = (1, 1, 4, 4) inner_field = (2, 2, 3, 3) - assert oa(big_field, inner_field) == 1 + assert overlap_area(big_field, inner_field) == 1 From d115866d79d26e268f3e407a63007aed4cd4b257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Fri, 14 Sep 2018 18:17:48 +0100 Subject: [PATCH 05/25] Add partial overlap test --- fields_overlap/test_overlap.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fields_overlap/test_overlap.py b/fields_overlap/test_overlap.py index 63922bd..2fbd3a8 100644 --- a/fields_overlap/test_overlap.py +++ b/fields_overlap/test_overlap.py @@ -5,3 +5,10 @@ def test_basic(): big_field = (1, 1, 4, 4) inner_field = (2, 2, 3, 3) assert overlap_area(big_field, inner_field) == 1 + + +def test_partial_overlap(): + ''' Tests when there's a partial overlap''' + base_field = (1, 1, 4, 3) + over_field = (2, 2, 3, 4) + assert overlap_area(base_field, over_field) == 1 From 76a5fba515eab6be21d3b816821c4f74bab9bc66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Fri, 14 Sep 2018 18:28:18 +0100 Subject: [PATCH 06/25] Add tests corner overlap... :warning: it fail! --- fields_overlap/test_overlap.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fields_overlap/test_overlap.py b/fields_overlap/test_overlap.py index 2fbd3a8..a14e8e8 100644 --- a/fields_overlap/test_overlap.py +++ b/fields_overlap/test_overlap.py @@ -12,3 +12,10 @@ def test_partial_overlap(): base_field = (1, 1, 4, 3) over_field = (2, 2, 3, 4) assert overlap_area(base_field, over_field) == 1 + + +def test_corner_overlap(): + ''' Test when there is a box in a corner''' + base_field = (1, 0, 3, 5) + over_field = (2, 4, 4, 6) + assert overlap_area(base_field, over_field) == 1 From 2bd4595bf5855da1de19ba7fb0324ef4988a997f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Fri, 14 Sep 2018 18:33:32 +0100 Subject: [PATCH 07/25] Fix inconsistency between plotting and area calculation --- fields_overlap/overlap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fields_overlap/overlap.py b/fields_overlap/overlap.py index 0452f6e..3bb7058 100644 --- a/fields_overlap/overlap.py +++ b/fields_overlap/overlap.py @@ -22,8 +22,8 @@ def vertices(left, bottom, right, top): def overlap_area(field1, field2): - left1, bottom1, top1, right1 = field1 - left2, bottom2, top2, right2 = field2 + left1, bottom1, right1, top1 = field1 + left2, bottom2, right2, top2 = field2 overlap_left = max(left1, left2) overlap_bottom = max(bottom1, bottom2) overlap_right = min(right1, right2) From 1846b51eed1a3fe7ce71f0f91eafba67e3c9d588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Fri, 14 Sep 2018 18:34:19 +0100 Subject: [PATCH 08/25] Make the limits in the plot as max value + 1 --- fields_overlap/overlap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fields_overlap/overlap.py b/fields_overlap/overlap.py index 3bb7058..26bd1d7 100644 --- a/fields_overlap/overlap.py +++ b/fields_overlap/overlap.py @@ -16,8 +16,8 @@ def vertices(left, bottom, right, top): patch2 = patches.PathPatch(path2, facecolor='blue', lw=2) ax.add_patch(patch1) ax.add_patch(patch2) - ax.set_xlim(0,5) - ax.set_ylim(0,5) + ax.set_xlim(0, max(*field1, *field2) + 1) + ax.set_ylim(0, max(*field1, *field2) + 1) fig.show() From 106dd5ac30e515e4098b2cee4c9343257101f903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Fri, 14 Sep 2018 18:46:39 +0100 Subject: [PATCH 09/25] test edge touching --- fields_overlap/test_overlap.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fields_overlap/test_overlap.py b/fields_overlap/test_overlap.py index a14e8e8..e7f227d 100644 --- a/fields_overlap/test_overlap.py +++ b/fields_overlap/test_overlap.py @@ -19,3 +19,10 @@ def test_corner_overlap(): base_field = (1, 0, 3, 5) over_field = (2, 4, 4, 6) assert overlap_area(base_field, over_field) == 1 + + +def test_edge_touching(): + ''' Test when there is an edge ''' + base_field = (1, 1, 4, 4) + over_field = (2, 2, 3, 4) + assert overlap_area(base_field, over_field) == 2 From ac2a787ec3f4fcc015aa6b68606a4d15a3555fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Fri, 14 Sep 2018 18:46:51 +0100 Subject: [PATCH 10/25] test 2 opposite edges touching --- fields_overlap/test_overlap.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fields_overlap/test_overlap.py b/fields_overlap/test_overlap.py index e7f227d..622bf82 100644 --- a/fields_overlap/test_overlap.py +++ b/fields_overlap/test_overlap.py @@ -26,3 +26,10 @@ def test_edge_touching(): base_field = (1, 1, 4, 4) over_field = (2, 2, 3, 4) assert overlap_area(base_field, over_field) == 2 + + +def test_2opposite_edge_touching(): + ''' Test when there is an edge ''' + base_field = (1, 1, 4, 4) + over_field = (2, 1, 3, 4) + assert overlap_area(base_field, over_field) == 3 From 6a7179f7030c6f33f40d2141934ab6cfd5dc2e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Sat, 15 Sep 2018 11:15:18 +0100 Subject: [PATCH 11/25] Outside edge test --- fields_overlap/test_overlap.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fields_overlap/test_overlap.py b/fields_overlap/test_overlap.py index 622bf82..674d47a 100644 --- a/fields_overlap/test_overlap.py +++ b/fields_overlap/test_overlap.py @@ -33,3 +33,10 @@ def test_2opposite_edge_touching(): base_field = (1, 1, 4, 4) over_field = (2, 1, 3, 4) assert overlap_area(base_field, over_field) == 3 + + +def test_outside_edge_touching(): + ''' Test when they are touching on the outside ''' + base_field = (1, 1, 4, 4) + over_field = (2, 4, 3, 5) + assert overlap_area(base_field, over_field) == 0 From 1f5086f8122e7832e722120777d8de1f1964ef93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Sat, 15 Sep 2018 11:20:44 +0100 Subject: [PATCH 12/25] Test when they are not overlapping :warning: test fails! --- fields_overlap/test_overlap.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fields_overlap/test_overlap.py b/fields_overlap/test_overlap.py index 674d47a..dd3740b 100644 --- a/fields_overlap/test_overlap.py +++ b/fields_overlap/test_overlap.py @@ -40,3 +40,10 @@ def test_outside_edge_touching(): base_field = (1, 1, 4, 4) over_field = (2, 4, 3, 5) assert overlap_area(base_field, over_field) == 0 + + +def test_no_overlap(): + ''' Test when they are not touching each other ''' + base_field = (0, 0, 3, 3) + over_field = (4, 4, 5, 5) + assert overlap_area(base_field, over_field) == 0 From edcbc51f01972972537880f0faf6e608a138aa07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Sat, 15 Sep 2018 11:45:24 +0100 Subject: [PATCH 13/25] Fix the tests - even when they are not touching --- fields_overlap/overlap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fields_overlap/overlap.py b/fields_overlap/overlap.py index 26bd1d7..a5930bb 100644 --- a/fields_overlap/overlap.py +++ b/fields_overlap/overlap.py @@ -28,6 +28,6 @@ def overlap_area(field1, field2): overlap_bottom = max(bottom1, bottom2) overlap_right = min(right1, right2) overlap_top = min(top1, top2) - overlap_height = (overlap_top - overlap_bottom) - overlap_width = (overlap_right - overlap_left) + overlap_height = max(0, overlap_top - overlap_bottom) + overlap_width = max(0, overlap_right - overlap_left) return overlap_height * overlap_width From 2f80d58f3c8154e04dd5073d8bc4f32720c23b13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Sat, 15 Sep 2018 11:58:16 +0100 Subject: [PATCH 14/25] Test floats - it seems to work! --- fields_overlap/test_overlap.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fields_overlap/test_overlap.py b/fields_overlap/test_overlap.py index dd3740b..f5c2a15 100644 --- a/fields_overlap/test_overlap.py +++ b/fields_overlap/test_overlap.py @@ -47,3 +47,10 @@ def test_no_overlap(): base_field = (0, 0, 3, 3) over_field = (4, 4, 5, 5) assert overlap_area(base_field, over_field) == 0 + + +def test_floats(): + ''' Test that still works when using floats ''' + base_field = (1, 1., 3.5, 3.5) + over_field = (3, 3, 5, 5) + assert overlap_area(base_field, over_field) == 0.5 * 0.5 From 0b01aa6dd1529a1e69ca24772d5e7f1f4d5e3864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Sat, 15 Sep 2018 12:10:34 +0100 Subject: [PATCH 15/25] Found a problem on floating points - :warning: test fails --- fields_overlap/test_overlap.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fields_overlap/test_overlap.py b/fields_overlap/test_overlap.py index f5c2a15..590f2f9 100644 --- a/fields_overlap/test_overlap.py +++ b/fields_overlap/test_overlap.py @@ -54,3 +54,10 @@ def test_floats(): base_field = (1, 1., 3.5, 3.5) over_field = (3, 3, 5, 5) assert overlap_area(base_field, over_field) == 0.5 * 0.5 + + +def test_floats_again(): + ''' Test that still works when using floats ''' + base_field = (1, 1., 3.3, 3.1) + over_field = (3, 3, 5, 5) + assert overlap_area(base_field, over_field) == 0.3 * 0.1 From d19b2c46a284706ec7fc6f8f5945b22fa00d830c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Sat, 15 Sep 2018 17:58:22 +0100 Subject: [PATCH 16/25] Fixed the test for floats! --- fields_overlap/test_overlap.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fields_overlap/test_overlap.py b/fields_overlap/test_overlap.py index 590f2f9..092a5ab 100644 --- a/fields_overlap/test_overlap.py +++ b/fields_overlap/test_overlap.py @@ -1,3 +1,5 @@ +from pytest import approx + from overlap import overlap_area def test_basic(): @@ -60,4 +62,4 @@ def test_floats_again(): ''' Test that still works when using floats ''' base_field = (1, 1., 3.3, 3.1) over_field = (3, 3, 5, 5) - assert overlap_area(base_field, over_field) == 0.3 * 0.1 + assert overlap_area(base_field, over_field) == approx(0.3 * 0.1, rel=1e-3) From 305f47170062cf92d68e4df66142dfd0bbf9e000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Sat, 15 Sep 2018 18:13:35 +0100 Subject: [PATCH 17/25] Testing negative numbers - :warning: it fails!! --- fields_overlap/test_overlap.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fields_overlap/test_overlap.py b/fields_overlap/test_overlap.py index 092a5ab..2074f56 100644 --- a/fields_overlap/test_overlap.py +++ b/fields_overlap/test_overlap.py @@ -63,3 +63,10 @@ def test_floats_again(): base_field = (1, 1., 3.3, 3.1) over_field = (3, 3, 5, 5) assert overlap_area(base_field, over_field) == approx(0.3 * 0.1, rel=1e-3) + + +def test_negative_basic(): + ''' Tests that basic example works ''' + big_field = (-1, -1, -4, -4) + inner_field = (-2, -2, -3, -3) + assert overlap_area(big_field, inner_field) == 1 From b09dfea4a2decda7cdebdb52ce5f9fd81f77082e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Sat, 15 Sep 2018 18:44:52 +0100 Subject: [PATCH 18/25] New test with negative values... this works! --- fields_overlap/test_overlap.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fields_overlap/test_overlap.py b/fields_overlap/test_overlap.py index 2074f56..0c81e0c 100644 --- a/fields_overlap/test_overlap.py +++ b/fields_overlap/test_overlap.py @@ -70,3 +70,10 @@ def test_negative_basic(): big_field = (-1, -1, -4, -4) inner_field = (-2, -2, -3, -3) assert overlap_area(big_field, inner_field) == 1 + + +def test_negative_basic2(): + ''' Tests that basic example works ''' + big_field = (-1, -1, 1, 1) + inner_field = (0, -2, 1, 2) + assert overlap_area(big_field, inner_field) == 2 From ba9a5ba2efafbf47a40095f690d598cdce331345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Sat, 15 Sep 2018 19:08:48 +0100 Subject: [PATCH 19/25] Throw error if coordinates are in wrong order --- fields_overlap/overlap.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fields_overlap/overlap.py b/fields_overlap/overlap.py index a5930bb..4943f48 100644 --- a/fields_overlap/overlap.py +++ b/fields_overlap/overlap.py @@ -24,6 +24,11 @@ def vertices(left, bottom, right, top): def overlap_area(field1, field2): left1, bottom1, right1, top1 = field1 left2, bottom2, right2, top2 = field2 + + if (left1 > right1 or bottom1 > top1 or + left2 > right2 or bottom2 > top2): + raise ValueError(" Coordinates need to be entered (left, bottom, right, top)") + overlap_left = max(left1, left2) overlap_bottom = max(bottom1, bottom2) overlap_right = min(right1, right2) From 10f2d1375f391d61f993126101238f0c3f67063e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Sat, 15 Sep 2018 19:20:14 +0100 Subject: [PATCH 20/25] Add documentation on how to use overlap_area --- fields_overlap/overlap.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/fields_overlap/overlap.py b/fields_overlap/overlap.py index 4943f48..297cc07 100644 --- a/fields_overlap/overlap.py +++ b/fields_overlap/overlap.py @@ -22,6 +22,24 @@ def vertices(left, bottom, right, top): def overlap_area(field1, field2): + ''' + Calculates the area of overlapping fields from the coordinates + of their corners. + + parameters + ---------- + field1: (tuple | list) of (int | float) + Coordinates of the first field. Order should be: (left, bottom, right, top) + + field2: (tuple | list) of (int | float) + Coordinates of the second field. Order should be: (left, bottom, right, top) + + Returns + ------- + int or float + Area in the coordinates entered unit. + ''' + left1, bottom1, right1, top1 = field1 left2, bottom2, right2, top2 = field2 From 8ba79ced71c07ea4472e5efca5ac429fa3cdc7c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Sat, 15 Sep 2018 19:27:13 +0100 Subject: [PATCH 21/25] Change negative values test to a negative test! It works! --- fields_overlap/test_overlap.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fields_overlap/test_overlap.py b/fields_overlap/test_overlap.py index 0c81e0c..a5811cd 100644 --- a/fields_overlap/test_overlap.py +++ b/fields_overlap/test_overlap.py @@ -1,4 +1,4 @@ -from pytest import approx +from pytest import approx, raises from overlap import overlap_area @@ -69,7 +69,8 @@ def test_negative_basic(): ''' Tests that basic example works ''' big_field = (-1, -1, -4, -4) inner_field = (-2, -2, -3, -3) - assert overlap_area(big_field, inner_field) == 1 + with raises(ValueError, message=" Coordinates need to be entered (left, bottom, right, top) "): + overlap_area(big_field, inner_field) def test_negative_basic2(): From d034fc6c47d90bad13cec79868e4bff24e9cc8f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Sat, 15 Sep 2018 19:52:58 +0100 Subject: [PATCH 22/25] Add coverage settings --- fields_overlap/pytest.ini | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 fields_overlap/pytest.ini diff --git a/fields_overlap/pytest.ini b/fields_overlap/pytest.ini new file mode 100644 index 0000000..a5c20e7 --- /dev/null +++ b/fields_overlap/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +addopts = --cov=overlap --cov-report html From 311b17a69631b76f538a08b76aa1d9e69c981e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Sat, 15 Sep 2018 20:05:01 +0100 Subject: [PATCH 23/25] Example to test using doctest --- fields_overlap/overlap.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fields_overlap/overlap.py b/fields_overlap/overlap.py index 297cc07..b024be3 100644 --- a/fields_overlap/overlap.py +++ b/fields_overlap/overlap.py @@ -38,6 +38,15 @@ def overlap_area(field1, field2): ------- int or float Area in the coordinates entered unit. + + Example + ------- + >>> from overlap import overlap_area + >>> field_a = (1, 1, 4, 4) # position in kms as (x_0, y_0, x_1, y_1) + >>> field_b = (2, 2, 3, 3) # smaller field inside field_a + >>> overlap_area(field_a, field_b) + 1 + ''' left1, bottom1, right1, top1 = field1 From c6cf15ca02b52cdd8dbf733f773e10482b732133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Sat, 15 Sep 2018 20:08:13 +0100 Subject: [PATCH 24/25] Add doctest to pytest --- fields_overlap/pytest.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fields_overlap/pytest.ini b/fields_overlap/pytest.ini index a5c20e7..446b3ff 100644 --- a/fields_overlap/pytest.ini +++ b/fields_overlap/pytest.ini @@ -1,2 +1,2 @@ [pytest] -addopts = --cov=overlap --cov-report html +addopts = --cov=overlap --cov-report html --doctest-modules From 0833b70fc490c5914ba791b4e07d725d59d68e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A9rez-Su=C3=A1rez?= Date: Mon, 17 Sep 2018 18:43:50 +0100 Subject: [PATCH 25/25] Adds configuration to run in Travis --- .travis.yml | 12 ++++++++++++ fields_overlap/requirements.txt | 3 +++ 2 files changed, 15 insertions(+) create mode 100644 .travis.yml create mode 100644 fields_overlap/requirements.txt diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b71cfbb --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: python +python: + - "3.6" + - "3.7-dev" # 3.7 development branch +before_install: + - cd fields_overlap +# command to install dependencies +install: + - pip install -r requirements.txt +# command to run tests +script: + - pytest diff --git a/fields_overlap/requirements.txt b/fields_overlap/requirements.txt new file mode 100644 index 0000000..5e9b7af --- /dev/null +++ b/fields_overlap/requirements.txt @@ -0,0 +1,3 @@ +pytest==3.2.0 +pytest-cov==2.6.0 +matplotlib==2.0.2