Update of /cvsroot/metamorphosis/ruper2/src/test/core/org/krysalis/ruper2/util/select/logic
In directory sc8-pr-cvs1:/tmp/cvs-serv30481/src/test/core/org/krysalis/ruper2/util/select/logic
Added Files:
NotSelectorTests.java BooleanSelectorTests.java
AndSelectorTests.java OrSelectorTests.java
Log Message:
Avoid clash with existing Ruper...
--- NEW FILE: NotSelectorTests.java ---
package org.krysalis.ruper2.util.select.logic;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
*
* @author Ben Sommerville
*/
public class NotSelectorTests extends TestCase {
private NotSelector m_not = new NotSelector();
public void testEmpty() throws Exception {
assertFalse("Not should be false when empty", m_not.select(this )) ;
}
public void testSetNull() {
try{
m_not.setSelector( null );
fail("Should throw exception if we try to set null selector");
} catch( NullPointerException e ) {
//expect this
}
}
public void testNot() throws Exception {
m_not.setSelector( BooleanSelector.TRUE );
assertFalse("Not should be false when arg is true", m_not.select(this )) ;
m_not.setSelector( BooleanSelector.FALSE );
assertTrue("Not should be true when arg is false", m_not.select(this )) ;
}
public void testEquals() {
NotSelector testSelector = new NotSelector( BooleanSelector.TRUE );
m_not.setSelector( BooleanSelector.TRUE );
assertTrue("Selectors should be equal", m_not.equals(testSelector));
assertTrue("Selectors should be equal", testSelector.equals(m_not));
m_not.setSelector( BooleanSelector.FALSE );
assertFalse("Selectors should not be equal", m_not.equals(testSelector));
assertFalse("Selectors should not be equal", testSelector.equals(m_not));
}
public void testHashCode() {
NotSelector testSelector = new NotSelector( BooleanSelector.TRUE );
m_not.setSelector( BooleanSelector.TRUE );
assertEquals("Selectors should have same hashcode", m_not.hashCode(),
testSelector.hashCode() );
m_not.setSelector( BooleanSelector.FALSE );
assertTrue("Selectors should have different hash codes",
m_not.hashCode() != testSelector.hashCode() );
}
public static Test suite() {
return new TestSuite(NotSelectorTests.class);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
}
--- NEW FILE: BooleanSelectorTests.java ---
package org.krysalis.ruper2.util.select.logic;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.krysalis.ruper2.util.select.Selector;
/**
* Test the boolean selectors
* @author Ben Sommerville
*/
public class BooleanSelectorTests extends TestCase {
protected void setUp() {
}
protected void tearDown() {
}
public void testSelect() throws Exception {
Selector selector = new BooleanSelector(true);
assertTrue("Select is true", selector.select(this)) ;
selector = new BooleanSelector(false);
assertFalse("Select is false", selector.select(this)) ;
}
/**
* Test that identity is defined by result not be object.
*/
public void testIdentity(){
Selector firstTrue = BooleanSelector.TRUE;
Selector secondTrue = new BooleanSelector( true );
assertTrue("Two true selectors should be equals", firstTrue.equals( secondTrue ));
assertTrue("Two true selectors should be equals", secondTrue.equals( firstTrue ));
assertFalse("True and false selectors should not be equals", firstTrue.equals( BooleanSelector.FALSE ));
assertEquals("Hashcode should be the same", firstTrue.hashCode(), secondTrue.hashCode() );
assertTrue("True and false hashcode should be different", firstTrue.hashCode() != BooleanSelector.FALSE.hashCode() );
}
public static Test suite() {
return new TestSuite(BooleanSelectorTests.class);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
}
--- NEW FILE: AndSelectorTests.java ---
package org.krysalis.ruper2.util.select.logic;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.krysalis.ruper2.util.select.MockSelector;
/**
*
* @author Ben Sommerville
*/
public class AndSelectorTests extends TestCase {
AndSelector m_and = new AndSelector();
protected void setUp() {
}
protected void tearDown() {
}
public void testEmpty() throws Exception {
assertTrue("Empty selector should be true", m_and.select(this));
}
public void testTrue() throws Exception {
m_and.addSelector( BooleanSelector.TRUE );
assertTrue("And with true should return true", m_and.select( this ));
m_and.addSelector( new MockSelector(true));
m_and.addSelector( new MockSelector(true));
assertTrue("And with all trues should return true", m_and.select( this ));
}
public void testFalse() throws Exception {
m_and.addSelector( BooleanSelector.FALSE);
assertFalse("And with false should return false", m_and.select( this ));
m_and.addSelector( new MockSelector(false));
m_and.addSelector( new MockSelector(false));
assertFalse("And with all false should return false", m_and.select( this ));
}
public void testTrueAndFalse() throws Exception {
m_and.addSelector( BooleanSelector.TRUE );
m_and.addSelector( BooleanSelector.FALSE );
assertFalse("And with one false should return false", m_and.select( this ));
m_and.addSelector( new MockSelector(true));
assertFalse("And with one false should return false", m_and.select( this ));
}
public static Test suite() {
return new TestSuite(AndSelectorTests.class);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
}
--- NEW FILE: OrSelectorTests.java ---
package org.krysalis.ruper2.util.select.logic;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.krysalis.ruper2.util.select.MockSelector;
/**
*
* @author Ben Sommerville
*/
public class OrSelectorTests extends TestCase {
OrSelector m_or = new OrSelector();
protected void setUp() {
}
protected void tearDown() {
}
public void testEmpty() throws Exception {
assertTrue("Empty selector should be true", m_or.select(this));
}
public void testTrue() throws Exception {
m_or.addSelector( BooleanSelector.TRUE );
assertTrue("Or with true should return true", m_or.select( this ));
m_or.addSelector( new MockSelector(true));
m_or.addSelector( new MockSelector(true));
assertTrue("Or with all trues should return true", m_or.select( this ));
}
public void testFalse() throws Exception {
m_or.addSelector( BooleanSelector.FALSE);
assertFalse("Or with false should return false", m_or.select( this ));
m_or.addSelector( new MockSelector(false));
m_or.addSelector( new MockSelector(false));
assertFalse("Or with all false should return false", m_or.select( this ));
}
public void testTrueAndFalse() throws Exception {
m_or.addSelector( BooleanSelector.FALSE );
m_or.addSelector( BooleanSelector.TRUE );
assertTrue("Or with one true should return true", m_or.select( this ));
m_or.addSelector( new MockSelector(false));
assertTrue("Or with one true should return true", m_or.select( this ));
}
public static Test suite() {
return new TestSuite(OrSelectorTests.class);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
}
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.