|
| 1 | +# Copyright 2022 CodeNotary, Inc. All rights reserved. |
| 2 | + |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +# See the License for the specific language governing permissions and |
| 11 | +# limitations under the License. |
| 12 | + |
| 13 | +from tests.immuTestClient import ImmuTestClient |
| 14 | +import sys |
| 15 | + |
| 16 | + |
| 17 | +class TestSQLFloat: |
| 18 | + |
| 19 | + def test_sql_float_query(self, wrappedClient: ImmuTestClient): |
| 20 | + # Testing the FLOAT type inserting and querying |
| 21 | + if (not wrappedClient.serverHigherOrEqualsToVersion("1.5.0")): |
| 22 | + return |
| 23 | + |
| 24 | + value_to_test = 1.1 |
| 25 | + |
| 26 | + tabname = wrappedClient.createTestTable( |
| 27 | + "id INTEGER AUTO_INCREMENT", "tester FLOAT", "PRIMARY KEY id" |
| 28 | + ) |
| 29 | + wrappedClient.insertToTable( |
| 30 | + tabname, ["tester"], ["@test"], {"test": value_to_test} |
| 31 | + ) |
| 32 | + result = wrappedClient.simpleSelect( |
| 33 | + tabname, ["tester"], {"testvalue": value_to_test}, |
| 34 | + "tester=@testvalue" |
| 35 | + ) |
| 36 | + |
| 37 | + assert (len(result) > 0) |
| 38 | + assert (result[0][0] == value_to_test) |
| 39 | + |
| 40 | + def test_sql_float_aggreg_and_filter(self, wrappedClient: ImmuTestClient): |
| 41 | + # Testing the FLOAT type with aggregation and filtering |
| 42 | + if (not wrappedClient.serverHigherOrEqualsToVersion("1.5.0")): |
| 43 | + return |
| 44 | + |
| 45 | + values_to_test = [1.1, 2.2, 3.3, 4.4] |
| 46 | + |
| 47 | + tabname = wrappedClient.createTestTable( |
| 48 | + "id INTEGER AUTO_INCREMENT", "tester FLOAT", "PRIMARY KEY id" |
| 49 | + ) |
| 50 | + |
| 51 | + for val in values_to_test: |
| 52 | + wrappedClient.insertToTable( |
| 53 | + tabname, ["tester"], ["@test"], {"test": val} |
| 54 | + ) |
| 55 | + |
| 56 | + result = wrappedClient.simpleSelect( |
| 57 | + tabname, |
| 58 | + ["AVG(tester)"], |
| 59 | + {"min_val": values_to_test[1] + 0.1}, |
| 60 | + "tester > @min_val" |
| 61 | + ) |
| 62 | + |
| 63 | + assert (len(result) == 1) |
| 64 | + avg_val = result[0][0] |
| 65 | + expected_avg = sum(values_to_test[2:]) / len(values_to_test[2:]) |
| 66 | + assert (abs(avg_val - expected_avg) < sys.float_info.epsilon) |
0 commit comments