Skip to content

Commit

Permalink
More tests for decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
igorcoding committed Aug 13, 2023
1 parent c1ce9bc commit 4cdb56d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 49 deletions.
4 changes: 2 additions & 2 deletions bench/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def main():
parser.add_argument(
"-n", type=int, default=200000, help="number of executed requests"
)
parser.add_argument("-b", type=int, default=200, help="number of bulks")
parser.add_argument("-b", type=int, default=300, help="number of bulks")
args = parser.parse_args()

print("Running {} requests in {} batches. ".format(args.n, args.b))
Expand All @@ -33,7 +33,7 @@ def main():
["execute", ["select 1 as a, 2 as b"], {"parse_metadata": False}],
]

for use_uvloop in [False, True]:
for use_uvloop in [True]:
if use_uvloop:
try:
import uvloop
Expand Down
111 changes: 64 additions & 47 deletions tests/test_mp_ext.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import datetime
import sys
import unittest
import uuid
from dataclasses import dataclass
from decimal import Decimal

import dateutil.parser
Expand All @@ -12,58 +14,73 @@
from tests._testbase import ensure_version


@dataclass
class DecimalTestCase:
python: Decimal
tarantool: str


class MpExtTestCase(BaseTarantoolTestCase):
@ensure_version(min=(2, 2))
async def test__decimal(self):
space = "tester_ext_dec"

dec = Decimal("-12.34")
res = await self.conn.replace(space, [1, dec])
self.assertEqual(res[0][1], dec)

dec = Decimal("-12.345")
res = await self.conn.replace(space, [1, dec])
self.assertEqual(res[0][1], dec)

dec = Decimal("-12.4")
res = await self.conn.replace(space, [1, dec])
self.assertEqual(res[0][1], dec)

dec = Decimal("0")
res = await self.conn.replace(space, [1, dec])
self.assertEqual(res[0][1], dec)

dec = Decimal("0.000")
res = await self.conn.replace(space, [1, dec])
self.assertEqual(res[0][1], dec)

dec = Decimal(42)
res = await self.conn.replace(space, [1, dec])
self.assertEqual(res[0][1], dec)

dec = Decimal("0.33")
res = await self.conn.replace(space, [1, dec])
self.assertEqual(res[0][1], dec)

dec = Decimal("0.000000000000000000000000000000000010")
res = await self.conn.replace(space, [1, dec])
self.assertEqual(res[0][1], dec)

dec = Decimal("-0.000000000000000000000000000000000010")
res = await self.conn.replace(space, [1, dec])
self.assertEqual(res[0][1], dec)

dec = Decimal("0.1111111111111111")
res = await self.conn.replace(space, [1, dec])
self.assertEqual(res[0][1], dec)

dec = Decimal("-0.1111111111111111")
res = await self.conn.replace(space, [1, dec])
self.assertEqual(res[0][1], dec)

dec = Decimal("-0.111111")
res = await self.conn.replace(space, [1, dec])
self.assertEqual(res[0][1], dec)
cases = [
"-12.34",
"-12.345",
"-12.4",
"0.000",
"42",
"0.33",
"0.000000000000000000000000000000000010",
"-0.000000000000000000000000000000000010",
"0.1111111111111111",
"-0.1111111111111111",
"-0.111111",
"-18.34",
"-108.123456789",
"100",
"0.1",
"-0.1",
"2.718281828459045",
"-2.718281828459045",
"3.141592653589793",
"-3.141592653589793",
"1",
"-1",
"0",
"-0",
"0.01",
"-0.01",
"0.001",
"11111111111111111111111111111111111111",
"-11111111111111111111111111111111111111",
"0.0000000000000000000000000000000000001",
"-0.0000000000000000000000000000000000001",
"0.00000000000000000000000000000000000009",
"-0.00000000000000000000000000000000000009",
"99999999999999999999999999999999999999",
"-99999999999999999999999999999999999999",
"1234567891234567890.0987654321987654321",
"-1234567891234567890.0987654321987654321",
"1e33",
"1.2345e33",
"1.2345e2",
"1.2345e4",
"-1e33",
"1e-33",
]

for case in cases:
with self.subTest(case):
dec = Decimal(case)
res = await self.conn.replace(space, [1, dec])
self.assertEqual(res[0][1], dec, "self-return works")

res = await self.conn.eval(
f"local decimal = require('decimal'); return decimal.new('{case}')"
)
self.assertEqual(res[0], dec, "matches tarantool decimal")

@ensure_version(min=(2, 4, 1))
async def test__uuid(self):
Expand Down

0 comments on commit 4cdb56d

Please sign in to comment.