Skip to content

Commit

Permalink
ترتيب وتنسيق البرمجة المصدرية
Browse files Browse the repository at this point in the history
  • Loading branch information
vzool committed Jun 30, 2024
1 parent 83a9cc7 commit b1adb98
Showing 1 changed file with 31 additions and 32 deletions.
63 changes: 31 additions & 32 deletions zakat/zakat_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,7 @@ def _test_core(self, restore=False, debug=False):
assert count == 0
self.reset()

def test(self, debug: bool = False):
def test(self, debug: bool = False) -> bool:

try:

Expand All @@ -1640,8 +1640,7 @@ def test(self, debug: bool = False):

# Always preserve box age during transfer

created = ZakatTracker.time()
series = [
series: list[tuple] = [
(30, 4),
(60, 3),
(90, 2),
Expand Down Expand Up @@ -1757,10 +1756,10 @@ def test(self, debug: bool = False):
assert self.balance(x, False) == z[4]
assert xx == z[4]

l = self._vault['account'][x]['log']
s = 0
for i in l:
s += l[i]['value']
log = self._vault['account'][x]['log']
for i in log:
s += log[i]['value']
if debug:
print('s', s, 'z[5]', z[5])
assert s == z[5]
Expand All @@ -1774,10 +1773,10 @@ def test(self, debug: bool = False):
assert self.balance(y, False) == z[9]
assert yy == z[9]

l = self._vault['account'][y]['log']
s = 0
for i in l:
s += l[i]['value']
log = self._vault['account'][y]['log']
for i in log:
s += log[i]['value']
assert s == z[10]

assert self.box_size(y) == z[11]
Expand Down Expand Up @@ -1976,7 +1975,8 @@ def test(self, debug: bool = False):
for i in range(1, 31):
timestamp_ns = ZakatTracker.day_to_time(i)
rate, description = self.exchange("cash", timestamp_ns).values()
print(i, rate, description)
if debug:
print(i, rate, description)
if i < 10:
assert rate == 1
assert description is None
Expand All @@ -1999,7 +1999,8 @@ def test(self, debug: bool = False):
assert rate == 3.75
assert description is not None
rate, description = self.exchange("bank", i).values()
print(i, rate, description)
if debug:
print(i, rate, description)
assert rate == 1
assert description is None

Expand All @@ -2010,7 +2011,6 @@ def test(self, debug: bool = False):

# test transfer between accounts with different exchange rate

debug = True
a_SAR = "Bank (SAR)"
b_USD = "Bank (USD)"
c_SAR = "Safe (SAR)"
Expand Down Expand Up @@ -2079,7 +2079,7 @@ def test(self, debug: bool = False):
i = 0
for x in amounts:
if debug:
print(f'{i} - transfer-with-exchnage({x})')
print(f'{i} - transfer-with-exchange({x})')
self.transfer(x, b_USD, a_SAR, f"{x} USD -> SAR", debug=debug)

b_USD_balance -= x
Expand Down Expand Up @@ -2109,7 +2109,7 @@ def test(self, debug: bool = False):
i = 0
for x in amounts:
if debug:
print(f'{i} - transfer-with-exchnage({x})')
print(f'{i} - transfer-with-exchange({x})')
self.transfer(x, c_SAR, a_SAR, f"{x} SAR -> a_SAR", debug=debug)

c_SAR_balance -= x
Expand Down Expand Up @@ -2167,12 +2167,12 @@ def test(self, debug: bool = False):
if debug:
print(f"############# check(rate: {rate}) #############")
self.reset()
self.exchange(case[1], created=case[2], rate=rate)
self.track(case[0], desc='test-check', account=case[1], logging=True, created=case[2])
self.exchange(account=case[1], created=case[2], rate=rate)
self.track(value=case[0], desc='test-check', account=case[1], logging=True, created=case[2])

# assert self.nolock()
history_size = len(self._vault['history'])
print('history_size', history_size)
# history_size = len(self._vault['history'])
# print('history_size', history_size)
# assert history_size == 2
assert self.lock()
assert not self.nolock()
Expand Down Expand Up @@ -2213,27 +2213,26 @@ def test(self, debug: bool = False):
assert self.recall(False, debug) is False
self.free(self.lock())
assert self.nolock()
print('history_size', self._vault['history'])
assert len(self._vault['history']) == 3
assert self.recall(False, debug) is True
print('history_size', self._vault['history'])
assert len(self._vault['history']) == 2
assert self.recall(False, debug) is True
print('history_size', self._vault['history'])
assert len(self._vault['history']) == 1
assert self.recall(False, debug) is True
print('history_size', self._vault['history'])
for i in range(3, 0, -1):
history_size = len(self._vault['history'])
if debug:
print('history_size', history_size)
assert history_size == i
assert self.recall(False, debug) is True

# assert self.nolock()
# assert len(self._vault['history']) == 1
assert self.nolock()

assert self.recall(False, debug) is False
assert len(self._vault['history']) == 0
history_size = len(self._vault['history'])
if debug:
print('history_size', history_size)
assert history_size == 0

assert len(self._vault['account']) == 0
assert len(self._vault['history']) == 0
assert len(self._vault['report']) == 0
assert self.nolock()
return True
except:
# pp().pprint(self._vault)
assert self.export_json("test-snapshot.json")
Expand All @@ -2244,7 +2243,7 @@ def test(self, debug: bool = False):
def main():
ledger = ZakatTracker()
start = ZakatTracker.time()
ledger.test(True)
assert ledger.test(True)
print("#########################")
print("######## TEST DONE ########")
print("#########################")
Expand Down

0 comments on commit b1adb98

Please sign in to comment.