<commit_before>/*
 * Copyright 2001-2015 Artima, Inc.
 *
 * Licensed 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.scalatest

import org.scalactic.anyvals._
import scala.annotation.tailrec
import scala.reflect.runtime.universe.TypeTag

package object prop {
  def valueOf[A](a: Any, others: Any*)(multiplier: Int)(implicit genOfA: Generator[A]): A = {
    val combinedHashCode: Int =
      others.foldLeft(a.hashCode) { (acc, next) =>
        (37 * (acc + 37)) + next.hashCode
      }
    val seed = combinedHashCode.toLong * multiplier
    val rnd = Randomizer(seed)
    val maxSize = PosZInt(20)
    val (size, nextRnd) = rnd.choosePosZInt(1, maxSize) // size will be positive because between 1 and 20, inclusive
    val (result, _, _) = genOfA.next(SizeParam(PosZInt(0), maxSize, size), Nil, nextRnd)
    result
  }
}<commit_msg>First-draft documentation for the valueOf() function<commit_after>/*
 * Copyright 2001-2015 Artima, Inc.
 *
 * Licensed 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.scalatest

import org.scalactic.anyvals._
import scala.annotation.tailrec
import scala.reflect.runtime.universe.TypeTag

package object prop {
  /**
    * Deterministically generate a value for the given Generator.
    *
    * This function takes a set of anywhere from 1-22 parameters, plus a "multiplier". It combines these to
    * generate a pseudo-random (but deterministic) seed, feeds that into the Generator, and returns the
    * result. Since the results are deterministic, calling this repeatedly with the same parameters will produce
    * the same output.
    *
    * This is mainly helpful when generating random Functions -- since the inputs for a test run are
    * complex, you need more than a simple random seed to reproduce the same results. In order to make
    * this more useful, the `toString` of a instance of a Function [[Generator]] shows how to invoke
    * `valueOf()` to reproduce the same result.
    *
    * @param first The first parameter to use for calculating the seed.
    * @param others Any additional parameters to use for calculating the seed.
    * @param multiplier A number to combine with the other parameters, to calculate the seed.
    * @param genOfA A Generator. (Usually a Function Generator.)
    * @tparam A The type of the Generator.
    * @return An instance of A, computed by feeding the calculated seed into the Generator.
    */
  def valueOf[A](first: Any, others: Any*)(multiplier: Int)(implicit genOfA: Generator[A]): A = {
    val combinedHashCode: Int =
      others.foldLeft(first.hashCode) { (acc, next) =>
        (37 * (acc + 37)) + next.hashCode
      }
    val seed = combinedHashCode.toLong * multiplier
    val rnd = Randomizer(seed)
    val maxSize = PosZInt(20)
    val (size, nextRnd) = rnd.choosePosZInt(1, maxSize) // size will be positive because between 1 and 20, inclusive
    val (result, _, _) = genOfA.next(SizeParam(PosZInt(0), maxSize, size), Nil, nextRnd)
    result
  }
}
{'fraction_non_alphanumeric': 0.08668341708542714, 'fraction_numerical': 0.012311557788944723, 'mean_word_length': 3.549714285714286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6886221', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1099, 'n_words': 475}