def test_decimal(): assert -D('1') == D('-1') assert +D('1') == D('1') assert abs(D('-1')) == D('1') assert D('1') + 1 == D('2') assert 1 + D('1') == D('2') assert D('1') - 1 == D('0') assert 1 - D('1') == D('0') assert D('2') * 3 == D('6') assert 2 * D('3') == D('6') assert D('10') // 2 == D('5') assert 10 // D('2') == D('5') assert D('10') / 2.5 == D('4') assert 10 / D('2.5') == D('4') assert D('5') % 2 == D('1') assert 5 % D('2') == D('1') assert divmod(D('5'), 2) == (D('2'), D('1')) assert divmod(5, D('2')) == (D('2'), D('1')) assert D('3')**2 == D('9') assert 3**D('2') == D('9')
@pytest.fixture(scope='module') async def bot(event_loop): return FakeBot( loop=event_loop, process_pool_executor=ProcessPoolExecutor(), ) @pytest.mark.asyncio @pytest.mark.parametrize( ('expr, expected_decimal_result, expected_num_result,' 'expected_decimal_local, expected_num_local'), [ ('1', D('1'), 1, {}, {}), ('1+2', D('3'), 3, {}, {}), ( '0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1', D('1'), 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1, {}, {}, ), ('1-2', D('-1'), -1, {}, {}), ('4*5', D('20'), 20, {}, {}), ('1/2', D('0.5'), 0.5, {}, {}), ('10%3', D('1'), 1, {}, {}), ('2**3', D('8'), 8, {}, {}), ('(1+2)**3', D('27'), 27, {}, {}), ('max(1,2,3,4,5)', D('5'), 5, {}, {}),
def test_decimal(): assert -D("1") == D("-1") assert +D("1") == D("1") assert abs(D("-1")) == D("1") assert D("1") + 1 == D("2") assert 1 + D("1") == D("2") assert D("1") - 1 == D("0") assert 1 - D("1") == D("0") assert D("2") * 3 == D("6") assert 2 * D("3") == D("6") assert D("10") // 2 == D("5") assert 10 // D("2") == D("5") assert D("10") / 2.5 == D("4") assert 10 / D("2.5") == D("4") assert D("5") % 2 == D("1") assert 5 % D("2") == D("1") assert divmod(D("5"), 2) == (D("2"), D("1")) assert divmod(5, D("2")) == (D("2"), D("1")) assert D("3") ** 2 == D("9") assert 3 ** D("2") == D("9")
import math import pytest from yui.apps.compute.calc import Decimal as D, calculate @pytest.mark.parametrize( ('expr, expected_decimal_result, expected_num_result,' 'expected_decimal_local, expected_num_local'), [ ('1', D('1'), 1, {}, {}), ('1+2', D('3'), 3, {}, {}), ('0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1', D('1'), 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1, {}, {}), ('1-2', D('-1'), -1, {}, {}), ('4*5', D('20'), 20, {}, {}), ('1/2', D('0.5'), 0.5, {}, {}), ('10%3', D('1'), 1, {}, {}), ('2**3', D('8'), 8, {}, {}), ('(1+2)**3', D('27'), 27, {}, {}), ('max(1,2,3,4,5)', D('5'), 5, {}, {}), ('floor(3.2)', D('3'), 3, {}, {}), ('round', round, round, {}, {}), ('math', math, math, {}, {}), ('1+e', D(math.e) + D('1'), math.e + 1, {}, {}), ('[1,2,3]', [D('1'), D('2'), D('3')], [1, 2, 3], {}, {}), ('[x*10 for x in [0,1,2]]', [D('0'), D('10'), D('20')], [0, 10, 20], {}, {}), ('(1,2,3)', (D('1'), D('2'), D('3')), (1, 2, 3), {}, {}), ('{3,2,10}', {D('2'), D('3'), D('10')}, {2, 3, 10}, {}, {}), ('{x%2 for x in [1,2,3,4]}', {D('0'), D('1')}, {0, 1}, {}, {}),
@pytest.fixture(scope="module") async def bot(event_loop): return FakeBot( loop=event_loop, process_pool_executor=ProcessPoolExecutor(), ) @pytest.mark.asyncio @pytest.mark.parametrize( ( "expr, expected_decimal_result, expected_num_result," "expected_decimal_local, expected_num_local" ), [ ("1", D("1"), 1, {}, {}), ("1+2", D("3"), 3, {}, {}), ( "0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1", D("1"), 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1, {}, {}, ), ("1-2", D("-1"), -1, {}, {}), ("4*5", D("20"), 20, {}, {}), ("1/2", D("0.5"), 0.5, {}, {}), ("10%3", D("1"), 1, {}, {}), ("2**3", D("8"), 8, {}, {}), ("(1+2)**3", D("27"), 27, {}, {}), ("max(1,2,3,4,5)", D("5"), 5, {}, {}),