1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License;
4
+ * you may not use this file except in compliance with the Elastic License.
5
+ */
6
+ package org .elasticsearch .xpack .sql .expression .function .scalar .math ;
7
+
8
+ import org .elasticsearch .common .io .stream .NamedWriteableRegistry ;
9
+ import org .elasticsearch .common .io .stream .Writeable .Reader ;
10
+ import org .elasticsearch .test .AbstractWireSerializingTestCase ;
11
+ import org .elasticsearch .xpack .sql .expression .Literal ;
12
+ import org .elasticsearch .xpack .sql .expression .function .scalar .Processors ;
13
+ import org .elasticsearch .xpack .sql .expression .function .scalar .processor .runtime .ConstantProcessor ;
14
+ import org .elasticsearch .xpack .sql .expression .function .scalar .processor .runtime .Processor ;
15
+
16
+ import static org .elasticsearch .xpack .sql .tree .Location .EMPTY ;
17
+
18
+ public class BinaryMathProcessorTests extends AbstractWireSerializingTestCase <BinaryMathProcessor > {
19
+ public static BinaryMathProcessor randomProcessor () {
20
+ return new BinaryMathProcessor (
21
+ new ConstantProcessor (randomLong ()),
22
+ new ConstantProcessor (randomLong ()),
23
+ randomFrom (BinaryMathProcessor .BinaryMathOperation .values ()));
24
+ }
25
+
26
+ @ Override
27
+ protected BinaryMathProcessor createTestInstance () {
28
+ return randomProcessor ();
29
+ }
30
+
31
+ @ Override
32
+ protected Reader <BinaryMathProcessor > instanceReader () {
33
+ return BinaryMathProcessor ::new ;
34
+ }
35
+
36
+ @ Override
37
+ protected NamedWriteableRegistry getNamedWriteableRegistry () {
38
+ return new NamedWriteableRegistry (Processors .getNamedWriteables ());
39
+ }
40
+
41
+ public void testAtan2 () {
42
+ Processor ba = new ATan2 (EMPTY , l (1 ), l (1 )).makeProcessorDefinition ().asProcessor ();
43
+ assertEquals (0.7853981633974483d , ba .process (null ));
44
+ }
45
+
46
+ public void testPower () {
47
+ Processor ba = new Power (EMPTY , l (2 ), l (2 )).makeProcessorDefinition ().asProcessor ();
48
+ assertEquals (4d , ba .process (null ));
49
+ }
50
+
51
+ public void testHandleNull () {
52
+ assertNull (new ATan2 (EMPTY , l (null ), l (3 )).makeProcessorDefinition ().asProcessor ().process (null ));
53
+ assertNull (new Power (EMPTY , l (null ), l (null )).makeProcessorDefinition ().asProcessor ().process (null ));
54
+ }
55
+
56
+ private static Literal l (Object value ) {
57
+ return Literal .of (EMPTY , value );
58
+ }
59
+ }
0 commit comments