advancedxy commented on code in PR #426: URL: https://github.com/apache/datafusion-comet/pull/426#discussion_r1600826060
########## spark/src/test/scala/org/apache/comet/DataGenerator.scala: ########## @@ -0,0 +1,98 @@ +/* + * 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.comet + +import scala.util.Random + +object DataGenerator { + // note that we use `def` rather than `val` intentionally here so that + // each test suite starts with a fresh data generator to help ensure + // that tests are deterministic + def DEFAULT = new DataGenerator(new Random(42)) +} + +class DataGenerator(r: Random) { + + /** Generate a random string using the specified characters */ + def generateString(chars: String, maxLen: Int): String = { + val len = r.nextInt(maxLen) + Range(0, len).map(_ => chars.charAt(r.nextInt(chars.length))).mkString + } + + /** Generate random strings */ + def generateStrings(n: Int, maxLen: Int): Seq[String] = { + Range(0, n).map(_ => r.nextString(maxLen)) + } + + /** Generate random strings using the specified characters */ + def generateStrings(n: Int, chars: String, maxLen: Int): Seq[String] = { + Range(0, n).map(_ => generateString(chars, maxLen)) + } + + def generateFloats(n: Int): Seq[Float] = { + Seq( + Float.MaxValue, + Float.MinPositiveValue, + Float.MinValue, + Float.NaN, + Float.PositiveInfinity, + Float.NegativeInfinity, + 1.0f, + -1.0f, + Short.MinValue.toFloat, + Short.MaxValue.toFloat, + 0.0f) ++ + Range(0, n).map(_ => r.nextFloat()) + } + + def generateDoubles(n: Int): Seq[Double] = { + Seq( + Double.MaxValue, + Double.MinPositiveValue, + Double.MinValue, + Double.NaN, + Double.PositiveInfinity, + Double.NegativeInfinity, + 0.0d) ++ Review Comment: +1. But I think it could be addressed in a follow-up pr. -- 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]
