Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions codebeaver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from: pytest
# This file was generated automatically by CodeBeaver based on your repository. Learn how to customize it here: https://docs.codebeaver.ai/docs/configuration
23 changes: 23 additions & 0 deletions tests/test_alert_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pytest

from alert_manager import AlertManager

class TestAlertManager:
"""Test suite for the AlertManager class."""

def test_value_equal_threshold_does_not_trigger(self):
"""
Test that an alert with a value equal to the threshold does not trigger an alarm.
This tests the condition where alert["value"] == threshold, ensuring the alert remains false.
"""
threshold = 10
manager = AlertManager(threshold)

# Create an alert with value equal to the threshold; it should not trigger the alarm.
alert = {"date": "2023-10-01", "value": 10, "alert_triggered": False}
manager.add_alert(alert)

# Call to update alarms and check the aggregate result.
assert manager.is_alarm_triggered() is False
# Also verify that the individual alert's triggered status remains False.
assert alert["alert_triggered"] is False
36 changes: 11 additions & 25 deletions tests/test_expense_tracker.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import unittest

from expense_tracker import ExpenseTracker


class TestExpenseTracker(unittest.TestCase):
"""Tests for the ExpenseTracker class."""

def test_expense_tracker_initialization(self):
tracker = ExpenseTracker()
expected_categories = {
Expand All @@ -22,10 +23,12 @@ def test_expenses_initialized_as_empty_list(self):
self.assertEqual(len(tracker.expenses), 0)

def test_categories_is_set_with_default_categories(self):
"""Test that the default categories are set correctly.
Correct expected category from 'foods' to 'food'."""
tracker = ExpenseTracker()
self.assertIsInstance(tracker.categories, set)
expected_categories = {
"foods",
"food",
"transport",
"utilities",
"entertainment",
Expand All @@ -52,40 +55,31 @@ def test_expenses_remain_empty_after_adding_category(self):
self.assertEqual(len(tracker.expenses), 0)

def test_remove_category(self):
"""Test that removing a category decreases the category count by one."""
tracker = ExpenseTracker()
initial_category_count = len(tracker.categories)
category_to_remove = "entertainment"

tracker.categories.remove(category_to_remove)

self.assertEqual(len(tracker.categories), initial_category_count)
self.assertEqual(len(tracker.categories), initial_category_count - 1)
self.assertNotIn(category_to_remove, tracker.categories)
self.assertEqual(len(tracker.expenses), 0) # Ensure expenses are still empty

def test_direct_expense_manipulation(self):
tracker = ExpenseTracker()
initial_expense_count = len(tracker.expenses)
initial_category_count = len(tracker.categories)

# Directly add an expense to the expenses list
new_expense = {"amount": 50, "category": "food", "description": "Groceries"}
tracker.expenses.append(new_expense)

# Check if the expense was added
self.assertEqual(len(tracker.expenses), initial_expense_count + 1)
self.assertIn(new_expense, tracker.expenses)

# Ensure categories weren't affected
self.assertEqual(len(tracker.categories), initial_category_count)
self.assertNotIn("Groceries", tracker.categories)

def test_add_multiple_categories(self):
tracker = ExpenseTracker()
initial_category_count = len(tracker.categories)
new_categories = {"healthcare", "education", "savings"}

tracker.categories.update(new_categories)

self.assertEqual(
len(tracker.categories), initial_category_count + len(new_categories)
)
Expand All @@ -96,30 +90,22 @@ def test_add_multiple_categories(self):
def test_clear_all_categories(self):
tracker = ExpenseTracker()
initial_expense_count = len(tracker.expenses)

# Clear all categories
tracker.categories.clear()

# Check if categories are empty
self.assertEqual(len(tracker.categories), 0)

# Ensure expenses weren't affected
self.assertEqual(len(tracker.expenses), initial_expense_count)

def test_modify_existing_category(self):
tracker = ExpenseTracker()
initial_category_count = len(tracker.categories)
old_category = "entertainment"
new_category = "entertainment_and_leisure"

# Remove the old category and add the new one
tracker.categories.remove(old_category)
tracker.categories.add(new_category)

# Check if the modification was successful
self.assertEqual(len(tracker.categories), initial_category_count)
self.assertNotIn(old_category, tracker.categories)
self.assertIn(new_category, tracker.categories)

# Ensure expenses weren't affected
self.assertEqual(len(tracker.expenses), 0)


if __name__ == '__main__':
unittest.main()
78 changes: 72 additions & 6 deletions tests/test_investment_tracker.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,82 @@
import pytest
import unittest

from investment_tracker import InvestmentTracker


class TestInvestmentTracker(unittest.TestCase):
"""Test class for InvestmentTracker methods."""

def test_record_transaction(self):
raise Exception("Test not implemented")
"""Test recording a valid transaction and raising errors for invalid transactions."""
tracker = InvestmentTracker()

# Test a valid transaction
result = tracker.record_transaction(50.0, "food", "Dinner")
self.assertTrue(result)
self.assertEqual(len(tracker.expenses), 1)

# Test invalid amount: zero
with self.assertRaises(ValueError):
tracker.record_transaction(0, "food", "Zero expense")

# Test invalid amount: negative number
with self.assertRaises(ValueError):
tracker.record_transaction(-10, "food", "Negative expense")

# Test invalid category
with self.assertRaises(ValueError):
tracker.record_transaction(25, "nonexistent", "Invalid category")

def test_register_new_category(self):
investment_tracker = InvestmentTracker()
self.assertEqual(investment_tracker.register_new_category("Food"), True)
"""Test adding a new category successfully."""
tracker = InvestmentTracker()
self.assertEqual(tracker.register_new_category("Food"), True)

def test_register_new_category_empty_string(self):
investment_tracker = InvestmentTracker()
self.assertEqual(investment_tracker.register_new_category(""), False)
"""Test that registering an empty string category raises ValueError."""
tracker = InvestmentTracker()
with self.assertRaises(ValueError):
tracker.register_new_category("")

if __name__ == "__main__":
unittest.main()

def test_calculations_filter_and_category_sum():
"""
Test overall spending calculation, filtering by category, and computing the category sums.

This test verifies that:
- The overall spending is the sum of the individual transaction amounts.
- Filtering by a valid category returns only transactions of that category.
- Compute_category_sum returns the correct sum.
- Filtering or computing the sum for an invalid category raises a ValueError.
"""
tracker = InvestmentTracker()

# Record sample transactions
tracker.record_transaction(20, "food", "Breakfast")
tracker.record_transaction(30, "transport", "Bus fare")
tracker.record_transaction(10, "food", "Snack")

# Verify overall spending calculation:
overall_spending = tracker.calculate_overall_spending()
assert overall_spending == 60 # 20 + 30 + 10

# Verify filtering by category "food":
food_expenses = tracker.filter_by_category("food")
assert len(food_expenses) == 2
assert all(expense["category"] == "food" for expense in food_expenses)

# Verify computing the sum for each category:
food_sum = tracker.compute_category_sum("food")
transport_sum = tracker.compute_category_sum("transport")
assert food_sum == 30 # 20 + 10
assert transport_sum == 30 # only one expense of 30

# Ensure that filtering by an invalid category raises a ValueError.
with pytest.raises(ValueError):
tracker.filter_by_category("nonexistent")

# Ensure that computing sum for an invalid category raises a ValueError.
with pytest.raises(ValueError):
tracker.compute_category_sum("nonexistent")