File size: 1,002 Bytes
339ddd8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | """Arithmetic helpers for the sample Python fixture package."""
from __future__ import annotations
class Accumulator:
"""Running sum helper used to verify class and method graph extraction."""
def __init__(self, initial: int = 0) -> None:
self.total = initial
def add(self, value: int) -> int:
self.total += value
return self.total
class BoundedAccumulator(Accumulator):
"""Accumulator bounded by an upper limit."""
def __init__(self, limit: int, initial: int = 0) -> None:
super().__init__(initial=initial)
self.limit = limit
def add(self, value: int) -> int:
next_value = min(self.limit, self.total + value)
self.total = next_value
return self.total
def add_numbers(left: int, right: int) -> int:
"""Return the sum of two integers."""
return left + right
def double_sum(left: int, right: int) -> int:
"""Double the sum returned by add_numbers."""
return add_numbers(left, right) * 2
|