Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made a strava competitor - utils #317

Closed
wants to merge 1 commit into from
Closed

Conversation

maxvonhippel
Copy link
Collaborator

No description provided.

Copy link

@benchify benchify bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 Benchify Analysis of PR 317

All tests have passed, indicating that the functions haversine_distance, total_route_distance, average_speed, fastest_segment, and fastest_known_time behave as expected. The tests cover various scenarios, including non-negative distance values, symmetric distances, and correct handling of edge cases such as zero time or empty lists. The haversine_distance function correctly calculates distances between geographical points, while the total_route_distance function accurately calculates the total distance of a route. The average_speed function correctly handles division by zero, and the fastest_segment and fastest_known_time functions correctly identify the fastest time from a list of route times. Overall, the code handles different inputs and edge cases correctly, providing a solid foundation for geographical and route-related calculations.

import math

# Function to calculate the distance between two points using the Haversine formula
def haversine_distance(coord1: Tuple[float, float], coord2: Tuple[float, float]) -> float:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Haversine distance is non-negative
The haversine_distance function should always return a non-negative value, representing the distance between two geographical points.

Outcome Example Input # Inputs % of Total
coord1=(0.0, 0.0)
coord2=(0.0, 0.0)
200 100.0%

view all inputs
The test for the haversine_distance function has passed, confirming that it returns a non-negative value for the given coordinates (0.0, 0.0) and (0.0, 0.0), which is consistent with the expected behavior of representing a distance between two geographical points. The function correctly calculated the distance between these two points, which are essentially the same location, resulting in a distance of 0. With no error type or trace reported, the function is working as intended for this test case.

Unit Tests
# Unit Test for "Haversine distance is non-negative": The haversine_distance function should always return a non-negative value, representing the distance between two geographical points.
def benchify_test_haversine_distance_non_negative(coord1, coord2):
    distance = haversine_distance(coord1, coord2)
    assert distance >= 0

def benchify_test_haversine_distance_non_negative_exec_test_passing_0():
    coord1=(0.0, 0.0)
    coord2=(0.0, 0.0)
    benchify_test_haversine_distance_non_negative(coord1, coord2)

import math

# Function to calculate the distance between two points using the Haversine formula
def haversine_distance(coord1: Tuple[float, float], coord2: Tuple[float, float]) -> float:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Haversine distance is zero for identical points
The haversine_distance function should return zero if and only if the two input coordinates are identical.

Outcome Example Input # Inputs % of Total
coord=(0.0
0.0)
200 100.0%

view all inputs
The property-based test for the haversine_distance function has passed, confirming that it returns zero when given identical coordinates, such as coord=(0.0, 0.0). This result aligns with the expected behavior described in the property description. The test's success indicates that the function is working correctly for this specific scenario, with no errors or exceptions encountered during execution.

Unit Tests
# Unit Test for "Haversine distance is zero for identical points": The haversine_distance function should return zero if and only if the two input coordinates are identical.
def benchify_test_haversine_distance_zero_for_identical_points(coord):
    distance = haversine_distance(coord, coord)
    assert distance == 0

def benchify_test_haversine_distance_zero_for_identical_points_exec_test_passing_0():
    coord=(0.0
    arg1 = 0.0)
    benchify_test_haversine_distance_zero_for_identical_points(coord, arg1)

import math

# Function to calculate the distance between two points using the Haversine formula
def haversine_distance(coord1: Tuple[float, float], coord2: Tuple[float, float]) -> float:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Haversine distance is symmetric
The haversine_distance function should be symmetric, meaning that the distance from coord1 to coord2 should be the same as from coord2 to coord1.

Outcome Example Input # Inputs % of Total
coord1=(0.0, 0.0)
coord2=(0.0, 0.0)
200 100.0%

view all inputs
The test for the haversine_distance function's symmetry has passed, confirming that the distance from coord1 to coord2 is the same as from coord2 to coord1, as expected. With the given arguments, coord1=(0.0, 0.0) and coord2=(0.0, 0.0), the function correctly calculated the same distance in both directions. This result supports the property that the haversine_distance function is symmetric, meaning it does not matter which coordinate is used as the starting point.

Unit Tests
# Unit Test for "Haversine distance is symmetric": The haversine_distance function should be symmetric, meaning that the distance from coord1 to coord2 should be the same as from coord2 to coord1.
def benchify_test_haversine_distance_symmetric(coord1, coord2):
    distance1 = haversine_distance(coord1, coord2)
    distance2 = haversine_distance(coord2, coord1)
    assert distance1 == distance2

def benchify_test_haversine_distance_symmetric_exec_test_passing_0():
    coord1=(0.0, 0.0)
    coord2=(0.0, 0.0)
    benchify_test_haversine_distance_symmetric(coord1, coord2)

return distance

# Function to calculate the total distance of a route given a list of coordinates
def total_route_distance(route: List[Tuple[float, float]]) -> float:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Total distance is non-negative
The total distance calculated by total_route_distance should always be a non-negative number, even if the route contains only one point.

Outcome Example Input # Inputs % of Total
route=[(0.0, 0.0)] 200 100.0%

view all inputs
The property-based test has passed, indicating that the total_route_distance function correctly calculates a non-negative total distance for a given route. With the provided argument route=[(0.0, 0.0)], the test confirmed that the total distance is greater than or equal to 0.0, aligning with the expected property that the total distance should always be non-negative. This suggests that the function behaves as intended for routes with a single point, and no further action is required.

Unit Tests
# Unit Test for "Total distance is non-negative": The total distance calculated by `total_route_distance` should always be a non-negative number, even if the route contains only one point.
def benchify_test_total_distance_non_negative(route):
    total_distance = total_route_distance(route)
    assert total_distance >= 0.0

def benchify_test_total_distance_non_negative_exec_test_passing_0():
    route=[(0.0, 0.0)]
    benchify_test_total_distance_non_negative(route)

return distance

# Function to calculate the total distance of a route given a list of coordinates
def total_route_distance(route: List[Tuple[float, float]]) -> float:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Total distance is zero for a single point
If the route contains only one point, the total_route_distance function should return 0.0 since there is no distance to calculate.

Outcome Example Input # Inputs % of Total
route=[(0.0, 0.0)] 200 100.0%

view all inputs
The property-based test has passed, indicating that the total_route_distance function correctly returns 0.0 when given a route with only one point, as specified in the property description. The test was run with the argument route=[(0.0, 0.0)], which represents a single point at coordinates (0.0, 0.0). Since there is no error type or trace, the function is behaving as expected for this specific case.

Unit Tests
# Unit Test for "Total distance is zero for a single point": If the `route` contains only one point, the `total_route_distance` function should return 0.0 since there is no distance to calculate.
def benchify_test_single_point_distance(route):
    total_distance = total_route_distance(route)
    assert total_distance == 0.0

def benchify_test_single_point_distance_exec_test_passing_0():
    route=[(0.0, 0.0)]
    benchify_test_single_point_distance(route)

return total_distance / total_time

# Function to find the fastest segment in a route given a list of segment times
def fastest_segment(segment_times: List[float]) -> float:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Fastest segment is less than or equal to all elements
For any non-empty list segment_times, the result of fastest_segment(segment_times) should be less than or equal to every element in segment_times.

Outcome Example Input # Inputs % of Total
segment_times=[0.0] 200 100.0%

view all inputs
The property-based test has passed, indicating that the fastest_segment function behaves as expected. With the input segment_times=[0.0], the function correctly returns the fastest segment time, which is less than or equal to every element in the input list. The test confirms that the function satisfies the property that the fastest segment time is always less than or equal to every segment time in the input list.

Unit Tests
# Unit Test for "Fastest segment is less than or equal to all elements": For any non-empty list `segment_times`, the result of `fastest_segment(segment_times)` should be less than or equal to every element in `segment_times`.
def benchify_test_fastest_segment_non_empty(segment_times):
    fastest = fastest_segment(segment_times)
    assert all(fastest <= time for time in segment_times)

def benchify_test_fastest_segment_non_empty_exec_test_passing_0():
    segment_times=[0.0]
    benchify_test_fastest_segment_non_empty(segment_times)

return total_distance / total_time

# Function to find the fastest segment in a route given a list of segment times
def fastest_segment(segment_times: List[float]) -> float:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Fastest segment handles single element list
The function fastest_segment should return the single element when the input list segment_times contains only one element.

Outcome Example Input # Inputs % of Total
segment_times=[0.0] 200 100.0%

view all inputs
The property-based test has passed, confirming that the fastest_segment function behaves as expected when given a list with a single element, returning that single element as the fastest segment time. The test case used an input list segment_times containing only one element, [0.0], and the function correctly returned this value. This result verifies the property description, which states that the function should return the single element when the input list contains only one element.

Unit Tests
# Unit Test for "Fastest segment handles single element list": The function `fastest_segment` should return the single element when the input list `segment_times` contains only one element.
def benchify_test_fastest_segment_single_element(segment_times):
    assert fastest_segment(segment_times) == segment_times[0]

def benchify_test_fastest_segment_single_element_exec_test_passing_0():
    segment_times=[0.0]
    benchify_test_fastest_segment_single_element(segment_times)

return min(segment_times)

# Function to find the fastest known time (FKT) for a given route
def fastest_known_time(route_times: List[float]) -> float:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ "Fastest Known Time for Non-Empty List"
The function fastest_known_time should return the smallest value from the route_times list when it is not empty. This ensures that the function correctly identifies the fastest time from the provided list of route times.

Outcome Example Input # Inputs % of Total
route_times=[0.0] 200 100.0%

view all inputs
The property-based test for the fastest_known_time function has passed, indicating that it correctly returns the smallest value from the route_times list when it is not empty. With the provided argument route_times=[0.0], the function behaved as expected, confirming its ability to identify the fastest time from a list of route times. This passing result suggests that the function is working correctly for non-empty lists of route times.

Unit Tests
# Unit Test for ""Fastest Known Time for Non-Empty List"": The function `fastest_known_time` should return the smallest value from the `route_times` list when it is not empty. This ensures that the function correctly identifies the fastest time from the provided list of route times.
def benchify_test_fastest_known_time_non_empty(route_times):
    result = fastest_known_time(route_times)
    assert result == min(route_times)

def benchify_test_fastest_known_time_non_empty_exec_test_passing_0():
    route_times=[0.0]
    benchify_test_fastest_known_time_non_empty(route_times)

return min(segment_times)

# Function to find the fastest known time (FKT) for a given route
def fastest_known_time(route_times: List[float]) -> float:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ "Fastest Known Time for Empty List"
The function fastest_known_time should return 0.0 when the route_times list is empty. This ensures that the function handles the edge case of an empty list correctly.

Outcome Example Input # Inputs % of Total
route_times=[] 1 100.0%

view all inputs
The property-based test for the fastest_known_time function has passed, confirming that it correctly handles the edge case of an empty route_times list by returning 0.0. The test, defined by the code @given(route_times=st.just([])), verified this behavior with an empty list as input. With this passing result, the function is ensured to behave as expected when given no route times, providing a reliable foundation for further testing and implementation.

Unit Tests
# Unit Test for ""Fastest Known Time for Empty List"": The function `fastest_known_time` should return `0.0` when the `route_times` list is empty. This ensures that the function handles the edge case of an empty list correctly.
def benchify_test_fastest_known_time_empty(route_times):
    result = fastest_known_time(route_times)
    assert result == 0.0

def benchify_test_fastest_known_time_empty_exec_test_passing_0():
    route_times=[]
    benchify_test_fastest_known_time_empty(route_times)

return min(segment_times)

# Function to find the fastest known time (FKT) for a given route
def fastest_known_time(route_times: List[float]) -> float:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ "Fastest Known Time is Non-Negative"
The function fastest_known_time should always return a non-negative value, as route times represent durations and cannot be negative.

Outcome Example Input # Inputs % of Total
route_times=[] 200 100.0%

view all inputs
The property-based test has passed, indicating that the fastest_known_time function always returns a non-negative value as expected. With an empty list of route times (route_times=[]), the function correctly returns 0.0, aligning with the property that route times represent durations and cannot be negative. This suggests that the function is behaving as intended, returning the minimum time from the list of route times or 0.0 when the list is empty.

Unit Tests
# Unit Test for ""Fastest Known Time is Non-Negative"": The function `fastest_known_time` should always return a non-negative value, as route times represent durations and cannot be negative.
def benchify_test_fastest_known_time_non_negative(route_times):
    result = fastest_known_time(route_times)
    assert result >= 0.0

def benchify_test_fastest_known_time_non_negative_exec_test_passing_0():
    route_times=[]
    benchify_test_fastest_known_time_non_negative(route_times)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant