34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
# This file is part of facho. The COPYRIGHT file at the top level of
|
|
# this repository contains the full copyright notices and license terms.
|
|
|
|
"""Tests for `facho` package."""
|
|
|
|
import pytest
|
|
|
|
import facho.fe.form as form
|
|
|
|
|
|
def test_amount_positive():
|
|
with pytest.raises(ValueError):
|
|
form.Amount(-1.0)
|
|
|
|
def test_amount_equals():
|
|
price1 = form.Amount(110.0)
|
|
price2 = form.Amount(100 + 10.0)
|
|
assert price1 == price2
|
|
assert price1 == form.Amount(100) + form.Amount(10)
|
|
assert price1 == form.Amount(10) * form.Amount(10) + form.Amount(10)
|
|
assert form.Amount(110) == (form.Amount(1.10) * form.Amount(100))
|
|
|
|
def test_round():
|
|
# Entre 0 y 5 Mantener el dígito menos significativo
|
|
assert form.Amount(1.133).round(2) == form.Amount(1.13)
|
|
# Entre 6 y 9 Incrementar el dígito menos significativo
|
|
assert form.Amount(1.166).round(2) == form.Amount(1.17)
|
|
# 5, y el segundo dígito siguiente al dígito menos significativo es cero o par Mantener el dígito menos significativo
|
|
assert str(form.Amount(1.1560).round(2)) == str(form.Amount(1.15))
|
|
# 5, y el segundo dígito siguiente al dígito menos significativo es impar Incrementar el dígito menos significativo
|
|
assert form.Amount(1.1569).round(2) == form.Amount(1.157)
|