<commit_before>require File.expand_path("../test_helper", __FILE__)

require File.expand_path("../../lib/population", __FILE__)

describe "Population" do
  describe "the first vector" do
    it "is accessible" do
      vector = Vector.new(2, [1, 2], [1, 2], lambda {|i, j| i + j})
      population = Population.new(1, 2, [1, 2], [1, 2], lambda {|i, j| i + j})
      assert_equal(vector, population[0])
    end
  end

  describe "with one vector" do
    it "has a fitness" do
      population = Population.new(1, 2, [1.1, 2.2], [1.1, 2.2], lambda {|i, j| i + j})
      assert_in_delta(3.3, population[0].fitness, 0.00001)
    end
  end

  it "has a difference vector" do
    population = Population.new(3, 1, [1.0], [1.0], lambda {|i| i + 2})
    assert(population.difference_vector[0], 1.0)
  end

  it "has a crossover vector" do
    population = Population.new(3, 1, [1.0], [1.0], lambda {|i| i + 2})
    assert(population.crossover_vector[0], 1.0)
  end

  describe "with fitness criteria x squared plus one" do
    it "has a minima at zero" do
      population = Population.new(100, 1, [-100], [100], lambda {|x|  x*x+1  })
      vector, value, generations = population.differential_evolution(200000, 0.0005)

      assert_in_delta(value, 1.0, 0.0005);
      assert_in_delta(vector[0], 0.0, 0.002)
    end
  end

  describe "for camel hump back problem" do
    it "has a solution" do
      population = Population.new(100, 2, [-3.0, -2.0], [3.0, 2.0], lambda {|x, y|  ( 4.0 - 2.1*x*x +  x*x*x*x/3.0) * x*x + x*y + ( -4.0  +  4.0*y*y) * y*y })
      vector, value, generations = population.differential_evolution(200000, 0.0)
<commit_msg>Don't run end-to-end test that takes a lomg amount of time as a part of unit tests<commit_after>require File.expand_path("../test_helper", __FILE__)

require File.expand_path("../../lib/population", __FILE__)

describe "Population" do
  describe "the first vector" do
    it "is accessible" do
      vector = Vector.new(2, [1, 2], [1, 2], lambda {|i, j| i + j})
      population = Population.new(1, 2, [1, 2], [1, 2], lambda {|i, j| i + j})
      assert_equal(vector, population[0])
    end
  end

  describe "with one vector" do
    it "has a fitness" do
      population = Population.new(1, 2, [1.1, 2.2], [1.1, 2.2], lambda {|i, j| i + j})
      assert_in_delta(3.3, population[0].fitness, 0.00001)
    end
  end

  it "has a difference vector" do
    population = Population.new(3, 1, [1.0], [1.0], lambda {|i| i + 2})
    assert(population.difference_vector[0], 1.0)
  end

  it "has a crossover vector" do
    population = Population.new(3, 1, [1.0], [1.0], lambda {|i| i + 2})
    assert(population.crossover_vector[0], 1.0)
  end

  describe "with fitness criteria x squared plus one" do
    it "has a minima at zero" do
      population = Population.new(100, 1, [-100], [100], lambda {|x|  x*x+1  })
      vector, value, generations = population.differential_evolution(200000, 0.0005)

      assert_in_delta(value, 1.0, 0.0005);
      assert_in_delta(vector[0], 0.0, 0.002)
    end
  end

  describe "for camel hump back problem" do
    it "has a solution" do
      skip "don't run end-to-end test as a part of unit test suite"
      population = Population.new(100, 2, [-3.0, -2.0], [3.0, 2.0], lambda {|x, y|  ( 4.0 - 2.1*x*x +  x*x*x*x/3.0) * x*x + x*y + ( -4.0  +  4.0*y*y) * y*y })
      vector, value, generations = population.differential_evolution(200000, 0.0)

{'fraction_non_alphanumeric': 0.16554548113483475, 'fraction_numerical': 0.06844106463878327, 'mean_word_length': 3.0, 'pattern_counts': {'":': 0, '<': 3, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4192280', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1276, 'n_words': 388}