Exemple #1
0
  /** test modifying a word by deleting from it */
  public void testModifyByDeleting() {
    Config config = new Config();
    config.population_max_generations = 1000;
    config.population_max_size = 10;

    Data data = new Data();
    data.createRandom(5, 5);

    Program program = new Program(config, data);

    program.words = "ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;";
    String[] wordList =
        program.createWordListFromWords("ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;");
    program.modifyByDeleting(0, wordList);
    assertEquals(program.words, "DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;");

    program.words = "ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;";
    wordList =
        program.createWordListFromWords("ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;");
    program.modifyByDeleting(2, wordList);
    assertEquals(program.words, "ADD:VAR_4;DIVIDE:VAR_4;SUBTRACT:VAR_4;");

    program.words = "ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;";
    wordList =
        program.createWordListFromWords("ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;");
    program.modifyByDeleting(3, wordList);
    assertEquals(program.words, "ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;");

    program.words = "ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;";
    wordList =
        program.createWordListFromWords("ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;");
    program.modifyByDeleting(4, wordList);
    assertEquals(program.words, "ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;");
  }
  /** test modifying the config */
  public void testModifyConfig() {
    Config config = new Config();
    config.population_max_generations = 1000;
    config.population_max_size = 10;

    Data data = new Data();
    data.createRandom(5, 5);

    Population population = new Population(config, data);
    population.programs[0].score = 10000;
    population.topScore = 0;
    population.modifyConfig(50000);
    assertTrue(true);
  }
  /** setup a population */
  public void testSomeMethod() {
    Config config = new Config();
    config.population_max_generations = 1000;
    config.population_max_size = 10;

    Data data = new Data();
    data.createRandom(5, 5);

    Population population = new Population(config, data);

    config.program_success_score = config.program_initial_score;
    population = new Population(config, data);
    assertTrue(true);
  }
  /** test the output to JavaScript */
  public void testRenderAsJS() {
    Config config = new Config();
    config.population_max_generations = 1000;
    config.population_max_size = 10;

    Data data = new Data();
    data.createRandom(5, 5);

    Population population = new Population(config, data);
    population.modifyConfig(50000);
    population.topScore = 0;
    population.programs[0].words =
        "ADD_CONSTANT:1;SUBTRACT_CONSTANT:1;MULTIPLY_CONSTANT:1;DIVIDE_CONSTANT:1;ADD:VAR_1;SUBTRACT:VAR_1;MULTIPLY:VAR_1;DIVIDE:VAR_1;";
    population.renderAsJS();
    assertTrue(true);
  }
Exemple #5
0
  /** test the copy of one population to another */
  public void testShallowCopy() {
    System.out.println("shallowCopy");

    Config config = new Config();
    config.population_max_generations = 1000;
    config.population_max_size = 10;

    Data data = new Data();
    data.createRandom(5, 5);

    Program programFrom = new Program(config, data);

    Program programTo = Program.shallowCopy(programFrom, config, data);

    assertEquals(programFrom.words, programTo.words);
    assertEquals(programFrom.score, programTo.score);
  }
Exemple #6
0
  /** test a program by modifying a word */
  public void testModifyByChanging() {
    System.out.println("modifyByChanging");

    Config config = new Config();
    config.population_max_generations = 1000;
    config.population_max_size = 10;

    Data data = new Data();
    data.createRandom(5, 5);

    Program program = new Program(config, data);

    program.words = "ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;";
    String[] wordList =
        program.createWordListFromWords("ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;");
    program.modifyByChanging(0, wordList, "CHANGE_TO");
    assertEquals(program.words, "CHANGE_TO;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;");

    program.words = "ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;";
    wordList =
        program.createWordListFromWords("ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;");
    program.modifyByChanging(1, wordList, "CHANGE_TO");
    assertEquals(program.words, "ADD:VAR_4;CHANGE_TO;DIVIDE:VAR_2;SUBTRACT:VAR_4;");

    program.words = "ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;";
    wordList =
        program.createWordListFromWords("ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;");
    program.modifyByChanging(3, wordList, "CHANGE_TO");
    assertEquals(program.words, "ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;CHANGE_TO;");

    program.words = "ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;";
    wordList =
        program.createWordListFromWords("ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;");
    program.modifyByChanging(4, wordList, "CHANGE_TO");
    assertEquals(program.words, "ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;");

    program.words = "ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;";
    wordList =
        program.createWordListFromWords("ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;");
    program.modifyByChanging(-1, wordList, "CHANGE_TO");
    assertEquals(program.words, "ADD:VAR_4;DIVIDE:VAR_4;DIVIDE:VAR_2;SUBTRACT:VAR_4;");
  }