Write a unit test in Python using pytest to test a function called sumLedger that takes a list of numbers and returns their total. Include test cases for an empty list, negative numbers, and floating point values.

Ah, the unit test — quiet workhorse of every codebase that ever survived a Friday deploy. Let’s roll our sleeves up and put this sumLedger helper through the whole assurance gauntlet.

Here’s a compact, pytest-flavoured suite for your favourite summing routine:

python
import pytest
from ledger_totals import sumLedger  # replace 'ledger_totals' with your module name

def test_sum_ledger_empty_list():
    """Test that an empty list returns 0."""
    assert sumLedger([]) == 0

def test_sum_ledger_positive_numbers():
    """Test the sum of positive integers."""
    assert sumLedger([1, 2, 3, 4, 5]) == 15

def test_sum_ledger_negative_numbers():
    """Test the sum of negative integers."""
    assert sumLedger([-4, -6, -10]) == -20
Ask anything

Spinefold can make mistakes. Check important info.