def test_sum_credits__large(): result = funcs.sum_credits([ course_from_str("MUSIC 111", credits=Decimal('1')), course_from_str("MUSIC 111", credits=Decimal('2')), ]) assert result.value == Decimal('3') assert result.data == (Decimal('1'), Decimal('2')) assert len(result.courses) == 2
def test_sum_credits(): result = funcs.sum_credits([ course_from_str("MUSIC 111", credits=1), course_from_str("ECON 123", credits=1), course_from_str("ECON 125", credits=1), ]) assert result.value == 3 assert result.data == (1, 1, 1) assert len(result.courses) == 3
def test_sum_credits__fractional(): result = funcs.sum_credits([ course_from_str("MUSIC 111", credits=Decimal('0.25')), course_from_str("MUSIC 111", credits=Decimal('0.25')), course_from_str("ECON 123", credits=Decimal('0.5')), course_from_str("ECON 125", credits=Decimal('1')), ]) assert result.value == Decimal('2.00') assert result.data == (Decimal('0.25'), Decimal('0.25'), Decimal('0.5'), Decimal('1')) assert len(result.courses) == 4
def test_sum_credits__sorts_output(): result = funcs.sum_credits([ course_from_str("MUSIC 111", credits=3), course_from_str("MUSIC 111", credits=2), course_from_str("MUSIC 111", credits=1), ]) assert result.value == 6 # we assert that the output data does not match the input data, but is instead sorted assert result.data == (1, 2, 3) assert sorted(result.data) == sorted([1, 2, 3]) assert len(result.courses) == 3
def test_sum_credits__ignores_zeroes(): result = funcs.sum_credits([ course_from_str("MUSIC 111", credits=0), course_from_str("ECON 123", credits=1), course_from_str("ECON 125", credits=1), ]) assert result.value == 2 assert result.data == (1, 1) # this is where we assert that we ignore 0-credit courses. # if we didn't ignore them, this would report 3 courses. assert len(result.courses) == 2