<commit_before>/*
 * Java Genetic Algorithm Library (@!identifier!@).
 * Copyright (c) @!year!@ <NAME>
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Author:
 *     <NAME> (<EMAIL>)
 *     
 */
package org.jenetics;

import java.util.Comparator;

import org.testng.Assert;
import org.testng.annotations.Test;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Id$
 */
public class OptimizeTest {

	private static class FF implements FitnessFunction<Float64Gene, Double> {
		private static final long serialVersionUID = 6215331666272441749L;

		@Override
		public Double evaluate(Genotype<Float64Gene> genotype) {
			return genotype.getGene().doubleValue();
		}
	}
	
	private static final FF _ff = new FF();
	
	private static Phenotype<Float64Gene, Double> pt(double value) {
		return Phenotype.valueOf(Genotype.valueOf(new Float64Chromosome(Float64Gene.valueOf(value, 0, 10))), _ff, 0);
	}
	
	@Test
	public void comparator() {
		Comparator<Phenotype<Float64Gene, Double>> comp = Optimize.MAXIMUM.comparator();
		Assert.assertTrue(comp.compare(pt(2), pt(3)) < 0);
		Assert.assertTrue(comp.compare(pt(2), pt(2)) == 0);
		Assert.assertTrue(comp.compare(pt(5), pt(3)) > 0);
		
		comp = Optimize.MINIMUM.comparator();
		Assert.assertTrue(comp.compare(pt(4), pt(3)) < 0);
		Assert.assertTrue(comp.compare(pt(2), pt(2)) == 0);
		Assert.assertTrue(comp.compare(pt(2), pt(3)) > 0);
	}
	
	@Test
	public void compare() {
		final FF ff = new FF();
		final Phenotype<Float64Gene, Double> pt1 = Phenotype.valueOf(Genotype.valueOf(
				new Float64Chromosome(Float64Gene.valueOf(5, 0, 10))), ff, 0);<commit_msg>Add test for Optimize.comparator() method. (Fix compile error.)<commit_after>/*
 * Java Genetic Algorithm Library (@!identifier!@).
 * Copyright (c) @!year!@ <NAME>
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Author:
 *     <NAME> (<EMAIL>.at)
 *     
 */
package org.jenetics;

import java.util.Comparator;

import org.testng.Assert;
import org.testng.annotations.Test;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Id$
 */
public class OptimizeTest {

	private static class FF implements FitnessFunction<Float64Gene, Double> {
		private static final long serialVersionUID = 6215331666272441749L;

		@Override
		public Double evaluate(Genotype<Float64Gene> genotype) {
			return genotype.getGene().doubleValue();
		}
	}
	
	private static final FF _ff = new FF();
	
	private static Phenotype<Float64Gene, Double> pt(double value) {
		return Phenotype.valueOf(Genotype.valueOf(new Float64Chromosome(Float64Gene.valueOf(value, 0, 10))), _ff, 0);
	}
	
	@Test
	public void comparator() {
		Comparator<Phenotype<Float64Gene, Double>> comp =
			Optimize.MAXIMUM.<Phenotype<Float64Gene, Double>>comparator();
		Assert.assertTrue(comp.compare(pt(2), pt(3)) < 0);
		Assert.assertTrue(comp.compare(pt(2), pt(2)) == 0);
		Assert.assertTrue(comp.compare(pt(5), pt(3)) > 0);
		
		comp = Optimize.MINIMUM.<Phenotype<Float64Gene, Double>>comparator();
		Assert.assertTrue(comp.compare(pt(4), pt(3)) < 0);
		Assert.assertTrue(comp.compare(pt(2), pt(2)) == 0);
		Assert.assertTrue(comp.compare(pt(2), pt(3)) > 0);
	}
	
	@Test
	public void compare() {
		final FF ff = new FF();
		final Phenotype<Float64Gene, Double> pt1 = Phenotype.valueOf(Genotype.valueOf(
				new Float64Chromosome(Float64Gene.valueOf(5, 0, 10))), ff, 0);
{'fraction_non_alphanumeric': 0.1239460370994941, 'fraction_numerical': 0.03372681281618887, 'mean_word_length': 4.447761194029851, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '4659987', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1466, 'n_words': 474}