Skip to content
Snippets Groups Projects
Commit 85811ca2 authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

add: 1 working unit test

parent c91759b5
No related branches found
No related tags found
1 merge request!16Clhp map into main
File added
File added
No preview for this file type
...@@ -5,7 +5,7 @@ from math import cos ...@@ -5,7 +5,7 @@ from math import cos
import geopandas as gpd import geopandas as gpd
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from shapely.ops import linemerge, unary_union, polygonize from shapely.ops import linemerge, unary_union, polygonize
from shapely.geometry import Polygon, LineString, MultiLineString from shapely.geometry import Polygon, LineString
from server.consts import LAKE_RELATIONS_PATH from server.consts import LAKE_RELATIONS_PATH
...@@ -148,20 +148,20 @@ def create_grid(poly: Polygon, cell_width: float, cell_height: float): ...@@ -148,20 +148,20 @@ def create_grid(poly: Polygon, cell_width: float, cell_height: float):
# List to store all created lines # List to store all created lines
grid_lines = [] grid_lines = []
# Create new horizontal lines while within bounds # Create vertical lines while within bounds
y = min_y
while y <= max_y:
line = LineString([(min_x, y), (max_x, y)])
grid_lines.append(line)
y += cell_height
# Create new vertical lines while within bounds
x = min_x x = min_x
while x <= max_x: while x <= max_x:
line = LineString([(x, min_y), (x, max_y)]) line = LineString([(x, min_y), (x, max_y)])
grid_lines.append(line) grid_lines.append(line)
x += cell_width x += cell_width
# Create horizontal lines while within bounds
y = min_y
while y <= max_y:
line = LineString([(min_x, y), (max_x, y)])
grid_lines.append(line)
y += cell_height
return grid_lines return grid_lines
...@@ -199,10 +199,10 @@ def write_json_to_file(lake_name: str, map_data: dict): ...@@ -199,10 +199,10 @@ def write_json_to_file(lake_name: str, map_data: dict):
# to plot the map after each division to ensure that the map was divided as intended. # to plot the map after each division to ensure that the map was divided as intended.
def plot_map(divided_map): def plot_map(divided_map):
""" """
Plots a divided map using matplotlib. Plots the divisions of a map using matplotlib.
Parameters: Parameters:
divided_map (list): List of Shapely Polygons divided_map (list): List of Shapely Polygons to be plotted
""" """
print("Plotting... This may take some time...") print("Plotting... This may take some time...")
......
File added
File added
from shapely.geometry import Polygon, LineString
from server.map_handler.add_new_lake import create_grid from server.map_handler.add_new_lake import create_grid
#def tes_create_grid_default():
#grid = create_grid(0.2, 0.3) def test_create_grid_default():
#assert # Create a simple square polygon
\ No newline at end of file test_poly = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])
# Define the expected grid output
coordinates = [[(0, 0), (0, 1)], [(0.5, 0), (0.5, 1)], [(1, 0), (1, 1)],
[(0, 0), (1, 0)], [(0, 0.4), (1, 0.4)], [(0, 0.8), (1, 0.8)]]
expected = [LineString(coords) for coords in coordinates]
grid = create_grid(test_poly, 0.5, 0.4)
assert grid == expected
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment