<commit_before>require 'minitest/autorun'
require 'test_helper'
require 'mocha/test_unit'

class ExperimentExtenderTest < MiniTest::Test

  def setup
    # it has 1 value of the first param and 50 values of the second param
    @experiment = Experiment.new({experiment_input:
                                      [{"id" => "main_category", "entities" =>
                                          [{"id" => "main_group", "parameters" =>
                                              [{"id" => "parameter1",
                                                "type" => "integer",
                                                "min" => 0,
                                                "max" => 1000,
                                                "with_default_value" => false,
                                                "index" => 1,
                                                "parametrizationType" => "value",
                                                "value" => "0",
                                                "in_doe" => false},
                                               {"id" => "parameter2",
                                                "type" => "integer",
                                                "min" => "1",
                                                "max" => "3",
                                                "step" => "1",
                                                "with_default_value" => false,
                                                "index" => 2,
                                                "parametrizationType" => "range",
                                                "in_doe" => false}]
                                           }]
                                       }
                                      ]
                                 })

    @experiment_with_doe = Experiment.new({experiment_input:
                                               [{"id" => "main_category", "entities" =>
                                                   [{"id" => "main_group", "parameters" =>
                                                       [{"id" => "parameter1",
                                                         "type" => "integer",
                                                         "min" => 0,
                                                         "max" => 1000,
                                                         "with_default_value" => false,
                                                         "index" => 1,
                                                         "parametrizationType" => "value",
                                                         "value" => "0",
                                                         "in_doe" => true},
                                                        {"id" => "parameter2",
                                                         "type" => "integer",
                                                         "min" => "1",
                                                         "max" => "100",
                                                         "step" => "2",
                                                         "with_default_value" => false,
                                                         "index" => 2,
                                                         "parametrizationType" => "range",
                                                         "in_doe" => true}]
                                                    }]
                                                }
                                               ],
                                           doe_info: [
                                               ["2k", ["main_category___main_group___parameter1", "main_category___main_group___parameter2"],
                                                [[0.0, 1.0], [0.0, 100.0], [1000.0, 1.0], [1000.0, 100.0]]]]
                                          })

    # it has 1 value of the first param and 50 values of the second param
    @experiment2 = Experiment.new({experiment_input:
                                      [{"id" => "main_category", "entities" =>
                                          [{"id" => "main_group", "parameters" =>
                                              [{"id" => "parameter1",
                                                "type" => "integer",
                                                "min" => "1",
                                                "max" => "3",
                                                "step" => "1",
                                                "with_default_value" => false,
                                                "index" => 1,
                                                "parametrizationType" => "range",
                                                "in_doe" => false},
                                               {"id" => "parameter2",
                                                "type" => "integer",
                                                "min" => "1",
                                                "max" => "3",
                                                "step" => "1",
                                                "with_default_value" => false,
                                                "index" => 2,
                                                "parametrizationType" => "range",
                                                "in_doe" => false}]
                                           }]
                                       }
                                      ]
                                 })
  end

  def test_extend_with_single_value
    @experiment.stubs(:save)
    Scalarm::Database::MongoActiveRecord.stubs(:where).returns([])

    original_size = @experiment.experiment_size

    @experiment.add_parameter_values("main_category___main_group___parameter2", [100])

    assert_equal original_size + 1, @experiment.experiment_size


    original_size = @experiment.experiment_size

    @experiment.add_parameter_values("main_category___main_group___parameter1", [200])

    assert_equal original_size * 2, @experiment.experiment_size
  end

  def test_extend_with_multiple_values
    @experiment.stubs(:save)
    Scalarm::Database::MongoActiveRecord.stubs(:where).returns([])

    original_size = @experiment.experiment_size

    @experiment.add_parameter_values("main_category___main_group___parameter2", [100, 200, 300])

    assert_equal original_size + 3, @experiment.experiment_size


    original_size = @experiment.experiment_size

    @experiment.add_parameter_values("main_category___main_group___parameter1", [100, 200, 300])

    assert_equal original_size * 4, @experiment.experiment_size
  end

  def test_extend_experiment_with_doe
    @experiment_with_doe.stubs(:save)
    Scalarm::Database::MongoActiveRecord.stubs(:where).returns([])

    original_size = @experiment_with_doe.experiment_size

    @experiment_with_doe.add_parameter_values("main_category___main_group___parameter1", [1])

    assert_equal original_size + 2, @experiment_with_doe.experiment_size
<commit_msg>Test for experiment extender - checking value_list and multiple list besides experiment size.<commit_after>require 'minitest/autorun'
require 'test_helper'
require 'mocha/test_unit'

class ExperimentExtenderTest < MiniTest::Test

  def setup
    # it has 1 value of the first param and 50 values of the second param
    @experiment = Experiment.new({experiment_input:
                                      [{"id" => "main_category", "entities" =>
                                          [{"id" => "main_group", "parameters" =>
                                              [{"id" => "parameter1", "type" => "integer", "index" => 1,
                                                "min" => 0, "max" => 1000, "with_default_value" => false, "value" => "0",
                                                "parametrizationType" => "value",
                                                "in_doe" => false},
                                               {"id" => "parameter2", "type" => "integer", "index" => 2,
                                                "min" => "1", "max" => "3", "step" => "1",
                                                "with_default_value" => false,
                                                "parametrizationType" => "range",
                                                "in_doe" => false}]
                                           }]
                                       }]
                                 })

    @experiment_with_doe = Experiment.new({experiment_input:
                                               [{"id" => "main_category", "entities" =>
                                                   [{"id" => "main_group", "parameters" =>
                                                       [{"id" => "parameter1",
                                                         "type" => "integer",
                                                         "min" => 0,
                                                         "max" => 1000,
                                                         "with_default_value" => false,
                                                         "index" => 1,
                                                         "parametrizationType" => "value",
                                                         "value" => "0",
                                                         "in_doe" => true},
                                                        {"id" => "parameter2",
                                                         "type" => "integer",
                                                         "min" => "1",
                                                         "max" => "100",
                                                         "step" => "2",
                                                         "with_default_value" => false,
                                                         "index" => 2,
                                                         "parametrizationType" => "range",
                                                         "in_doe" => true}]
                                                    }]
                                                }
                                               ],
                                           doe_info: [
                                               ["2k", ["main_category___main_group___parameter1", "main_category___main_group___parameter2"],
                                                [[0.0, 1.0], [0.0, 100.0], [1000.0, 1.0], [1000.0, 100.0]]]]
                                          })

    # it has 1 value of the first param and 50 values of the second param
    @experiment2 = Experiment.new({experiment_input:
                                      [{"id" => "main_category", "entities" =>
                                          [{"id" => "main_group", "parameters" =>
                                              [{"id" => "parameter1",
                                                "type" => "integer",
                                                "min" => "1",
                                                "max" => "3",
                                                "step" => "1",
                                                "with_default_value" => false,
                                                "index" => 1,
                                                "parametrizationType" => "range",
                                                "in_doe" => false},
                                               {"id" => "parameter2",
                                                "type" => "integer",
                                                "min" => "1",
                                                "max" => "3",
                                                "step" => "1",
                                                "with_default_value" => false,
                                                "index" => 2,
                                                "parametrizationType" => "range",
                                                "in_doe" => false}]
                                           }]
                                       }
                                      ]
                                 })
  end

  def test_extend_with_single_value
    @experiment.stubs(:save)
    Scalarm::Database::MongoActiveRecord.stubs(:where).returns([])

    original_size = @experiment.experiment_size

    @experiment.add_parameter_values("main_category___main_group___parameter2", [100])

    assert_equal original_size + 1, @experiment.experiment_size
    assert_equal [[0], [1, 2, 3, 100]], @experiment.value_list
    assert_equal [4, 1], @experiment.multiply_list

    original_size = @experiment.experiment_size

    @experiment.add_parameter_values("main_category___main_group___parameter1", [200])

    assert_equal original_size * 2, @experiment.experiment_size
    assert_equal [[0, 200], [1, 2, 3, 100]], @experiment.value_list
    assert_equal [4, 1], @experiment.multiply_list
  end

  def test_extend_with_multiple_values
    @experiment.stubs(:save)
    Scalarm::Database::MongoActiveRecord.stubs(:where).returns([])

    original_size = @experiment.experiment_size

    @experiment.add_parameter_values("main_category___main_group___parameter2", [100, 200, 300])

    assert_equal original_size + 3, @experiment.experiment_size
    assert_equal [[0], [1, 2, 3, 100, 200, 300]], @experiment.value_list
    assert_equal [6, 1], @experiment.multiply_list

    original_size = @experiment.experiment_size

    @experiment.add_parameter_values("main_category___main_group___parameter1", [100, 200, 300])

    assert_equal original_size * 4, @experiment.experiment_size
    assert_equal [[0, 100, 200, 300], [1, 2, 3, 100, 200, 300]], @experiment.value_list
    assert_equal [6, 1], @experiment.multiply_list

  end

  def test_extend_experiment_with_doe
    @experiment_with_doe.stubs(:save)
    Scalarm::Database::MongoActiveRecord.stubs(:where).returns([])

    original_size = @experiment_with_doe.experiment_size

    @experiment_with_doe.add_parameter_values("main_category___main_group___parameter1", [1])

    assert_equal original_size + 2, @experiment_with_doe.experiment_size

{'fraction_non_alphanumeric': 0.0972972972972973, 'fraction_numerical': 0.019265419265419265, 'mean_word_length': 0.8168198413697595, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 135, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 259, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6121714', 'n_tokens_mistral': 3014, 'n_tokens_neox': 2768, 'n_words': 551}