• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright (C) 2023 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License a
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from python.generators.diff_tests.testing import Path, DataPath, Metric
17from python.generators.diff_tests.testing import Csv, Json, TextProto, BinaryProto
18from python.generators.diff_tests.testing import DiffTestBlueprint
19from python.generators.diff_tests.testing import TestSuite
20from python.generators.diff_tests.testing import PrintProfileProto
21from google.protobuf import text_format
22
23
24class PreludeMathFunctions(TestSuite):
25
26  def test_math_ln_function(self):
27    return DiffTestBlueprint(
28        trace=TextProto(""),
29        query="""
30        SELECT
31          CAST(LN(1) * 1000 AS INTEGER) AS valid,
32          LN("as") AS invalid_str,
33          LN(NULL) AS invalid_null
34        """,
35        out=Csv("""
36        "valid","invalid_str","invalid_null"
37        0,"[NULL]","[NULL]"
38        """))
39
40  def test_math_exp_function(self):
41    return DiffTestBlueprint(
42        trace=TextProto(""),
43        query="""
44        SELECT
45          CAST(EXP(1) * 1000 AS INTEGER) AS valid,
46          EXP("asd") AS invalid_str,
47          EXP(NULL) AS invalid_null
48        """,
49        out=Csv("""
50        "valid","invalid_str","invalid_null"
51        2718,"[NULL]","[NULL]"
52        """))
53
54  def test_math_sqrt_function(self):
55    return DiffTestBlueprint(
56        trace=TextProto(""),
57        query="""
58        SELECT
59          CAST(SQRT(4) AS INTEGER) AS valid,
60          SQRT("asd") AS invalid_str,
61          SQRT(NULL) AS invalid_null
62        """,
63        out=Csv("""
64        "valid","invalid_str","invalid_null"
65        2,"[NULL]","[NULL]"
66        """))
67
68  def test_math_functions(self):
69    return DiffTestBlueprint(
70        trace=TextProto(""),
71        query="""
72        SELECT
73          CAST(SQRT(EXP(LN(1))) AS INTEGER) AS valid,
74          SQRT(EXP(LN("asd"))) AS invalid_str,
75          SQRT(EXP(LN(NULL))) AS invalid_null
76        """,
77        out=Csv("""
78        "valid","invalid_str","invalid_null"
79        1,"[NULL]","[NULL]"
80        """))
81