📄 booleangenetest.java
字号:
/*
* This file is part of JGAP.
*
* JGAP offers a dual license model containing the LGPL as well as the MPL.
*
* For licencing information please see the file license.txt included with JGAP
* or have a look at the top of class org.jgap.Chromosome which representatively
* includes the JGAP license policy applicable for any file delivered with JGAP.
*/
package org.jgap.impl;
import java.util.*;
import org.jgap.*;
import junit.framework.*;
/**
* Tests the BooleanGene class.
*
* @author Klaus Meffert
* @since 1.1
*/
public class BooleanGeneTest
extends JGAPTestCase {
/** String containing the CVS revision. Read out via reflection!*/
private final static String CVS_REVISION = "$Revision: 1.21 $";
public static Test suite() {
TestSuite suite = new TestSuite(BooleanGeneTest.class);
return suite;
}
public void testConstruct_0()
throws Exception {
Gene gene = new BooleanGene(conf);
//following should be possible without exception
gene.setAllele(Boolean.valueOf(true));
gene.setAllele(Boolean.valueOf(false));
}
/**
* @throws Exception
*
* @author Klaus Meffert
* @since 2.4
*/
public void testConstruct_1()
throws Exception {
BooleanGene gene = new BooleanGene(conf, true);
assertEquals(true, gene.booleanValue());
gene = new BooleanGene(conf, false);
assertEquals(false, gene.booleanValue());
}
/**
* @throws Exception
*
* @author Klaus Meffert
* @since 2.4
*/
public void testConstruct_2()
throws Exception {
BooleanGene gene = new BooleanGene(conf, Boolean.valueOf(true));
assertEquals(true, gene.booleanValue());
gene = new BooleanGene(conf, Boolean.valueOf(false));
assertEquals(false, gene.booleanValue());
}
/**
* @throws Exception
*
* @author Klaus Meffert
* @since 2.4
*/
public void testConstruct_3()
throws Exception {
try {
new BooleanGene(conf, null);
fail();
} catch (IllegalArgumentException iex) {
; //this is OK
}
}
/**
* @throws Exception
*
* @author Klaus Meffert
* @since 3.1
*/
public void testConstruct_4()
throws Exception {
Genotype.setStaticConfiguration(conf);
Gene gene = new BooleanGene();
assertSame(conf, gene.getConfiguration());
}
public void testToString_0()
throws Exception {
Gene gene = new BooleanGene(conf);
gene.setAllele(Boolean.valueOf(true));
assertEquals("BooleanGene=true", gene.toString());
}
public void testToString_1()
throws Exception {
Gene gene = new BooleanGene(conf);
gene.setAllele(Boolean.valueOf(false));
assertEquals("BooleanGene=false", gene.toString());
}
/**
* @throws Exception
*
* @author Klaus Meffert
* @since 2.4
*/
public void testToString_2()
throws Exception {
Gene gene = new BooleanGene(conf, true);
assertEquals("BooleanGene=true", gene.toString());
}
public void testGetAllele_0()
throws Exception {
Gene gene = new BooleanGene(conf);
gene.setAllele(Boolean.valueOf(true));
assertEquals(Boolean.valueOf(true), gene.getAllele());
}
public void testGetAllele_1()
throws Exception {
Gene gene = new BooleanGene(conf);
gene.setAllele(Boolean.valueOf(false));
assertEquals(Boolean.valueOf(false), gene.getAllele());
}
public void testGetAllele_2()
throws Exception {
Gene gene = new BooleanGene(conf);
try {
gene.setAllele(new Integer(100));
fail();
} catch (ClassCastException classex) {
; //this is OK
}
}
public void testEquals_0()
throws Exception {
Gene gene1 = new BooleanGene(conf);
Gene gene2 = new BooleanGene(conf);
assertTrue(gene1.equals(gene2));
}
public void testEquals_1()
throws Exception {
Gene gene1 = new BooleanGene(conf);
assertFalse(gene1.equals(null));
}
public void testEquals_2()
throws Exception {
Gene gene1 = new BooleanGene(conf);
gene1.setAllele(Boolean.valueOf(true));
Gene gene2 = new BooleanGene(conf);
gene2.setAllele(Boolean.valueOf(false));
assertFalse(gene1.equals(gene2));
assertFalse(gene2.equals(gene1));
}
public void testEquals_3()
throws Exception {
Gene gene1 = new BooleanGene(conf);
assertFalse(gene1.equals(new IntegerGene(conf)));
}
public void testEquals_4()
throws Exception {
Gene gene1 = new BooleanGene(conf);
Gene gene2 = new IntegerGene(conf);
assertFalse(gene1.equals(gene2));
assertFalse(gene2.equals(gene1));
}
public void testEquals_5()
throws Exception {
Gene gene1 = new BooleanGene(conf);
Gene gene2 = new FixedBinaryGene(conf, 1);
assertFalse(gene1.equals(gene2));
assertFalse(gene2.equals(gene1));
}
public void testBooleanValue_0()
throws Exception {
BooleanGene gene1 = new BooleanGene(conf);
gene1.setAllele(Boolean.valueOf(true));
assertEquals(true, gene1.booleanValue());
}
public void testBooleanValue_1()
throws Exception {
BooleanGene gene1 = new BooleanGene(conf);
gene1.setAllele(Boolean.valueOf(false));
assertEquals(false, gene1.booleanValue());
}
public void testBooleanValue_2()
throws Exception {
BooleanGene gene1 = new BooleanGene(conf);
gene1.setAllele(null);
try {
assertEquals(true, gene1.booleanValue());
fail();
} catch (NullPointerException nullex) {
; //this is OK
}
}
/**
* Set Allele to null, no exception should occur.
*
* @throws Exception
*/
public void testSetAllele_0()
throws Exception {
Gene gene1 = new BooleanGene(conf);
gene1.setAllele(null);
}
public void testSetAllele_1()
throws Exception {
Gene gene1 = new BooleanGene(conf);
try {
gene1.setAllele("22");
fail();
} catch (ClassCastException classex) {
; //this is OK
}
}
/**
* Set Allele to boolean value, no exception should occur.
*
* @throws Exception
*/
public void testSetAllele_2()
throws Exception {
Gene gene1 = new BooleanGene(conf);
gene1.setAllele(Boolean.valueOf(true));
}
/**
* Set Allele to boolean value, no exception should occur.
*
* @throws Exception
*/
public void testSetAllele_3()
throws Exception {
Gene gene1 = new BooleanGene(conf);
gene1.setAllele(Boolean.valueOf(false));
}
public void testCompareTo_0()
throws Exception {
Gene gene1 = new BooleanGene(conf);
assertEquals(1, gene1.compareTo(null));
}
public void testCompareTo_1()
throws Exception {
Gene gene1 = new BooleanGene(conf);
Gene gene2 = new BooleanGene(conf);
assertEquals(0, gene1.compareTo(gene2));
assertEquals(0, gene2.compareTo(gene1));
}
public void testCompareTo_2()
throws Exception {
Gene gene1 = new BooleanGene(conf);
gene1.setAllele(Boolean.valueOf(true));
Gene gene2 = new BooleanGene(conf);
gene2.setAllele(Boolean.valueOf(true));
assertEquals(0, gene1.compareTo(gene2));
assertEquals(0, gene2.compareTo(gene1));
gene1.setAllele(Boolean.valueOf(false));
gene2.setAllele(Boolean.valueOf(false));
assertEquals(0, gene1.compareTo(gene2));
assertEquals(0, gene2.compareTo(gene1));
}
public void testCompareTo_3()
throws Exception {
Gene gene1 = new BooleanGene(conf);
gene1.setAllele(Boolean.valueOf(true));
Gene gene2 = new BooleanGene(conf);
gene2.setAllele(Boolean.valueOf(false));
assertEquals(1, gene1.compareTo(gene2));
assertEquals( -1, gene2.compareTo(gene1));
}
/**
* @throws Exception
*
* @author Klaus Meffert
* @since 2.2
*/
public void testCompareTo_4()
throws Exception {
Gene gene1 = new BooleanGene(conf);
gene1.setAllele(Boolean.valueOf(true));
Gene gene2 = new BooleanGene(conf);
assertEquals(1, gene1.compareTo(gene2));
assertEquals( -1, gene2.compareTo(gene1));
}
/**
* @throws Exception
*
* @author Klaus Meffert
* @since 2.2
*/
public void testCompareTo_5()
throws Exception {
Gene gene1 = new BooleanGene(conf);
Gene gene2 = new BooleanGene(conf);
assertEquals(0, gene1.compareTo(gene2));
assertEquals(0, gene2.compareTo(gene1));
}
/**
* @throws Exception
*
* @author Klaus Meffert
* @since 3.1
*/
public void testCompareTo_6()
throws Exception {
Gene gene1 = new BooleanGene(conf);
Gene gene2 = new BooleanGene(conf);
gene1.setCompareApplicationData(true);
gene2.setCompareApplicationData(false);
List app1 = new Vector();
gene1.setApplicationData(app1);
assertEquals(1, gene1.compareTo(gene2));
assertEquals(0, gene2.compareTo(gene1));
}
/**
* @throws Exception
*
* @author Klaus Meffert
* @since 3.1
*/
public void testCompareTo_6_2()
throws Exception {
Gene gene1 = new BooleanGene(conf);
gene1.setAllele(Boolean.TRUE);
Gene gene2 = new BooleanGene(conf);
gene2.setAllele(Boolean.FALSE);
gene1.setCompareApplicationData(true);
gene2.setCompareApplicationData(true);
List app1 = new Vector();
gene1.setApplicationData(app1);
assertEquals(1, gene1.compareTo(gene2));
assertEquals(-1, gene2.compareTo(gene1));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -