📄 culturetest.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.distr;
import org.jgap.*;
import junit.framework.*;
/**
* Tests for Culture class
*
* @author Klaus Meffert
* @since 2.3
*/
public class CultureTest
extends JGAPTestCase {
/** String containing the CVS revision. Read out via reflection!*/
private static final String CVS_REVISION = "$Revision: 1.8 $";
public static Test suite() {
TestSuite suite = new TestSuite(CultureTest.class);
return suite;
}
/**
* @author Klaus Meffert
* @since 2.3
*/
public void testConstruct_0() {
try {
new Culture(0);
fail();
}
catch (IllegalArgumentException iex) {
; //this is OK
}
}
/**
* @author Klaus Meffert
* @since 2.3
*/
public void testConstruct_1() {
try {
new Culture( -3);
fail();
}
catch (IllegalArgumentException iex) {
; //this is OK
}
}
/**
* @author Klaus Meffert
* @since 2.3
*/
public void testConstruct_2() {
Culture c = new Culture(7);
assertEquals(7, c.size());
}
/**
* @author Klaus Meffert
* @since 2.3
*/
public void testGet_0() {
try {
Culture c = new Culture(35);
c.set( -1, 2, 5, "");
fail();
}
catch (IllegalArgumentException iex) {
//this is OK
}
}
/**
* @author Klaus Meffert
* @since 2.3
*/
public void testGet_1() {
try {
Culture c = new Culture(35);
c.set(35, 2, 5, "");
fail();
}
catch (IllegalArgumentException iex) {
//this is OK
}
}
/**
* @author Klaus Meffert
* @since 2.3
*/
public void testGet_2() {
Culture c = new Culture(9);
c.set(3, 5.7d, 0, "");
CultureMemoryCell cell = c.get(3);
assertEquals(5.7d, cell.getCurrentValueAsDouble(), DELTA);
assertEquals(0, cell.getHistorySize());
assertEquals("", cell.getName());
}
/**
* @author Klaus Meffert
* @since 2.3
*/
public void testGet_3() {
Culture c = new Culture(9);
c.set(3, -5.7d, -1, null);
CultureMemoryCell cell = c.get(3);
assertEquals( -5.7d, cell.getCurrentValueAsDouble(), DELTA);
assertEquals(0, cell.getHistorySize());
assertEquals(null, cell.getName());
}
/**
* @author Klaus Meffert
* @since 2.3
*/
public void testGet_4() {
Culture c = new Culture(11);
c.set(0, 0.0d, 17, "aName");
CultureMemoryCell cell = c.get(0);
assertEquals(0.0d, cell.getCurrentValueAsDouble(), DELTA);
assertEquals(17, cell.getHistorySize());
assertEquals("aName", cell.getName());
}
/**
* @author Klaus Meffert
* @since 2.3
*/
public void testGet_5() {
Culture c = new Culture(11);
CultureMemoryCell cell = c.get(7);
assertEquals(null, cell);
}
/**
* @author Klaus Meffert
* @since 2.3
*/
public void testToString_0() {
Culture c = new Culture(11);
String s = "[";
for (int i = 0; i < c.size(); i++) {
if (i > 0) {
s += ";";
}
if (c.get(i) == null) {
s += "null";
}
else {
s += c.get(i).toString();
}
}
s += "]";
assertEquals(s, c.toString());
}
/**
* @author Klaus Meffert
* @since 2.3
*/
public void testToString_1() {
Culture c = new Culture(11);
c.set(1, 0.0d, 17, "aName");
c.set(3, 23.5d, 5, "ANAME");
c.set(4, 19.6d, 0, "aName");
String s = "[";
for (int i = 0; i < c.size(); i++) {
if (i > 0) {
s += ";";
}
if (c.get(i) == null) {
s += "null";
}
else {
s += c.get(i).toString();
}
}
s += "]";
assertEquals(s, c.toString());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -