diff --git a/hexy/hexy.py b/hexy/hexy.py index 7733440..09444b8 100644 --- a/hexy/hexy.py +++ b/hexy/hexy.py @@ -115,7 +115,7 @@ def get_spiral(center, radius_start=1, radius_end=2): return np.array(hex_area) -def get_hex_line(hex_start, hex_end): +def get_hex_line(hex_start, hex_end): # TODO start and end seems to not be commutative, why ? """ Get hexes on line from hex_start to hex_end. :param hex_start: The hex where the line starts. @@ -124,7 +124,7 @@ def get_hex_line(hex_start, hex_end): """ hex_distance = get_cube_distance(hex_start, hex_end) if hex_distance < 1: - return np.array([hex_start]) + return np.array([hex_start.copy()]) # Set up linear system to compute linearly interpolated cube points bottom_row = np.array([i / hex_distance for i in np.arange(hex_distance)]) diff --git a/test/test_base_map.py b/test/test_base_map.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_hex_line.py b/test/test_hex_line.py index bebe436..b80712d 100644 --- a/test/test_hex_line.py +++ b/test/test_hex_line.py @@ -12,10 +12,16 @@ def test_get_hex_line(): start = np.array([-3, 3, 0]) end = np.array([1, 1, -2]) print(hx.get_hex_line(start, end)) - print(expected); + print(expected) assert(np.array_equal( hx.get_hex_line(start, end), - expected)); + expected)) + # testing one hex line special case + one_hex_line = hx.get_hex_line(start, start) + assert len(one_hex_line) == 1 + assert(np.array_equal(one_hex_line[0], start)) + assert id(start) != id(one_hex_line) + if __name__ == "__main__": test_get_hex_line() diff --git a/test/test_rounding.py b/test/test_rounding.py index 7db7298..8ffc365 100644 --- a/test/test_rounding.py +++ b/test/test_rounding.py @@ -5,12 +5,12 @@ def test_cube_round(): test_coords = np.array([ [1.1, -1.4, 0.3], [3.3, 2.3, -5.4], - ]); + ]) expected_coords = np.array([ [1, -1, 0], [3, 2, -5], - ]); + ]) assert(np.array_equal(hx.cube_round(test_coords), expected_coords)) @@ -18,11 +18,11 @@ def test_axial_round(): test_coords = np.array([ [1.1, -1.4], [3.3, 2.3], - ]); + ]) expected_coords = np.array([ [1, -1], [3, 2], - ]); + ]) assert(np.array_equal(hx.axial_round(test_coords), expected_coords)) diff --git a/test/test_selections.py b/test/test_selections.py index 842356a..95ca98b 100644 --- a/test/test_selections.py +++ b/test/test_selections.py @@ -47,22 +47,6 @@ def test_get_spiral(): _assert_np_array_equal(actual_array, expected_array) -def test_get_spiral(): - start_radius = 2 - end_radius = 4 - expected = [] - for r in range(start_radius, end_radius + 1): - expected += _get_linear_combinations(hx.W, hx.NW, r) + \ - _get_linear_combinations(hx.NW, hx.NE, r) + \ - _get_linear_combinations(hx.NE, hx.E, r) + \ - _get_linear_combinations(hx.E, hx.SE, r) + \ - _get_linear_combinations(hx.SE, hx.SW, r) + \ - _get_linear_combinations(hx.SW, hx.W, r) - - actual_array = hx.get_spiral([0, 0, 0], start_radius, end_radius) - expected_array = np.array(expected) - _assert_np_array_equal(actual_array, expected_array) - def test_get_disk(): expected = [[0, 0, 0]]