Skip to content

Commit

Permalink
تحسين اختبار الأرقام العشرية
Browse files Browse the repository at this point in the history
  • Loading branch information
vzool committed Jul 18, 2024
1 parent ac36bc3 commit fcb9989
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "zakat"
version = "0.2.76"
version = "0.2.77"
authors = [
{ name="Abdelaziz Elrashed Elshaikh Mohamed", email="aeemh.sdn@gmail.com" },
]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name='zakat',
packages=find_packages(include=['zakat']),
version='0.2.76',
version='0.2.77',
description='A Python Library for Islamic Financial Management.',
author='Abdelaziz Elrashed Elshaikh Mohamed',
install_requires=[],
Expand Down
40 changes: 23 additions & 17 deletions zakat/zakat_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def Version():
Returns:
str: The current version of the software.
"""
return '0.2.76'
return '0.2.77'

@staticmethod
def ZakatCut(x: float) -> float:
Expand Down Expand Up @@ -2056,23 +2056,29 @@ def _test_core(self, restore=False, debug=False):
# number scale
error = 0
total = 0
for return_type in (
float,
Decimal,
):
for i in range(101):
for j in range(101):
total += 1
num_str = f'{i}.{j}'
num = return_type(num_str)
scaled = self.scale(num)
unscaled = self.unscale(scaled, return_type=return_type)
if debug:
print(f'return_type: {return_type}, num_str: {num_str} - num: {num} - scaled: {scaled} - unscaled: {unscaled}')
if unscaled != num:
for max_i, max_j, decimal_places in [
(101, 101, 2), # fiat currency minimum unit took 2 decimal places
(1, 1_000, 8), # cryptocurrency like Satoshi in Bitcoin took 8 decimal places
(1, 1_000, 18) # cryptocurrency like Wei in Ethereum took 18 decimal places
]:
for return_type in (
float,
Decimal,
):
for i in range(max_i):
for j in range(max_j):
total += 1
num_str = f'{i}.{j:0{decimal_places}d}'
num = return_type(num_str)
scaled = self.scale(num, decimal_places=decimal_places)
unscaled = self.unscale(scaled, return_type=return_type, decimal_places=decimal_places)
if debug:
print('***** SCALE ERROR *****')
error += 1
print(
f'return_type: {return_type}, num_str: {num_str} - num: {num} - scaled: {scaled} - unscaled: {unscaled}')
if unscaled != num:
if debug:
print('***** SCALE ERROR *****')
error += 1
if debug:
print(f'total: {total}, error({error}): {100 * error / total}%')
assert error == 0
Expand Down

0 comments on commit fcb9989

Please sign in to comment.