Coverage for src \ syriantaxes \ ss.py: 54%
28 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-12 14:00 +0200
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-12 14:00 +0200
1from decimal import Decimal
3from .cast import cast_to_decimal
4from .types import Number, Rounder
7class SocialSecurity:
8 def __init__(
9 self,
10 min_salary: Number,
11 deduction_rate: Number,
12 rounder: Rounder | None = None,
13 ) -> None:
14 self._min_salary = cast_to_decimal(min_salary, lt=Decimal(0))
15 self._deduction_rate = cast_to_decimal(
16 deduction_rate, lt=Decimal(0), gt=Decimal(1)
17 )
18 self.rounder = rounder
20 @property
21 def min_salary(self) -> Decimal:
22 return self._min_salary
24 @min_salary.setter
25 def min_salary(self, value: Number) -> None:
26 self._min_salary = cast_to_decimal(value, lt=Decimal(0))
28 @property
29 def deduction_rate(self) -> Decimal:
30 return self._deduction_rate
32 @deduction_rate.setter
33 def deduction_rate(self, value: Number) -> None:
34 self._deduction_rate = cast_to_decimal(
35 value, lt=Decimal(0), gt=Decimal(1)
36 )
38 def calculate_deduction(self, salary: Number) -> Decimal:
39 salary = cast_to_decimal(salary, lt=self._min_salary)
40 result = salary * self._deduction_rate
42 if self.rounder is not None:
43 return self.rounder.round(result)
45 return result
47 def __repr__(self) -> str:
48 return f"SocialSecurity(min_salary={self._min_salary}, deduction_rate={self._deduction_rate})" # noqa: E501