Skip to content

Commit

Permalink
Update test_category_counter.py
Browse files Browse the repository at this point in the history
  • Loading branch information
erivlis authored Jul 25, 2024
1 parent 68adf32 commit c92961b
Showing 1 changed file with 32 additions and 52 deletions.
84 changes: 32 additions & 52 deletions tests/test_category_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,9 @@
import pytest
from mappingtools import CategoryCounter

fruits = ['apple', 'apricot', 'banana', 'cherry', 'pear', 'pineapple', 'plum', 'banana']

# 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({
expected_total = Counter({
'banana': 2,
'apple': 1,
'apricot': 1,
Expand All @@ -38,7 +15,8 @@ def test_categorize_with_direct_category_values():
'pineapple': 1,
'plum': 1
})
assert counter == {

expected_counter = {
'char_count': {
4: Counter({'pear': 1, 'plum': 1}),
5: Counter({'apple': 1}),
Expand All @@ -55,12 +33,37 @@ def test_categorize_with_direct_category_values():
}
}

# 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()

# Act
for fruit in fruits:
counter.update({fruit: 1}, char_count=len(fruit), unique_char_count=len(set(fruit)))

# Assert
assert counter.total == expected_total
assert counter == expected_counter


# 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:
Expand All @@ -69,31 +72,8 @@ def test_categorize_with_functions():
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})
}
}
assert counter.total == expected_total
assert counter == expected_counter


# Retrieve counts for specific categories
Expand Down

0 comments on commit c92961b

Please sign in to comment.