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

add: one more unit test

parent 85811ca2
No related branches found
No related tags found
1 merge request!16Clhp map into main
.coverage 0 → 100644
File added
[
"Mjøsa",
"Skumsjøen"
"Skumsjøen",
"test_lake"
]
\ No newline at end of file
{"test-field1": "test-value1", "test-field2": ["test-value2", "testvalue3"]}
\ No newline at end of file
No preview for this file type
import json
from shapely.geometry import Polygon, LineString
from server.map_handler.add_new_lake import create_grid
from server.consts import LAKE_RELATIONS_PATH
from server.map_handler.add_new_lake import create_grid, write_json_to_file
def test_create_grid_default():
def test_create_grid_default() -> None:
# Create a simple square polygon
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)]]
[(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
def test_write_json_to_file() -> None:
# Define some test data
test_lake_name = "test_lake"
test_data = {
'test-field1': 'test-value1',
'test-field2': [
"test-value2",
"testvalue3"
],
}
# Call the function that is being tested
write_json_to_file(test_lake_name, test_data)
# Try to read the data from the newly created file
with open(LAKE_RELATIONS_PATH + '/' + test_lake_name + '_div.json', 'r') as f:
result = json.load(f)
assert result == test_data
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