leerho commented on code in PR #411:
URL: https://github.com/apache/datasketches-java/pull/411#discussion_r947092433


##########
src/test/java/org/apache/datasketches/ReflectUtility.java:
##########
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.datasketches;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import static org.apache.datasketches.QuantileSearchCriteria.*;
+import static org.testng.Assert.assertEquals;
+
+import org.apache.datasketches.req.ReqSketchSortedView;
+import org.testng.annotations.Test;
+
+public final class ReflectUtility {
+
+  private ReflectUtility() {}
+
+  static final Class<?> REQ_SV;
+  static final Class<?> KLL_FLOATS_SV;
+  static final Class<?> KLL_DOUBLES_SV;
+
+  static final Constructor<?> REQ_SV_CTOR;
+  static final Constructor<?> KLL_FLOATS_SV_CTOR;
+  static final Constructor<?> KLL_DOUBLES_SV_CTOR;
+
+  static {
+    REQ_SV = getClass("org.apache.datasketches.req.ReqSketchSortedView");
+    KLL_FLOATS_SV = 
getClass("org.apache.datasketches.kll.KllFloatsSketchSortedView");
+    KLL_DOUBLES_SV = 
getClass("org.apache.datasketches.kll.KllDoublesSketchSortedView");
+
+    REQ_SV_CTOR = getConstructor(REQ_SV, float[].class, long[].class, 
long.class);
+    KLL_FLOATS_SV_CTOR = getConstructor(KLL_FLOATS_SV, float[].class, 
long[].class, long.class);
+    KLL_DOUBLES_SV_CTOR = getConstructor(KLL_DOUBLES_SV, double[].class, 
long[].class, long.class);
+  }
+
+  @Test //Example
+  public void checkCtr() throws Exception {
+    float[] farr = { 10, 20, 30 };
+    long[] larr = { 1, 2, 3 };
+    long n = 3;
+    ReqSketchSortedView reqSV =
+        (ReqSketchSortedView) REQ_SV_CTOR.newInstance(farr, larr, n);
+    float q = reqSV.getQuantile(1.0, INCLUSIVE);
+    assertEquals(q, 30f);
+  }

Review Comment:
   This Reflect Utility is used by the CrossCheckQuantilesTest which lives in 
the o.a.datasketches package and runs a common suite of tests against all the 
different quantiles-type sketches, which live in different packages, and some 
of these tests leverage the package-private constructor that is common for all 
of the Sorted View implementations.   Thus, the need for reflection.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to