Commit f58994e1 by Owo Sugiana

Penyempurnaan round_up()

1 parent 8110854e
0.2 2022-02-09
----------------
- round_up() disempurnakan yaitu bila pecahan kurang dari 0.1 maka akan
dibulatkan ke bawah. Ini terkait masalah operasi bilangan pecahan yang
disebutkan di
https://stackoverflow.com/questions/588004/is-floating-point-math-broken
- Penggunaan pkgutil agar lebih fleksibel saat pip install -e
0.1.8 2020-10-17
----------------
- Baru, STAN (System Trace Audit Number) generator
......
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
......@@ -6,11 +6,10 @@ from datetime import (
def round_up(n):
i = int(n)
if n == i:
return i
if n > 0:
return i + 1
return i - 1
plus = (int(n*10) - int(n)*10) and 1
if n < 0:
return i - plus
return i + plus
def bulan_tunggakan_berdasarkan_tgl(jatuh_tempo, tgl_hitung):
......
......@@ -3,6 +3,7 @@ from datetime import date
from opensipkd.hitung import (
bulan_tunggakan_berdasarkan_tgl as by_date,
bulan_tunggakan_berdasarkan_bln as by_month,
round_up,
)
......@@ -42,5 +43,28 @@ class Denda(unittest.TestCase):
self.bandingkan(tgl_bayar, 4)
class Round(unittest.TestCase):
def test_round_0(self):
self.assertEqual(round_up(0), 0)
def test_round_5(self):
self.assertEqual(round_up(5), 5)
def test_round_5_1(self):
self.assertEqual(round_up(5.1), 6)
def test_round_5_09(self):
self.assertEqual(round_up(5.09), 5)
def test_round_minus_5(self):
self.assertEqual(round_up(-5), -5)
def test_round_minus_5_1(self):
self.assertEqual(round_up(-5.1), -6)
def test_round_minus_5_09(self):
self.assertEqual(round_up(-5.09), -5)
if __name__ == '__main__':
unittest.main()
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!