From 81693995898fd7e61fb9c4858b622821b69a52b8 Mon Sep 17 00:00:00 2001 From: MyroTk Date: Tue, 15 Jun 2021 18:42:05 +0200 Subject: [PATCH] Rounding precision controlled by one variable --- tests/testflows/extended_precision_data_types/common.py | 2 ++ .../extended_precision_data_types/tests/arithmetic.py | 8 ++++---- .../extended_precision_data_types/tests/mathematical.py | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/testflows/extended_precision_data_types/common.py b/tests/testflows/extended_precision_data_types/common.py index 1c852bbf935..ebd0a6cac45 100644 --- a/tests/testflows/extended_precision_data_types/common.py +++ b/tests/testflows/extended_precision_data_types/common.py @@ -8,6 +8,8 @@ from testflows.asserts import values, error, snapshot from helpers.common import * +rounding_precision = 7 + @contextmanager def allow_experimental_bigint(node): """Enable experimental big int setting in Clickhouse. diff --git a/tests/testflows/extended_precision_data_types/tests/arithmetic.py b/tests/testflows/extended_precision_data_types/tests/arithmetic.py index db15e6fcfab..49d7ee1fcb3 100644 --- a/tests/testflows/extended_precision_data_types/tests/arithmetic.py +++ b/tests/testflows/extended_precision_data_types/tests/arithmetic.py @@ -63,7 +63,7 @@ def inline_check(self, arithmetic_func, expected_result, int_type, min, max, nod with When(f"I check {arithmetic_func} with {int_type} max and min value"): execute_query(f""" - SELECT round({arithmetic_func}(to{int_type}(\'{max}\'), to{int_type}(1)), 7), round({arithmetic_func}(to{int_type}(\'{min}\'), to{int_type}(1)), 7) + SELECT round({arithmetic_func}(to{int_type}(\'{max}\'), to{int_type}(1)), {rounding_precision}), round({arithmetic_func}(to{int_type}(\'{min}\'), to{int_type}(1)), {rounding_precision}) """) @TestOutline @@ -95,7 +95,7 @@ def table_check(self, arithmetic_func, expected_result, int_type, min, max, node else: with When(f"I insert {arithmetic_func} with {int_type} into the table"): - node.query(f"INSERT INTO {table_name} SELECT round({arithmetic_func}(to{int_type}(1), to{int_type}(1)), 7)") + node.query(f"INSERT INTO {table_name} SELECT round({arithmetic_func}(to{int_type}(1), to{int_type}(1)), {rounding_precision})") with Then("I check that the output matches the expected value"): output = node.query(f"SELECT * FROM {table_name}").output @@ -125,7 +125,7 @@ def table_check(self, arithmetic_func, expected_result, int_type, min, max, node for value in [min, max]: with When(f"I insert {arithmetic_func} with {int_type} {value} into the table"): - node.query(f"INSERT INTO {table_name} SELECT round({arithmetic_func}(to{int_type}(\'{value}\'), to{int_type}(1)), 7)") + node.query(f"INSERT INTO {table_name} SELECT round({arithmetic_func}(to{int_type}(\'{value}\'), to{int_type}(1)), {rounding_precision})") with Then(f"I check the table output of {arithmetic_func} with {int_type}"): execute_query(f""" @@ -191,7 +191,7 @@ def table_check_dec(self, arithmetic_func, expected_result, node=None): else: with When(f"I insert {arithmetic_func} with toDecimal256 into the table"): - node.query(f"INSERT INTO {table_name} SELECT round({arithmetic_func}(toDecimal256(1,0), toDecimal256(1,0)), 7)") + node.query(f"INSERT INTO {table_name} SELECT round({arithmetic_func}(toDecimal256(1,0), toDecimal256(1,0)), {rounding_precision})") with Then("I check that the output matches the expected value"): output = node.query(f"SELECT * FROM {table_name}").output diff --git a/tests/testflows/extended_precision_data_types/tests/mathematical.py b/tests/testflows/extended_precision_data_types/tests/mathematical.py index b305c61ec06..65872b766dd 100644 --- a/tests/testflows/extended_precision_data_types/tests/mathematical.py +++ b/tests/testflows/extended_precision_data_types/tests/mathematical.py @@ -65,7 +65,7 @@ def math_int_inline(self, func, expected_result, exitcode, int_type, min, max, n with And(f"I check {func} with {int_type} using max and min"): execute_query(f""" - SELECT round({func} to{int_type}(\'{max}\')), 7), round({func} to{int_type}(\'{min}\')), 7) + SELECT round({func} to{int_type}(\'{max}\')), {rounding_precision}), round({func} to{int_type}(\'{min}\')), {rounding_precision}) """) @TestOutline(Scenario) @@ -94,7 +94,7 @@ def math_int_table(self, func, expected_result, exitcode, int_type, min, max, no for value in [1, max, min]: with And(f"I insert the output of {func} with {int_type} using {value} into a table"): - node.query(f"INSERT INTO {table_name} SELECT round(to{int_type}OrZero( toString({func} to{int_type}(\'{value}\')))), 7)") + node.query(f"INSERT INTO {table_name} SELECT round(to{int_type}OrZero( toString({func} to{int_type}(\'{value}\')))), {rounding_precision})") with Then(f"I check the outputs of {func} with {int_type}"): execute_query(f""" @@ -129,7 +129,7 @@ def math_dec_inline(self, func, expected_result, exitcode, node=None): with And(f"I check {func} with Decimal256 using max and min"): execute_query(f""" - SELECT round({func} toDecimal256(\'{max}\',0)),7), round({func} toDecimal256(\'{min}\',0)),7) + SELECT round({func} toDecimal256(\'{max}\',0)),{rounding_precision}), round({func} toDecimal256(\'{min}\',0)),{rounding_precision}) """) @TestOutline(Scenario)