-
Notifications
You must be signed in to change notification settings - Fork 1
made an instagram competitor - utils #316
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
Conversation
There was a problem hiding this 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 316
All tests have passed, indicating that the functions are_following_each_other, rank_users_by_followers, get_mutual_followers, get_non_follow_backs, and get_users_not_following_back behave as expected. The tests cover various scenarios, including checking if two users follow each other, ranking users by follower count, finding mutual followers, and identifying users who do not follow back. The passing tests suggest that the code handles empty lists, symmetric input, and idempotent operations correctly, and that the output lists do not contain duplicates and are subsets of the input lists. Overall, the code appears to be robust and functions as intended, handling different edge cases and input scenarios for the user1_following, user2_following, user1, user2, followers, user_following, and user_followers variables.
| from typing import List, Dict | ||
|
|
||
| # Check if two users are following each other | ||
| def are_following_each_other(user1_following: List[str], user2_following: List[str], user1: str, user2: str) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Users follow each other
The function should return True if user1 is in user2_following and user2 is in user1_following.
| Outcome | Example Input | # Inputs | % of Total |
|---|---|---|---|
| ✅ | user1_following=['']user2_following=['']user1=''user2='' |
200 | 100.0% |
view all inputs
The property-based test has passed, indicating that the are_following_each_other function behaves as expected when checking if two users are following each other. With input arguments such as user1_following=[''], user2_following=[''], user1='', and user2='', the function correctly returns True when both users are in each other's following list. This suggests that the function is working correctly for the given test case.
Unit Tests
# Unit Test for "Users follow each other": The function should return True if user1 is in user2_following and user2 is in user1_following.
def benchify_test_users_follow_each_other(user1_following, user2_following, user1, user2):
if user1 in user2_following and user2 in user1_following:
assert are_following_each_other(user1_following, user2_following, user1, user2) == True
def benchify_test_users_follow_each_other_exec_test_passing_0():
user1_following=['']
user2_following=['']
user1=''
user2=''
benchify_test_users_follow_each_other(user1_following, user2_following, user1, user2)| from typing import List, Dict | ||
|
|
||
| # Check if two users are following each other | ||
| def are_following_each_other(user1_following: List[str], user2_following: List[str], user1: str, user2: str) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Users do not follow each other
The function should return False if user1 is not in user2_following or user2 is not in user1_following.
| Outcome | Example Input | # Inputs | % of Total |
|---|---|---|---|
| ✅ | user1_following=['']user2_following=['']user1=''user2='' |
200 | 100.0% |
view all inputs
The property-based test has passed, indicating that the function behaves as expected when checking if two users are following each other. With input arguments such as empty strings for user1_following, user2_following, user1, and user2, the function correctly returns False. This result aligns with the property description, which states that the function should return False if user1 is not in user2_following or user2 is not in user1_following.
Unit Tests
# Unit Test for "Users do not follow each other": The function should return False if user1 is not in user2_following or user2 is not in user1_following.
def benchify_test_users_do_not_follow_each_other(user1_following, user2_following, user1, user2):
if user1 not in user2_following or user2 not in user1_following:
assert are_following_each_other(user1_following, user2_following, user1, user2) == False
def benchify_test_users_do_not_follow_each_other_exec_test_passing_0():
user1_following=['']
user2_following=['']
user1=''
user2=''
benchify_test_users_do_not_follow_each_other(user1_following, user2_following, user1, user2)| return user1 in user2_following and user2 in user1_following | ||
|
|
||
| # Rank users by follower count | ||
| def rank_users_by_followers(followers: Dict[str, List[str]]) -> List[str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Ranked list is sorted by follower count
For any two consecutive usernames in the output list, the number of followers of the first should be greater than or equal to the number of followers of the second.
| Outcome | Example Input | # Inputs | % of Total |
|---|---|---|---|
| ✅ | followers={} |
200 | 100.0% |
view all inputs
The property-based test has passed, indicating that the rank_users_by_followers function correctly ranks users by their follower count in descending order. With an input of an empty followers dictionary, the test confirmed that the function behaves as expected, satisfying the property that for any two consecutive usernames in the output list, the number of followers of the first is greater than or equal to the number of followers of the second. No errors were encountered during the test, suggesting that the function is working correctly for this specific input.
Unit Tests
# Unit Test for "Ranked list is sorted by follower count": For any two consecutive usernames in the output list, the number of followers of the first should be greater than or equal to the number of followers of the second.
def benchify_test_ranked_list_sorted_by_follower_count(followers):
ranked_users = rank_users_by_followers(followers)
for i in range(len(ranked_users) - 1):
assert len(followers[ranked_users[i]]) >= len(followers[ranked_users[i + 1]])
def benchify_test_ranked_list_sorted_by_follower_count_exec_test_passing_0():
followers={}
benchify_test_ranked_list_sorted_by_follower_count(followers)| return user1 in user2_following and user2 in user1_following | ||
|
|
||
| # Rank users by follower count | ||
| def rank_users_by_followers(followers: Dict[str, List[str]]) -> List[str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Function is idempotent
Applying the function to its own output should yield the same result.
| Outcome | Example Input | # Inputs | % of Total |
|---|---|---|---|
| ✅ | followers={} |
200 | 100.0% |
view all inputs
The property-based test has passed, indicating that the function is idempotent and applying it to its own output yields the same result. With an input of an empty followers dictionary, the function successfully demonstrated this property, as shown by the test arguments followers={}. This suggests that the function is working as expected and can be relied upon to produce consistent results.
Unit Tests
# Unit Test for "Function is idempotent": Applying the function to its own output should yield the same result.
def benchify_test_function_is_idempotent(followers):
first_ranking = rank_users_by_followers(followers)
second_ranking = rank_users_by_followers({user: followers[user] for user in first_ranking})
assert first_ranking == second_ranking
def benchify_test_function_is_idempotent_exec_test_passing_0():
followers={}
benchify_test_function_is_idempotent(followers)| return sorted(followers.keys(), key=lambda user: len(followers[user]), reverse=True) | ||
|
|
||
| # Get mutual followers between two users | ||
| def get_mutual_followers(user1_followers: List[str], user2_followers: List[str]) -> List[str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Mutual followers are symmetric
The mutual followers between two users should be the same regardless of the order of the input lists.
| Outcome | Example Input | # Inputs | % of Total |
|---|---|---|---|
| ✅ | user1_followers=[]user2_followers=[] |
200 | 100.0% |
view all inputs
The property-based test has passed, confirming that the mutual followers between two users are the same regardless of the order of the input lists, as described in the property. With input lists user1_followers and user2_followers both being empty, the test successfully validated the symmetry of the get_mutual_followers function. This result indicates that the function behaves as expected, returning the same mutual followers when the input lists are reversed.
Unit Tests
# Unit Test for "Mutual followers are symmetric": The mutual followers between two users should be the same regardless of the order of the input lists.
def benchify_test_mutual_followers_symmetric(user1_followers, user2_followers):
assert set(get_mutual_followers(user1_followers, user2_followers)) == set(get_mutual_followers(user2_followers, user1_followers))
def benchify_test_mutual_followers_symmetric_exec_test_passing_0():
user1_followers=[]
user2_followers=[]
benchify_test_mutual_followers_symmetric(user1_followers, user2_followers)| return sorted(followers.keys(), key=lambda user: len(followers[user]), reverse=True) | ||
|
|
||
| # Get mutual followers between two users | ||
| def get_mutual_followers(user1_followers: List[str], user2_followers: List[str]) -> List[str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Mutual followers contain no duplicates
The mutual followers list should not contain any duplicate elements.
| Outcome | Example Input | # Inputs | % of Total |
|---|---|---|---|
| ✅ | user1_followers=[]user2_followers=[] |
200 | 100.0% |
view all inputs
The property-based test has passed, indicating that the mutual followers list does not contain any duplicate elements when the input lists user1_followers and user2_followers are empty. The test case user1_followers=[] and user2_followers=[] was successfully executed, confirming that the get_mutual_followers function returns a list with no duplicates. This suggests that the function is working as expected, and no further action is required.
Unit Tests
# Unit Test for "Mutual followers contain no duplicates": The mutual followers list should not contain any duplicate elements.
def benchify_test_mutual_followers_no_duplicates(user1_followers, user2_followers):
mutual_followers = get_mutual_followers(user1_followers, user2_followers)
assert len(mutual_followers) == len(set(mutual_followers))
def benchify_test_mutual_followers_no_duplicates_exec_test_passing_0():
user1_followers=[]
user2_followers=[]
benchify_test_mutual_followers_no_duplicates(user1_followers, user2_followers)| return list(set(user1_followers) & set(user2_followers)) | ||
|
|
||
| # Get the list of users a user is not following back | ||
| def get_non_follow_backs(user_following: List[str], user_followers: List[str]) -> List[str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Output contains only non-follow-backs
For any username in the output list of get_non_follow_backs, the username should be in user_following and not in user_followers.
| Outcome | Example Input | # Inputs | % of Total |
|---|---|---|---|
| ✅ | user_following=[]user_followers=[] |
200 | 100.0% |
view all inputs
The property-based test has passed, indicating that the get_non_follow_backs function behaves as expected. With input arguments user_following=[] and user_followers=[], the function correctly returns a list of users that are not following back, adhering to the property that any username in the output list should be in user_following and not in user_followers. This suggests that the function is working correctly for empty input lists, and no errors were encountered during the test.
Unit Tests
# Unit Test for "Output contains only non-follow-backs": For any username in the output list of `get_non_follow_backs`, the username should be in `user_following` and not in `user_followers`.
def benchify_test_output_contains_only_non_follow_backs(user_following, user_followers):
result = get_non_follow_backs(user_following, user_followers)
for user in result:
assert user in user_following and user not in user_followers
def benchify_test_output_contains_only_non_follow_backs_exec_test_passing_0():
user_following=[]
user_followers=[]
benchify_test_output_contains_only_non_follow_backs(user_following, user_followers)| return list(set(user1_followers) & set(user2_followers)) | ||
|
|
||
| # Get the list of users a user is not following back | ||
| def get_non_follow_backs(user_following: List[str], user_followers: List[str]) -> List[str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Output is a subset of user_following
The length of the output list from get_non_follow_backs should be less than or equal to the length of user_following.
| Outcome | Example Input | # Inputs | % of Total |
|---|---|---|---|
| ✅ | user_following=[]user_followers=[] |
200 | 100.0% |
view all inputs
The property-based test has passed, indicating that the length of the output list from get_non_follow_backs is indeed less than or equal to the length of user_following, as expected. With input arguments user_following=[] and user_followers=[], the test confirmed that the function behaves correctly for empty lists. This suggests that the get_non_follow_backs function is working as intended, correctly identifying users that are not following back.
Unit Tests
# Unit Test for "Output is a subset of user_following": The length of the output list from `get_non_follow_backs` should be less than or equal to the length of `user_following`.
def benchify_test_output_is_subset_of_user_following(user_following, user_followers):
result = get_non_follow_backs(user_following, user_followers)
assert len(result) <= len(user_following)
def benchify_test_output_is_subset_of_user_following_exec_test_passing_0():
user_following=[]
user_followers=[]
benchify_test_output_is_subset_of_user_following(user_following, user_followers)| return [user for user in user_following if user not in user_followers] | ||
|
|
||
| # Get the list of users who are not following back the given user | ||
| def get_users_not_following_back(user_followers: List[str], user_following: List[str]) -> List[str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Output contains only users not following back
For any username in the output list, it should be present in user_followers and not in user_following.
| Outcome | Example Input | # Inputs | % of Total |
|---|---|---|---|
| ✅ | user_followers=[]user_following=[] |
200 | 100.0% |
view all inputs
The property-based test has passed with empty lists for user followers and user following, indicating that the function get_users_not_following_back behaves correctly when given no input data. The test verified that the function returns an empty list, which aligns with the property that any username in the output list should be present in user_followers and not in user_following. This suggests that the function is working as expected for this specific edge case, with user_followers and user_following being empty lists.
Unit Tests
# Unit Test for "Output contains only users not following back": For any username in the output list, it should be present in `user_followers` and not in `user_following`.
def benchify_test_users_not_following_back(user_followers, user_following):
result = get_users_not_following_back(user_followers, user_following)
for user in result:
assert user in user_followers and user not in user_following
def benchify_test_users_not_following_back_exec_test_passing_0():
user_followers=[]
user_following=[]
benchify_test_users_not_following_back(user_followers, user_following)| return [user for user in user_following if user not in user_followers] | ||
|
|
||
| # Get the list of users who are not following back the given user | ||
| def get_users_not_following_back(user_followers: List[str], user_following: List[str]) -> List[str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Output length is less than or equal to user_followers
The length of the output list should be less than or equal to the length of user_followers.
| Outcome | Example Input | # Inputs | % of Total |
|---|---|---|---|
| ✅ | user_followers=[]user_following=[] |
200 | 100.0% |
view all inputs
The property-based test has passed with the given arguments user_followers=[] and user_following=[], indicating that the function get_users_not_following_back behaves correctly when both input lists are empty. The test verifies that the length of the output list is less than or equal to the length of user_followers, which is a fundamental property of the function's expected behavior. Since the test passed without any errors, no further action is required.
Unit Tests
# Unit Test for "Output length is less than or equal to user_followers": The length of the output list should be less than or equal to the length of `user_followers`.
def benchify_test_output_length(user_followers, user_following):
result = get_users_not_following_back(user_followers, user_following)
assert len(result) <= len(user_followers)
def benchify_test_output_length_exec_test_passing_0():
user_followers=[]
user_following=[]
benchify_test_output_length(user_followers, user_following)
No description provided.