<commit_before>export { test_FloatValue_Bounds };

import * as RandTools from "../util/RandTools.js";
import * as FloatValue from "../Unpacker/FloatValue.js";

/**
 * For testing Bounds.
 *
 */
class Case {
  constructor( aLowerUpper, bLowerUpper, N, addedArray, multipledArray, aMultipledNArray ) {
    this.N = N;
    this.addedArray = addedArray;
    this.multipledArray = multipledArray;
    this.aMultipledNArray = aMultipledNArray;

    this.aBounds = new FloatValue.Bounds( aLowerUpper[ 0 ], aLowerUpper[ 1 ] );
    this.bBounds = new FloatValue.Bounds( bLowerUpper[ 0 ], bLowerUpper[ 1 ] );

    this.addedBounds = this.aBounds.clone().add_Bounds( this.bBounds );
    this.multipledBounds = this.aBounds.clone().multiply_Bounds( this.bBounds );
    this.aMultipledNBounds = this.aBounds.clone().multiply_N( N );

    this.assert_Bounds_byArray( "addedBounds", addedArray );
    this.assert_Bounds_byArray( "multipledBounds", multipledArray );
    this.assert_Bounds_byArray( "aMultipledNBounds", aMultipledNArray );
  }

  assert_Bounds_byArray( strBoundsTestName, rhsArray ) {
    this.assert_lower_or_upper( strBoundsTestName, "lower", rhsArray, 0 );
    this.assert_lower_or_upper( strBoundsTestName, "upper", rhsArray, 1 );
  }

  assert_lower_or_upper( strBoundsTestName, lower_or_upper_name, rhsArray, rhsArrayIndex ) {
    let thisValue = this[ strBoundsTestName ][ lower_or_upper_name ];
    let rhsArrayValue = rhsArray[ rhsArrayIndex ];
    tf.util.assert( thisValue == rhsArrayValue,
      `test_FloatValue_Bounds(): Case.${strBoundsTestName}.${lower_or_upper_name} ( ${thisValue} ) should be ( ${rhsArrayValue} ).` );
  }
}

/**
 * For testing BoundsArray.
 *
 */
class Cases {
  /**
   * @param {Case[]} aCaseArray  Multiple Case objects.
   */
  constructor( aCaseArray ) {
    let oneRandIndex = RandTools.getRandomIntInclusive( 0, ( aCaseArray.length - 1 ) ); // Randomly select one.
    let oneRandCase = aCaseArray[ oneRandIndex ];
    let aLower = oneRandCase.aBounds.lower;
    let aUpper = oneRandCase.aBounds.upper;
    let bLower = oneRandCase.bBounds.lower;
    let bUpper = oneRandCase.bBounds.upper;
    let N = oneRandCase.N;

    {
//???
      // BoundsArray all with one same bounds.
      let BoundsArrayLength = aCaseArray.length;
      this.aBoundsArrayOne = new FloatValue.BoundsArray( BoundsArrayLength );
      this.bBoundsArrayOne = new FloatValue.BoundsArray( BoundsArrayLength );

      this.aBoundsArrayOne.set_one_byN( 0, N );
      this.assert_BoundsArray_one_byArray( "aBoundsArrayOne", 0, [ N, N ] );

      this.aBoundsArrayOne.set_one_byLowerUpper( 1, aLower, aUpper );
      this.assert_BoundsArray_one_byArray( "aBoundsArrayOne", 1, [ aLower, aUpper ] );
      
      this.aBoundsArrayOne.set_one_byBounds( 2, oneRandCase.bBounds );
      this.assert_BoundsArray_one_byArray( "aBoundsArrayOne", 2, [ bLower, bUpper ] );

      this.aBoundsArrayOne.set_one_byNs( 3, [ N - 1 , N, N + 1 ], 1 );
      this.assert_BoundsArray_one_byArray( "aBoundsArrayOne", 3, [ N, N ] );


      this.bBoundsArrayOne.set_one_byLowersUppers( 0, [ aLower, bLower ], [ aUpper, bUpper ], 1 );
      this.assert_BoundsArray_one_byArray( "bBoundsArrayOne", 0, [ bLower, bUpper ] );

      this.bBoundsArrayOne.set_one_byBoundsArray( 1, this.aBoundsArrayOne, 1 );
      this.assert_BoundsArray_one_byArray( "bBoundsArrayOne", 1, [ aLower, aUpper ] );

      this.bBoundsArrayOne. set_all_byN( N );
      
//!!!
    this.addedBounds = this.aBounds.clone().add_Bounds( this.bBounds );
    this.multipledBounds = this.aBounds.clone().multiply_Bounds( this.bBounds );
    this.aMultipledNBounds = this.aBounds.clone().multiply_N( N );

    this.assert_Bounds_byArray( "addedBounds", addedArray );
    this.assert_Bounds_byArray( "multipledBounds", multipledArray );
    this.assert_Bounds_byArray( "aMultipledNBounds", aMultipledNArray );

    }

    // Convert multiple Bounds into one BoundsArray.
    {
      this.aLowers = new Array( aCaseArray.length ); this.aUppers = new Array( aCaseArray.length );
      this.bLowers = new Array( aCaseArray.length ); this.bUppers = new Array( aCaseArray.length );
      this.Ns = new Array( aCaseArray.length );
      this.addedArrayArray = [ new Array( aCaseArray.length ), new Array( aCaseArray.length ) ];
      this.multipledArrayArray = [ new Array( aCaseArray.length ), new Array( aCaseArray.length ) ];
      this.aMultipledNArrayArray = [ new Array( aCaseArray.length ), new Array( aCaseArray.length ) ];

      for ( let i = 0; i < aCaseArray.length; ++i ) {
        let oneCase = aCaseArray[ i ];
        this.aLowers[ i ] = oneCase.aBounds.lower;
        this.aUppers[ i ] = oneCase.aBounds.upper;
        this.bLowers[ i ] = oneCase.bBounds.lower;
        this.bUppers[ i ] = oneCase.bBounds.upper;
        this.Ns[ i ] = oneCase.N;
        this.addedArrayArray[ 0 ][ i ] = oneCase.addedArray[ 0 ]; // lowers
        this.addedArrayArray[ 1 ][ i ] = oneCase.addedArray[ 1 ]; // uppers
        this.multipledArrayArray[ 0 ][ i ] = oneCase.multipledArray[ 0 ]; // lowers
        this.multipledArrayArray[ 1 ][ i ] = oneCase.multipledArray[ 1 ]; // uppers
        this.aMultipledNArrayArray[ 0 ][ i ] = oneCase.aMultipledNArray[ 0 ]; // lowers
        this.aMultipledNArrayArray[ 1 ][ i ] = oneCase.aMultipledNArray[ 1 ]; // uppers
      }

      this.aBoundsArray = new FloatValue.BoundsArray( aCaseArray.length );
      this.bBoundsArray = new FloatValue.BoundsArray( aCaseArray.length );

      {
        let Ns = ( new Array( aCaseArray.length ) ).fill( N );
        this.aBoundsArray.set_all_byN( oneRandCase.N );
        this.assert_BoundsArray_all_byArray( "aBoundsArray", [ Ns, Ns ] );
      }

      {
        let aLowers = ( new Array( aCaseArray.length ) ).fill( aLower );
        let aUppers = ( new Array( aCaseArray.length ) ).fill( aUpper );
        this.aBoundsArray.set_all_byLowerUpper( aLower, aUpper );
        this.assert_BoundsArray_all_byArray( "aBoundsArray", [ aLowers, aUppers ] );

        this.aBoundsArray.set_all_byBounds( oneRandCase.aBounds );
        this.assert_BoundsArray_all_byArray( "aBoundsArray", [ aLowers, aUppers ] );
      }

      this.aBoundsArray.set_all_byNs( this.Ns );
      this.assert_BoundsArray_all_byArray( "aBoundsArray", [ this.Ns, this.Ns ] );

      this.aBoundsArray.set_all_byLowersUppers( this.aLowers, this.aUppers );
      this.assert_BoundsArray_all_byArray( "aBoundsArray", [ this.aLowers, this.aUppers ] );
      
      this.bBoundsArray.set_all_byBoundsArray( this.aBoundsArray );
      this.assert_BoundsArray_all_byArray( "bBoundsArray", [ this.aLowers, this.aUppers ] );

<commit_msg>Update jsPerf_BoundsArray.js<commit_after>export { test_FloatValue_Bounds };

import * as RandTools from "../util/RandTools.js";
import * as FloatValue from "../Unpacker/FloatValue.js";

/**
 * For testing Bounds.
 *
 */
class Case {
  constructor( aLowerUpper, bLowerUpper, N, addedArray, multipledArray, aMultipledNArray ) {
    this.N = N;
    this.addedArray = addedArray;
    this.multipledArray = multipledArray;
    this.aMultipledNArray = aMultipledNArray;

    this.aBounds = new FloatValue.Bounds( aLowerUpper[ 0 ], aLowerUpper[ 1 ] );
    this.bBounds = new FloatValue.Bounds( bLowerUpper[ 0 ], bLowerUpper[ 1 ] );

    this.addedBounds = this.aBounds.clone().add_Bounds( this.bBounds );
    this.multipledBounds = this.aBounds.clone().multiply_Bounds( this.bBounds );
    this.aMultipledNBounds = this.aBounds.clone().multiply_N( N );

    this.assert_Bounds_byArray( "addedBounds", addedArray );
    this.assert_Bounds_byArray( "multipledBounds", multipledArray );
    this.assert_Bounds_byArray( "aMultipledNBounds", aMultipledNArray );
  }

  assert_Bounds_byArray( strBoundsTestName, rhsArray ) {
    this.assert_lower_or_upper( strBoundsTestName, "lower", rhsArray, 0 );
    this.assert_lower_or_upper( strBoundsTestName, "upper", rhsArray, 1 );
  }

  assert_lower_or_upper( strBoundsTestName, lower_or_upper_name, rhsArray, rhsArrayIndex ) {
    let thisValue = this[ strBoundsTestName ][ lower_or_upper_name ];
    let rhsArrayValue = rhsArray[ rhsArrayIndex ];
    tf.util.assert( thisValue == rhsArrayValue,
      `test_FloatValue_Bounds(): Case.${strBoundsTestName}.${lower_or_upper_name} ( ${thisValue} ) should be ( ${rhsArrayValue} ).` );
  }
}

/**
 * For testing BoundsArray.
 *
 */
class Cases {
  /**
   * @param {Case[]} aCaseArray  Multiple Case objects.
   */
  constructor( aCaseArray ) {
    {
      let oneRandIndex = RandTools.getRandomIntInclusive( 0, ( aCaseArray.length - 1 ) ); // Randomly select one.
      let oneRandCase = aCaseArray[ oneRandIndex ];
      let aLower = oneRandCase.aBounds.lower;
      let aUpper = oneRandCase.aBounds.upper;
      let bLower = oneRandCase.bBounds.lower;
      let bUpper = oneRandCase.bBounds.upper;
      let N = oneRandCase.N;

//???
      // BoundsArray all with one same bounds.
      let BoundsArrayLength = aCaseArray.length;
      this.aBoundsArrayOne = new FloatValue.BoundsArray( BoundsArrayLength );
      this.bBoundsArrayOne = new FloatValue.BoundsArray( BoundsArrayLength );

      this.aBoundsArrayOne.set_one_byN( 0, N );
      this.assert_BoundsArray_one_byArray( "aBoundsArrayOne", 0, [ N, N ] );

      this.aBoundsArrayOne.set_one_byLowerUpper( 1, aLower, aUpper );
      this.assert_BoundsArray_one_byArray( "aBoundsArrayOne", 1, [ aLower, aUpper ] );
      
      this.aBoundsArrayOne.set_one_byBounds( 2, oneRandCase.bBounds );
      this.assert_BoundsArray_one_byArray( "aBoundsArrayOne", 2, [ bLower, bUpper ] );

      this.aBoundsArrayOne.set_one_byNs( 3, [ N - 1 , N, N + 1 ], 1 );
      this.assert_BoundsArray_one_byArray( "aBoundsArrayOne", 3, [ N, N ] );


      this.bBoundsArrayOne.set_one_byLowersUppers( 0, [ aLower, bLower ], [ aUpper, bUpper ], 1 );
      this.assert_BoundsArray_one_byArray( "bBoundsArrayOne", 0, [ bLower, bUpper ] );

      this.bBoundsArrayOne.set_one_byBoundsArray( 1, this.aBoundsArrayOne, 1 );
      this.assert_BoundsArray_one_byArray( "bBoundsArrayOne", 1, [ aLower, aUpper ] );

      {
        let Ns = ( new Array( aCaseArray.length ) ).fill( N );
        this.aBoundsArrayOne.set_all_byN( N );
        this.assert_BoundsArray_all_byArray( "aBoundsArrayOne", [ Ns, Ns ] );
      }

      {
        let aLowers = ( new Array( aCaseArray.length ) ).fill( aLower );
        let aUppers = ( new Array( aCaseArray.length ) ).fill( aUpper );
        this.aBoundsArrayOne.set_all_byLowerUpper( aLower, aUpper );
        this.assert_BoundsArray_all_byArray( "aBoundsArrayOne", [ aLowers, aUppers ] );

        this.bBoundsArrayOne.set_all_byBounds( oneRandCase.aBounds );
        this.assert_BoundsArray_all_byArray( "bBoundsArrayOne", [ aLowers, aUppers ] );
      }


//!!!
    this.addedBounds = this.aBounds.clone().add_Bounds( this.bBounds );
    this.multipledBounds = this.aBounds.clone().multiply_Bounds( this.bBounds );
    this.aMultipledNBounds = this.aBounds.clone().multiply_N( N );


      this.aBoundsArrayOne.add_one_byN( 0, N );
      this.assert_BoundsArray_one_byArray( "aBoundsArrayOne", 0, rhsArray ) {

      this.bBoundsArrayOne. set_all_byN( N );
      
//!!!
    this.addedBounds = this.aBounds.clone().add_Bounds( this.bBounds );
    this.multipledBounds = this.aBounds.clone().multiply_Bounds( this.bBounds );
    this.aMultipledNBounds = this.aBounds.clone().multiply_N( N );

    this.assert_Bounds_byArray( "addedBounds", addedArray );
    this.assert_Bounds_byArray( "multipledBounds", multipledArray );
    this.assert_Bounds_byArray( "aMultipledNBounds", aMultipledNArray );

    }

    // Convert multiple Bounds into one BoundsArray.
    {
      this.aLowers = new Array( aCaseArray.length ); this.aUppers = new Array( aCaseArray.length );
      this.bLowers = new Array( aCaseArray.length ); this.bUppers = new Array( aCaseArray.length );
      this.Ns = new Array( aCaseArray.length );
      this.addedArrayArray = [ new Array( aCaseArray.length ), new Array( aCaseArray.length ) ];
      this.multipledArrayArray = [ new Array( aCaseArray.length ), new Array( aCaseArray.length ) ];
      this.aMultipledNArrayArray = [ new Array( aCaseArray.length ), new Array( aCaseArray.length ) ];

      for ( let i = 0; i < aCaseArray.length; ++i ) {
        let oneCase = aCaseArray[ i ];
        this.aLowers[ i ] = oneCase.aBounds.lower;
        this.aUppers[ i ] = oneCase.aBounds.upper;
        this.bLowers[ i ] = oneCase.bBounds.lower;
        this.bUppers[ i ] = oneCase.bBounds.upper;
        this.Ns[ i ] = oneCase.N;
        this.addedArrayArray[ 0 ][ i ] = oneCase.addedArray[ 0 ]; // lowers
        this.addedArrayArray[ 1 ][ i ] = oneCase.addedArray[ 1 ]; // uppers
        this.multipledArrayArray[ 0 ][ i ] = oneCase.multipledArray[ 0 ]; // lowers
        this.multipledArrayArray[ 1 ][ i ] = oneCase.multipledArray[ 1 ]; // uppers
        this.aMultipledNArrayArray[ 0 ][ i ] = oneCase.aMultipledNArray[ 0 ]; // lowers
        this.aMultipledNArrayArray[ 1 ][ i ] = oneCase.aMultipledNArray[ 1 ]; // uppers
      }

      this.aBoundsArray = new FloatValue.BoundsArray( aCaseArray.length );
      this.bBoundsArray = new FloatValue.BoundsArray( aCaseArray.length );

      this.aBoundsArray.set_all_byNs( this.Ns );
      this.assert_BoundsArray_all_byArray( "aBoundsArray", [ this.Ns, this.Ns ] );

      this.aBoundsArray.set_all_byLowersUppers( this.aLowers, this.aUppers );
      this.assert_BoundsArray_all_byArray( "aBoundsArray", [ this.aLowers, this.aUppers ] );
      
      this.bBoundsArray.set_all_byBoundsArray( this.aBoundsArray );
      this.assert_BoundsArray_all_byArray( "bBoundsArray", [ this.aLowers, this.aUppers ] );


{'fraction_non_alphanumeric': 0.12297663517175712, 'fraction_numerical': 0.005713030103274006, 'mean_word_length': 3.4432150992515456, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3723037', 'n_tokens_mistral': 4709, 'n_tokens_neox': 4544, 'n_words': 845}