-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
233 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
# Generated by CodiumAI | ||
from collections import Counter | ||
|
||
import pytest | ||
from mappingtools import CategoryCounter | ||
|
||
|
||
# Initialize CategoryCounter and update with a list of items | ||
def test_initialize_and_update_with_list(): | ||
# Arrange | ||
counter = CategoryCounter() | ||
data = ['apple', 'banana', 'apple'] | ||
|
||
# Act | ||
counter.update(data) | ||
|
||
# Assert | ||
assert counter.total == Counter({'apple': 2, 'banana': 1}) | ||
|
||
|
||
# Categorize items using direct category values | ||
def test_categorize_with_direct_category_values(): | ||
# Arrange | ||
counter = CategoryCounter() | ||
fruits = ['apple', 'apricot', 'banana', 'cherry', 'pear', 'pineapple', 'plum', 'banana'] | ||
|
||
# Act | ||
for fruit in fruits: | ||
counter.update({fruit: 1}, char_count=len(fruit), unique_char_count=len(set(fruit))) | ||
|
||
# Assert | ||
assert counter.total == Counter({ | ||
'banana': 2, | ||
'apple': 1, | ||
'apricot': 1, | ||
'cherry': 1, | ||
'pear': 1, | ||
'pineapple': 1, | ||
'plum': 1 | ||
}) | ||
assert counter == { | ||
'char_count': { | ||
4: Counter({'pear': 1, 'plum': 1}), | ||
5: Counter({'apple': 1}), | ||
6: Counter({'banana': 2, 'cherry': 1}), | ||
7: Counter({'apricot': 1}), | ||
9: Counter({'pineapple': 1}) | ||
}, | ||
'unique_char_count': { | ||
3: Counter({'banana': 2}), | ||
4: Counter({'apple': 1, 'pear': 1, 'plum': 1}), | ||
5: Counter({'cherry': 1}), | ||
6: Counter({'pineapple': 1}), | ||
7: Counter({'apricot': 1}) | ||
} | ||
} | ||
|
||
|
||
# Categorize items using functions to determine categories | ||
def test_categorize_with_functions(): | ||
# Arrange | ||
counter = CategoryCounter() | ||
fruits = ['apple', 'apricot', 'banana', 'cherry', 'pear', 'pineapple', 'plum', 'banana'] | ||
|
||
# Act | ||
for fruit in fruits: | ||
counter.update({fruit: 1}, | ||
char_count=lambda s: len(next(iter(s))), | ||
unique_char_count=lambda s: len(set(next(iter(s))))) | ||
|
||
# Assert | ||
assert counter.total == Counter({ | ||
'banana': 2, | ||
'apple': 1, | ||
'apricot': 1, | ||
'cherry': 1, | ||
'pear': 1, | ||
'pineapple': 1, | ||
'plum': 1 | ||
}) | ||
assert counter == { | ||
'char_count': { | ||
4: Counter({'pear': 1, 'plum': 1}), | ||
5: Counter({'apple': 1}), | ||
6: Counter({'banana': 2, 'cherry': 1}), | ||
7: Counter({'apricot': 1}), | ||
9: Counter({'pineapple': 1}) | ||
}, | ||
'unique_char_count': { | ||
3: Counter({'banana': 2}), | ||
4: Counter({'apple': 1, 'pear': 1, 'plum': 1}), | ||
5: Counter({'cherry': 1}), | ||
6: Counter({'pineapple': 1}), | ||
7: Counter({'apricot': 1}) | ||
} | ||
} | ||
|
||
|
||
# Retrieve counts for specific categories | ||
def test_retrieve_counts_for_specific_categories(): | ||
# Arrange | ||
counter = CategoryCounter() | ||
data = ['apple', 'banana', 'apple'] | ||
|
||
# Act | ||
counter.update(data, type='fruit') | ||
|
||
# Assert | ||
assert counter['type']['fruit'] == Counter({'apple': 2, 'banana': 1}) | ||
|
||
|
||
# Update with an empty list | ||
def test_update_with_empty_list(): | ||
# Arrange | ||
counter = CategoryCounter() | ||
|
||
# Act | ||
counter.update([]) | ||
|
||
# Assert | ||
assert counter.total == Counter() | ||
|
||
|
||
# Provide static category | ||
def test_categories_not_matching_any_items(): | ||
# Arrange | ||
counter = CategoryCounter() | ||
data = ['apple', 'banana', 'pear'] | ||
|
||
# Act | ||
counter.update(data, type='fruit') | ||
|
||
# Assert | ||
assert counter['type']['car'] == Counter() | ||
|
||
|
||
# Update with mixed data types | ||
def test_update_with_mixed_data_types(): | ||
# Arrange | ||
counter = CategoryCounter() | ||
data = ['apple', 1, 2.5, 1, 1] | ||
|
||
# Act & Assert | ||
# with pytest.raises(TypeError): | ||
counter.update(data) | ||
|
||
assert counter.total == Counter({'apple': 1, 1: 3, 2.5: 1}) | ||
|
||
|
||
# Verify initialization without any updates | ||
def test_initialization_without_updates(): | ||
# Arrange & Act | ||
counter = CategoryCounter() | ||
|
||
# Assert | ||
assert counter.total == Counter() | ||
|
||
|
||
# Check behavior with nested data structures | ||
def test_nested_data_structures_behavior(): | ||
# Arrange | ||
counter = CategoryCounter() | ||
data = [{'name': 'apple'}, {'name': 'banana'}, {'name': 'apple'}] | ||
|
||
# Act & Assert | ||
with pytest.raises(TypeError): | ||
counter.update(data) | ||
|
||
|
||
# Correctly formats the string representation of CategoryCounter | ||
def test_correct_formatting(): | ||
# Arrange | ||
cc = CategoryCounter() | ||
|
||
# Act | ||
result = repr(cc) | ||
|
||
# Assert | ||
assert result == "CategoryCounter({})" |