Skip to content

strava competitor - idk if it works at all -- we be vibing #315

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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 315

The analysis reveals that most properties related to the calculate_distance, calculate_elevation_gain, and save_activity functions are passing. However, several properties related to the get_user_activities function are failing due to issues with directory creation and file handling, specifically when dealing with empty or invalid user_id and base_dir parameters. Additionally, the calculate_pace function and the save_activity function have failing properties related to correctness and activity data modification. To address these issues, the code should be modified to handle edge cases and validate input parameters more robustly, particularly for the get_user_activities and save_activity functions. The calculate_pace function should also be reviewed to ensure its correctness.

import os
from typing import Dict, List, Tuple, Optional, Union, Any

def calculate_distance(coords: 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.

✅ Distance Calculation with Single Coordinate
The function should return 0.0 when the list of coordinates contains only one point, as there are no consecutive points to calculate a distance between.

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

view all inputs
The property-based test has passed, indicating that the calculate_distance function behaves as expected when given a list containing a single GPS coordinate, returning a distance of 0.0 as there are no consecutive points to calculate a distance between, with the test using the argument coords=[(0.0, 0.0)]. This result aligns with the described property that the function should return 0.0 for a single point. The test confirms the function's correctness for this specific scenario.

Unit Tests
# Unit Test for "Distance Calculation with Single Coordinate": The function should return 0.0 when the list of coordinates contains only one point, as there are no consecutive points to calculate a distance between.
def benchify_test_single_coordinate_returns_zero(coords):
    distance = calculate_distance(coords)
    assert distance == 0.0

def benchify_test_single_coordinate_returns_zero_exec_test_passing_0():
    coords=[(0.0, 0.0)]
    benchify_test_single_coordinate_returns_zero(coords)

import os
from typing import Dict, List, Tuple, Optional, Union, Any

def calculate_distance(coords: 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.

✅ Non-decreasing Distance with Additional Coordinates
Adding more coordinates to the list should not decrease the total distance calculated by the function.

Outcome Example Input # Inputs % of Total
coords=[(0.0, 0.0), (0.0, 0.0)... view full input 200 100.0%

view all inputs
The property-based test has passed, indicating that adding more coordinates to the list does not decrease the total distance calculated by the function. With the provided arguments, coords=[(0.0, 0.0), (0.0, 0.0)], the test confirmed that the total distance remains non-decreasing when a new coordinate is added. This suggests that the calculate_distance function is behaving as expected, and the test has validated the property that adding more coordinates does not decrease the total distance.

Unit Tests
# Unit Test for "Non-decreasing Distance with Additional Coordinates": Adding more coordinates to the list should not decrease the total distance calculated by the function.
def benchify_test_distance_non_decreasing_with_more_coords(coords):
    initial_distance = calculate_distance(coords)
    new_coord = (0.0, 0.0)
    new_distance = calculate_distance(coords + [new_coord])
    assert new_distance >= initial_distance

def benchify_test_distance_non_decreasing_with_more_coords_exec_test_passing_0():
    coords=[(0.0, 0.0), (0.0, 0.0)]
    benchify_test_distance_non_decreasing_with_more_coords(coords)

import os
from typing import Dict, List, Tuple, Optional, Union, Any

def calculate_distance(coords: 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.

✅ Non-negative Distance Calculation
The function should always return a non-negative distance, regardless of the input coordinates.

Outcome Example Input # Inputs % of Total
coords=[(0.0, 0.0), (0.0, 0.0)... view full input 200 100.0%

view all inputs
The property-based test has passed, indicating that the calculate_distance function correctly returns a non-negative distance for the given input coordinates [(0.0, 0.0), (0.0, 0.0)]. This suggests that the function behaves as expected, returning a distance of 0.0 kilometers for identical coordinates. With no error type or trace reported, the test result confirms the function's correctness for this specific input scenario.

Unit Tests
# Unit Test for "Non-negative Distance Calculation": The function should always return a non-negative distance, regardless of the input coordinates.
def benchify_test_distance_is_non_negative(coords):
    distance = calculate_distance(coords)
    assert distance >= 0.0

def benchify_test_distance_is_non_negative_exec_test_passing_0():
    coords=[(0.0, 0.0), (0.0, 0.0)]
    benchify_test_distance_is_non_negative(coords)


return total_distance

def calculate_elevation_gain(elevation_data: 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.

✅ Elevation gain is non-negative
The function calculate_elevation_gain should always return a non-negative value, as it only sums positive elevation differences.

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

view all inputs
The test for the calculate_elevation_gain function has passed, indicating that it correctly returns a non-negative value for the given elevation data [0.0, 0.0]. This aligns with the expected property that the function should only sum positive elevation differences, resulting in a non-negative total elevation gain. The test result confirms that the function behaves as intended, with no errors or exceptions encountered during execution.

Unit Tests
# Unit Test for "Elevation gain is non-negative": The function `calculate_elevation_gain` should always return a non-negative value, as it only sums positive elevation differences.
def benchify_test_elevation_gain_non_negative(elevation_data):
    result = calculate_elevation_gain(elevation_data)
    assert result >= 0

def benchify_test_elevation_gain_non_negative_exec_test_passing_0():
    elevation_data=[0.0, 0.0]
    benchify_test_elevation_gain_non_negative(elevation_data)


return total_distance

def calculate_elevation_gain(elevation_data: 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.

✅ Zero gain for non-increasing elevation
If all elements in elevation_data are the same or in non-increasing order, the function should return zero, as there would be no positive elevation gain.

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

view all inputs
The test has passed, indicating that the calculate_elevation_gain function behaves as expected when given elevation data with no positive gain, such as [0.0, 0.0]. The function correctly returns zero, confirming that it handles non-increasing elevation data as described in the property. This result suggests that the function is working correctly for this specific scenario, with no errors or issues encountered during the test.

Unit Tests
# Unit Test for "Zero gain for non-increasing elevation": If all elements in `elevation_data` are the same or in non-increasing order, the function should return zero, as there would be no positive elevation gain.
def benchify_test_zero_gain_for_non_increasing_elevation(elevation_data):
    sorted_data = sorted(elevation_data, reverse=True)
    result = calculate_elevation_gain(sorted_data)
    assert result == 0

def benchify_test_zero_gain_for_non_increasing_elevation_exec_test_passing_0():
    elevation_data=[0.0, 0.0]
    benchify_test_zero_gain_for_non_increasing_elevation(elevation_data)


return (minutes, seconds)

def save_activity(user_id: str, activity_data: Dict[str, Any],
Copy link

Choose a reason for hiding this comment

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

❌ Activity Data Modification
The function save_activity should add an 'id' key with the generated activity ID and a 'timestamp' key with the current timestamp to the activity_data dictionary before saving it.

Outcome Example Input # Inputs % of Total
user_id='0'
activity_data={}
200 100.0%

view all inputs
The test failed with an AssertionError because the activity_data dictionary was empty, causing the assertion 'id' in activity_data to fail. The error occurred when user_id='0' and activity_data={} were passed to the test_activity_data_modification function, indicating that the save_activity function did not add the 'id' key to the activity_data dictionary as expected. The issue may be due to the fact that the activity_data dictionary was not modified by the save_activity function before the assertion was made.

Stack Trace
Traceback (most recent call last):
  File "/app/repo/StravaCompetitor/pver_fb14676c-49b7-4f06-aa43-d18f7ea2619e-test.py", line 319, in wrapper
    ret = func(*args, **kwargs)
  File "/app/repo/StravaCompetitor/pver_fb14676c-49b7-4f06-aa43-d18f7ea2619e-test.py", line 491, in test_activity_data_modification
    assert "id" in activity_data
AssertionError: assert 'id' in {}
Unit Tests
# Unit Test for "Activity Data Modification": The function `save_activity` should add an 'id' key with the generated activity ID and a 'timestamp' key with the current timestamp to the `activity_data` dictionary before saving it.
def benchify_test_activity_data_modification(user_id, activity_data):
    activity_id = save_activity(user_id, activity_data.copy())
    assert "id" in activity_data
    assert activity_data["id"] == activity_id
    assert "timestamp" in activity_data

def benchify_test_activity_data_modification_exec_test_failing_0():
    user_id='0'
    activity_data={}
    benchify_test_activity_data_modification(user_id, activity_data)


return activity_id

def get_user_activities(user_id: str, limit: Optional[int] = None,
Copy link

Choose a reason for hiding this comment

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

✅ Returns empty list if user directory does not exist
The function should return an empty list if the directory corresponding to the user_id does not exist.

Outcome Example Input # Inputs % of Total
user_id=''
limit=1
activity_type=''
base_dir=''
194 100.0%

view all inputs
The property-based test has passed, confirming that the get_user_activities function returns an empty list when the directory corresponding to the user_id does not exist, as specified by the property description. With input arguments such as user_id='', limit=1, activity_type='', and base_dir='', the function behaves as expected. This passing result indicates that the function is working correctly under these conditions, with no errors or exceptions encountered during the test.

Unit Tests
# Unit Test for "Returns empty list if user directory does not exist": The function should return an empty list if the directory corresponding to the user_id does not exist.
def benchify_test_get_user_activities_no_directory(user_id, limit, activity_type, base_dir):
    
    result = get_user_activities(user_id, limit, activity_type, base_dir)
    assert result == []

def benchify_test_get_user_activities_no_directory_exec_test_passing_0():
    user_id=''
    limit=1
    activity_type=''
    base_dir=''
    benchify_test_get_user_activities_no_directory(user_id, limit, activity_type, base_dir)


return activity_id

def get_user_activities(user_id: str, limit: Optional[int] = None,
Copy link

Choose a reason for hiding this comment

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

❌ Returns activities sorted by timestamp
The function should return a list of activities sorted by the 'timestamp' key in descending order.

Outcome Example Input # Inputs % of Total
user_id=''
limit=1
activity_type=''
base_dir=''
8 4.0%
user_id='TAJgi'
limit=1
activity_type=''
base_dir=''
192 96.0%

view all inputs
The test failed due to a FileNotFoundError when attempting to create a directory with an empty path, as indicated by the args showing user_id='' and base_dir=''. This error occurred because the os.makedirs function was called with an empty string, which is not a valid directory path. To resolve this issue, the function should be modified to handle empty or invalid input values for user_id and base_dir.

Stack Trace
Traceback (most recent call last):
  File "/app/repo/StravaCompetitor/pver_7fab035c-e229-4298-8fd2-f08c7d9d8c26-test.py", line 319, in wrapper
    ret = func(*args, **kwargs)
  File "/app/repo/StravaCompetitor/pver_7fab035c-e229-4298-8fd2-f08c7d9d8c26-test.py", line 489, in test_get_user_activities_sorted_by_timestamp
    os.makedirs(user_dir, exist_ok=True)
  File "/usr/lib/python3.10/os.py", line 225, in makedirs
    mkdir(name, mode)
FileNotFoundError: [Errno 2] No such file or directory: ''
Unit Tests
# Unit Test for "Returns activities sorted by timestamp": The function should return a list of activities sorted by the 'timestamp' key in descending order.
def benchify_test_get_user_activities_sorted_by_timestamp(user_id, limit, activity_type, base_dir):
    user_dir = os.path.join(base_dir, user_id)
    os.makedirs(user_dir, exist_ok=True)
    activities = [
        {'timestamp': '2023-10-01T12:00:00', 'type': 'run'},
        {'timestamp': '2023-10-02T12:00:00', 'type': 'ride'},
        {'timestamp': '2023-10-03T12:00:00', 'type': 'swim'}
    ]
    for i, activity in enumerate(activities):
        with open(os.path.join(user_dir, f'activity_{i}.json'), 'w') as f:
            json.dump(activity, f)
    result = get_user_activities(user_id, limit, activity_type, base_dir)
    assert result == sorted(result, key=lambda x: x['timestamp'], reverse=True)

def benchify_test_get_user_activities_sorted_by_timestamp_exec_test_failing_0():
    user_id=''
    limit=1
    activity_type=''
    base_dir=''
    benchify_test_get_user_activities_sorted_by_timestamp(user_id, limit, activity_type, base_dir)


return activity_id

def get_user_activities(user_id: str, limit: Optional[int] = None,
Copy link

Choose a reason for hiding this comment

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

❌ Respects limit on number of activities returned
The function should return at most 'limit' number of activities if 'limit' is provided and is a positive integer.

Outcome Example Input # Inputs % of Total
user_id=''
limit=1
activity_type=''
base_dir=''
6 3.0%
user_id='l7'
limit=1
activity_type=''
base_dir=''
194 97.0%

view all inputs
The test test_get_user_activities_respects_limit failed due to a FileNotFoundError when attempting to create a directory with an empty path, as indicated by the args user_id='' and base_dir=''. This error occurred because the os.makedirs function was called with an empty string, which is not a valid directory path. To resolve this issue, the function should be modified to handle empty or invalid input values for user_id and base_dir.

Stack Trace
Traceback (most recent call last):
  File "/app/repo/StravaCompetitor/pver_057c4ce3-08e6-44c7-8caa-f0f6ce502678-test.py", line 319, in wrapper
    ret = func(*args, **kwargs)
  File "/app/repo/StravaCompetitor/pver_057c4ce3-08e6-44c7-8caa-f0f6ce502678-test.py", line 487, in test_get_user_activities_respects_limit
    os.makedirs(user_dir, exist_ok=True)
  File "/usr/lib/python3.10/os.py", line 225, in makedirs
    mkdir(name, mode)
FileNotFoundError: [Errno 2] No such file or directory: ''
Unit Tests
# Unit Test for "Respects limit on number of activities returned": The function should return at most 'limit' number of activities if 'limit' is provided and is a positive integer.
def benchify_test_get_user_activities_respects_limit(user_id, limit, activity_type, base_dir):
    user_dir = os.path.join(base_dir, user_id)
    os.makedirs(user_dir, exist_ok=True)
    activities = [
        {'timestamp': '2023-10-01T12:00:00', 'type': 'run'},
        {'timestamp': '2023-10-02T12:00:00', 'type': 'ride'},
        {'timestamp': '2023-10-03T12:00:00', 'type': 'swim'}
    ]
    for i, activity in enumerate(activities):
        with open(os.path.join(user_dir, f'activity_{i}.json'), 'w') as f:
            json.dump(activity, f)
    result = get_user_activities(user_id, limit, activity_type, base_dir)
    assert len(result) <= limit

def benchify_test_get_user_activities_respects_limit_exec_test_failing_0():
    user_id=''
    limit=1
    activity_type=''
    base_dir=''
    benchify_test_get_user_activities_respects_limit(user_id, limit, activity_type, base_dir)


return activity_id

def get_user_activities(user_id: str, limit: Optional[int] = None,
Copy link

Choose a reason for hiding this comment

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

❌ Filters activities by type
The function should only include activities where the 'type' key matches the 'activity_type' if 'activity_type' is provided.

Outcome Example Input # Inputs % of Total
user_id=''
limit=1
activity_type='run'
base_dir=''
22 11.0%
user_id='I0wXJRS2'
limit=1
activity_type='run'
base_dir=''
178 89.0%

view all inputs
The test failed due to a FileNotFoundError when attempting to create a directory with an empty path, as indicated by the args showing base_dir='' and user_id=''. This error occurred because the os.makedirs function was called with an empty string, which is not a valid directory path. The test case was generated with empty strings for user_id and base_dir, which caused the function to fail when trying to create the directory.

Stack Trace
Traceback (most recent call last):
  File "/app/repo/StravaCompetitor/pver_8d5a61d7-845c-4404-be84-c0df0adee08a-test.py", line 319, in wrapper
    ret = func(*args, **kwargs)
  File "/app/repo/StravaCompetitor/pver_8d5a61d7-845c-4404-be84-c0df0adee08a-test.py", line 487, in test_get_user_activities_filters_by_type
    os.makedirs(user_dir, exist_ok=True)
  File "/usr/lib/python3.10/os.py", line 225, in makedirs
    mkdir(name, mode)
FileNotFoundError: [Errno 2] No such file or directory: ''
Unit Tests
# Unit Test for "Filters activities by type": The function should only include activities where the 'type' key matches the 'activity_type' if 'activity_type' is provided.
def benchify_test_get_user_activities_filters_by_type(user_id, limit, activity_type, base_dir):
    user_dir = os.path.join(base_dir, user_id)
    os.makedirs(user_dir, exist_ok=True)
    activities = [
        {'timestamp': '2023-10-01T12:00:00', 'type': 'run'},
        {'timestamp': '2023-10-02T12:00:00', 'type': 'ride'},
        {'timestamp': '2023-10-03T12:00:00', 'type': 'swim'}
    ]
    for i, activity in enumerate(activities):
        with open(os.path.join(user_dir, f'activity_{i}.json'), 'w') as f:
            json.dump(activity, f)
    result = get_user_activities(user_id, limit, activity_type, base_dir)
    assert all(activity['type'] == activity_type for activity in result)

def benchify_test_get_user_activities_filters_by_type_exec_test_failing_0():
    user_id=''
    limit=1
    activity_type='run'
    base_dir=''
    benchify_test_get_user_activities_filters_by_type(user_id, limit, activity_type, base_dir)

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