[jboss-svn-commits] JBL Code SVN: r7260 - in labs/jbossrules/trunk/drools-core/src: main/java/org/drools/base/evaluators main/java/org/drools/reteoo test/java/org/drools test/java/org/drools/base test/java/org/drools/base/extractors test/java/org/drools/reteoo test/java/org/drools/rule test/java/org/drools/util
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Oct 31 19:09:30 EST 2006
Author: tirelli
Date: 2006-10-31 19:09:04 -0500 (Tue, 31 Oct 2006)
New Revision: 7260
Added:
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/FieldValueTest.java
Removed:
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/FieldImplTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/OrTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/PriorityQueueTest.java
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/BigIntegerFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/BooleanFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/ByteFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/CharacterFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/DateFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/DoubleFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/FloatFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/IntegerFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/LongFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/ShortFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseFactoryTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/ClassFieldExtractorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/EvaluatorFactoryTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ByteClassFieldExtractorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/CharClassFieldExtractorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/IntClassFieldExtractorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ShortClassFieldExtractorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/BinaryHeapPriorityQueueTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexHashTableTest.java
Log:
Fixing unit tests
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/BigIntegerFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/BigIntegerFactory.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/BigIntegerFactory.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -168,9 +168,9 @@
final Object value1 = extractor1.getValue( object1 );
final Object value2 = extractor2.getValue( object2 );
if ( value1 == null ) {
- return value2 == null;
+ return value2 != null;
}
- return value1.equals( value2 );
+ return !value1.equals( value2 );
}
public String toString() {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/BooleanFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/BooleanFactory.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/BooleanFactory.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -60,7 +60,7 @@
private final static Evaluator INSTANCE = new BooleanEqualEvaluator();
private BooleanEqualEvaluator() {
- super( ValueType.BOOLEAN_TYPE,
+ super( ValueType.PBOOLEAN_TYPE,
Operator.EQUAL );
}
@@ -101,7 +101,7 @@
public final static Evaluator INSTANCE = new BooleanNotEqualEvaluator();
private BooleanNotEqualEvaluator() {
- super( ValueType.BOOLEAN_TYPE,
+ super( ValueType.PBOOLEAN_TYPE,
Operator.NOT_EQUAL );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/ByteFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/ByteFactory.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/ByteFactory.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -68,7 +68,7 @@
public final static Evaluator INSTANCE = new ByteEqualEvaluator();
private ByteEqualEvaluator() {
- super( ValueType.BYTE_TYPE,
+ super( ValueType.PBYTE_TYPE,
Operator.EQUAL );
}
@@ -109,7 +109,7 @@
public final static Evaluator INSTANCE = new ByteNotEqualEvaluator();
private ByteNotEqualEvaluator() {
- super( ValueType.BYTE_TYPE,
+ super( ValueType.PBYTE_TYPE,
Operator.NOT_EQUAL );
}
@@ -149,7 +149,7 @@
public final static Evaluator INSTANCE = new ByteLessEvaluator();
private ByteLessEvaluator() {
- super( ValueType.BYTE_TYPE,
+ super( ValueType.PBYTE_TYPE,
Operator.LESS );
}
@@ -189,7 +189,7 @@
public final static Evaluator INSTANCE = new ByteLessOrEqualEvaluator();
private ByteLessOrEqualEvaluator() {
- super( ValueType.BYTE_TYPE,
+ super( ValueType.PBYTE_TYPE,
Operator.LESS_OR_EQUAL );
}
@@ -229,7 +229,7 @@
public final static Evaluator INSTANCE = new ByteGreaterEvaluator();
private ByteGreaterEvaluator() {
- super( ValueType.BYTE_TYPE,
+ super( ValueType.PBYTE_TYPE,
Operator.GREATER );
}
@@ -269,7 +269,7 @@
private final static Evaluator INSTANCE = new ByteGreaterOrEqualEvaluator();
private ByteGreaterOrEqualEvaluator() {
- super( ValueType.BYTE_TYPE,
+ super( ValueType.PBYTE_TYPE,
Operator.GREATER_OR_EQUAL );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/CharacterFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/CharacterFactory.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/CharacterFactory.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -68,7 +68,7 @@
public final static Evaluator INSTANCE = new CharacterEqualEvaluator();
private CharacterEqualEvaluator() {
- super( ValueType.CHAR_TYPE,
+ super( ValueType.PCHAR_TYPE,
Operator.EQUAL );
}
@@ -108,7 +108,7 @@
public final static Evaluator INSTANCE = new CharacterNotEqualEvaluator();
private CharacterNotEqualEvaluator() {
- super( ValueType.CHAR_TYPE,
+ super( ValueType.PCHAR_TYPE,
Operator.NOT_EQUAL );
}
@@ -148,7 +148,7 @@
public final static Evaluator INSTANCE = new CharacterLessEvaluator();
private CharacterLessEvaluator() {
- super( ValueType.CHAR_TYPE,
+ super( ValueType.PCHAR_TYPE,
Operator.LESS );
}
@@ -188,7 +188,7 @@
public final static Evaluator INSTANCE = new CharacterLessOrEqualEvaluator();
private CharacterLessOrEqualEvaluator() {
- super( ValueType.CHAR_TYPE,
+ super( ValueType.PCHAR_TYPE,
Operator.LESS_OR_EQUAL );
}
@@ -228,7 +228,7 @@
public final static Evaluator INSTANCE = new CharacterGreaterEvaluator();
private CharacterGreaterEvaluator() {
- super( ValueType.CHAR_TYPE,
+ super( ValueType.PCHAR_TYPE,
Operator.GREATER );
}
@@ -268,7 +268,7 @@
private final static Evaluator INSTANCE = new CharacterGreaterOrEqualEvaluator();
private CharacterGreaterOrEqualEvaluator() {
- super( ValueType.CHAR_TYPE,
+ super( ValueType.PCHAR_TYPE,
Operator.GREATER_OR_EQUAL );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/DateFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/DateFactory.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/DateFactory.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -140,6 +140,9 @@
if ( value1 == null ) {
return value2 == null;
}
+ if ( value2 == null ) {
+ return false;
+ }
return value1.compareTo( value2 ) == 0;
}
@@ -208,8 +211,11 @@
final Date value1 = (Date) extractor1.getValue( object1 );
final Date value2 = (Date) extractor2.getValue( object2 );
if ( value1 == null ) {
- return value2 == null;
+ return value2 != null;
}
+ if ( value2 == null ) {
+ return true;
+ }
return value1.compareTo( value2 ) != 0;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/DoubleFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/DoubleFactory.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/DoubleFactory.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -68,7 +68,7 @@
public final static Evaluator INSTANCE = new DoubleEqualEvaluator();
private DoubleEqualEvaluator() {
- super( ValueType.DOUBLE_TYPE,
+ super( ValueType.PDOUBLE_TYPE,
Operator.EQUAL );
}
@@ -112,7 +112,7 @@
public final static Evaluator INSTANCE = new DoubleNotEqualEvaluator();
private DoubleNotEqualEvaluator() {
- super( ValueType.DOUBLE_TYPE,
+ super( ValueType.PDOUBLE_TYPE,
Operator.NOT_EQUAL );
}
@@ -156,7 +156,7 @@
public final static Evaluator INSTANCE = new DoubleLessEvaluator();
private DoubleLessEvaluator() {
- super( ValueType.DOUBLE_TYPE,
+ super( ValueType.PDOUBLE_TYPE,
Operator.LESS );
}
@@ -200,7 +200,7 @@
public final static Evaluator INSTANCE = new DoubleLessOrEqualEvaluator();
private DoubleLessOrEqualEvaluator() {
- super( ValueType.DOUBLE_TYPE,
+ super( ValueType.PDOUBLE_TYPE,
Operator.LESS_OR_EQUAL );
}
@@ -244,7 +244,7 @@
public final static Evaluator INSTANCE = new DoubleGreaterEvaluator();
private DoubleGreaterEvaluator() {
- super( ValueType.DOUBLE_TYPE,
+ super( ValueType.PDOUBLE_TYPE,
Operator.GREATER );
}
@@ -288,7 +288,7 @@
private final static Evaluator INSTANCE = new DoubleGreaterOrEqualEvaluator();
private DoubleGreaterOrEqualEvaluator() {
- super( ValueType.DOUBLE_TYPE,
+ super( ValueType.PDOUBLE_TYPE,
Operator.GREATER_OR_EQUAL );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/FloatFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/FloatFactory.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/FloatFactory.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -66,7 +66,7 @@
public final static Evaluator INSTANCE = new FloatEqualEvaluator();
private FloatEqualEvaluator() {
- super( ValueType.FLOAT_TYPE,
+ super( ValueType.PFLOAT_TYPE,
Operator.EQUAL );
}
@@ -110,7 +110,7 @@
public final static Evaluator INSTANCE = new FloatNotEqualEvaluator();
private FloatNotEqualEvaluator() {
- super( ValueType.FLOAT_TYPE,
+ super( ValueType.PFLOAT_TYPE,
Operator.NOT_EQUAL );
}
@@ -154,7 +154,7 @@
public final static Evaluator INSTANCE = new FloatLessEvaluator();
private FloatLessEvaluator() {
- super( ValueType.FLOAT_TYPE,
+ super( ValueType.PFLOAT_TYPE,
Operator.LESS );
}
@@ -198,7 +198,7 @@
public final static Evaluator INSTANCE = new FloatLessOrEqualEvaluator();
private FloatLessOrEqualEvaluator() {
- super( ValueType.FLOAT_TYPE,
+ super( ValueType.PFLOAT_TYPE,
Operator.LESS_OR_EQUAL );
}
@@ -242,7 +242,7 @@
public final static Evaluator INSTANCE = new FloatGreaterEvaluator();
private FloatGreaterEvaluator() {
- super( ValueType.FLOAT_TYPE,
+ super( ValueType.PFLOAT_TYPE,
Operator.GREATER );
}
@@ -286,7 +286,7 @@
private final static Evaluator INSTANCE = new FloatGreaterOrEqualEvaluator();
private FloatGreaterOrEqualEvaluator() {
- super( ValueType.FLOAT_TYPE,
+ super( ValueType.PFLOAT_TYPE,
Operator.GREATER_OR_EQUAL );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/IntegerFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/IntegerFactory.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/IntegerFactory.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -68,7 +68,7 @@
public final static Evaluator INSTANCE = new IntegerEqualEvaluator();
private IntegerEqualEvaluator() {
- super( ValueType.INTEGER_TYPE,
+ super( ValueType.PINTEGER_TYPE,
Operator.EQUAL );
}
@@ -109,7 +109,7 @@
public final static Evaluator INSTANCE = new IntegerNotEqualEvaluator();
private IntegerNotEqualEvaluator() {
- super( ValueType.INTEGER_TYPE,
+ super( ValueType.PINTEGER_TYPE,
Operator.NOT_EQUAL );
}
@@ -149,7 +149,7 @@
public final static Evaluator INSTANCE = new IntegerLessEvaluator();
private IntegerLessEvaluator() {
- super( ValueType.INTEGER_TYPE,
+ super( ValueType.PINTEGER_TYPE,
Operator.LESS );
}
@@ -189,7 +189,7 @@
public final static Evaluator INSTANCE = new IntegerLessOrEqualEvaluator();
private IntegerLessOrEqualEvaluator() {
- super( ValueType.INTEGER_TYPE,
+ super( ValueType.PINTEGER_TYPE,
Operator.LESS_OR_EQUAL );
}
@@ -229,7 +229,7 @@
public final static Evaluator INSTANCE = new IntegerGreaterEvaluator();
private IntegerGreaterEvaluator() {
- super( ValueType.INTEGER_TYPE,
+ super( ValueType.PINTEGER_TYPE,
Operator.GREATER );
}
@@ -269,7 +269,7 @@
private final static Evaluator INSTANCE = new IntegerGreaterOrEqualEvaluator();
private IntegerGreaterOrEqualEvaluator() {
- super( ValueType.INTEGER_TYPE,
+ super( ValueType.PINTEGER_TYPE,
Operator.GREATER_OR_EQUAL );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/LongFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/LongFactory.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/LongFactory.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -68,7 +68,7 @@
public final static Evaluator INSTANCE = new LongEqualEvaluator();
private LongEqualEvaluator() {
- super( ValueType.LONG_TYPE,
+ super( ValueType.PLONG_TYPE,
Operator.EQUAL );
}
@@ -108,7 +108,7 @@
public final static Evaluator INSTANCE = new LongNotEqualEvaluator();
private LongNotEqualEvaluator() {
- super( ValueType.LONG_TYPE,
+ super( ValueType.PLONG_TYPE,
Operator.NOT_EQUAL );
}
@@ -148,7 +148,7 @@
public final static Evaluator INSTANCE = new LongLessEvaluator();
private LongLessEvaluator() {
- super( ValueType.LONG_TYPE,
+ super( ValueType.PLONG_TYPE,
Operator.LESS );
}
@@ -188,7 +188,7 @@
public final static Evaluator INSTANCE = new LongLessOrEqualEvaluator();
private LongLessOrEqualEvaluator() {
- super( ValueType.LONG_TYPE,
+ super( ValueType.PLONG_TYPE,
Operator.LESS_OR_EQUAL );
}
@@ -228,7 +228,7 @@
public final static Evaluator INSTANCE = new LongGreaterEvaluator();
private LongGreaterEvaluator() {
- super( ValueType.LONG_TYPE,
+ super( ValueType.PLONG_TYPE,
Operator.GREATER );
}
@@ -268,7 +268,7 @@
private final static Evaluator INSTANCE = new LongGreaterOrEqualEvaluator();
private LongGreaterOrEqualEvaluator() {
- super( ValueType.LONG_TYPE,
+ super( ValueType.PLONG_TYPE,
Operator.GREATER_OR_EQUAL );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/ShortFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/ShortFactory.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/ShortFactory.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -68,7 +68,7 @@
private static final Evaluator INSTANCE = new ShortEqualEvaluator();
private ShortEqualEvaluator() {
- super( ValueType.SHORT_TYPE,
+ super( ValueType.PSHORT_TYPE,
Operator.EQUAL );
}
@@ -108,7 +108,7 @@
private static final Evaluator INSTANCE = new ShortNotEqualEvaluator();
private ShortNotEqualEvaluator() {
- super( ValueType.SHORT_TYPE,
+ super( ValueType.PSHORT_TYPE,
Operator.NOT_EQUAL );
}
@@ -148,7 +148,7 @@
private static final Evaluator INSTANCE = new ShortLessEvaluator();
private ShortLessEvaluator() {
- super( ValueType.SHORT_TYPE,
+ super( ValueType.PSHORT_TYPE,
Operator.LESS );
}
@@ -188,7 +188,7 @@
private static final Evaluator INSTANCE = new ShortLessOrEqualEvaluator();
private ShortLessOrEqualEvaluator() {
- super( ValueType.SHORT_TYPE,
+ super( ValueType.PSHORT_TYPE,
Operator.LESS_OR_EQUAL );
}
@@ -228,7 +228,7 @@
private static final Evaluator INSTANCE = new ShortGreaterEvaluator();
private ShortGreaterEvaluator() {
- super( ValueType.SHORT_TYPE,
+ super( ValueType.PSHORT_TYPE,
Operator.GREATER );
}
@@ -268,7 +268,7 @@
private static final Evaluator INSTANCE = new ShortGreaterOrEqualEvaluator();
private ShortGreaterOrEqualEvaluator() {
- super( ValueType.SHORT_TYPE,
+ super( ValueType.PSHORT_TYPE,
Operator.GREATER_OR_EQUAL );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -160,7 +160,7 @@
}
// A ReteTuple is only the same if it has the same hashCode, factId and parent
- if ( this.hashCode != other.hashCode ) {
+ if (( other == null ) || ( this.hashCode != other.hashCode )) {
return false;
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseFactoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseFactoryTest.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseFactoryTest.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -41,21 +41,4 @@
assertNotNull( ((InternalRuleBase) rb2).getId() );
}
- public void testLeaps() {
- final RuleBase rb = RuleBaseFactory.newRuleBase( RuleBase.LEAPS );
- assertTrue( rb instanceof org.drools.leaps.LeapsRuleBase );
- assertTrue( !"default".equals( ((InternalRuleBase) rb).getId() ) );
- assertTrue( !"".equals( ((InternalRuleBase) rb).getId() ) );
- assertNotNull( ((InternalRuleBase) rb).getId() );
-
- final RuleBase rb2 = RuleBaseFactory.newRuleBase( RuleBase.LEAPS );
- assertTrue( rb2 instanceof org.drools.leaps.LeapsRuleBase );
- assertNotSame( rb2,
- rb );
-
- assertTrue( !"default".equals( ((InternalRuleBase) rb2).getId() ) );
- assertTrue( !"".equals( ((InternalRuleBase) rb2).getId() ) );
- assertNotNull( ((InternalRuleBase) rb2).getId() );
- }
-
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/ClassFieldExtractorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/ClassFieldExtractorTest.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/ClassFieldExtractorTest.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -88,7 +88,7 @@
final ClassFieldExtractor ext = new ClassFieldExtractor( InterfaceChild.class,
"foo" );
assertEquals( 42,
- ((Integer) ext.getValue( obj )).intValue() );
+ ((Number) ext.getValue( obj )).intValue() );
}
public void testLong() throws Exception {
@@ -96,7 +96,7 @@
"longField" );
final TestBean bean = new TestBean();
assertEquals( 424242,
- ((Long) ext.getValue( bean )).longValue() );
+ ((Number) ext.getValue( bean )).longValue() );
}
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/EvaluatorFactoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/EvaluatorFactoryTest.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/EvaluatorFactoryTest.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
@@ -27,6 +28,7 @@
import org.drools.base.evaluators.Operator;
import org.drools.spi.Evaluator;
+import org.drools.spi.Extractor;
/**
* Some test coverage goodness for the evaluators.
@@ -79,11 +81,10 @@
final Object[][] data = {{new Integer( 42 ), "==", new Integer( 42 ), Boolean.TRUE}, {new Integer( 42 ), "<", new Integer( 43 ), Boolean.TRUE}, {new Integer( 42 ), ">=", new Integer( 41 ), Boolean.TRUE},
{new Integer( 42 ), "!=", new Integer( 41 ), Boolean.TRUE}, {new Integer( 42 ), ">", new Integer( 41 ), Boolean.TRUE}, {new Integer( 42 ), "<=", new Integer( 42 ), Boolean.TRUE},
- {new Integer( 42 ), ">", new Integer( 100 ), Boolean.FALSE}, {new Integer( 42 ), "==", null, Boolean.FALSE}, {new Integer( 42 ), "!=", null, Boolean.TRUE}, {null, "==", null, Boolean.TRUE},
- {null, "==", new Integer( 42 ), Boolean.FALSE}, {null, "!=", null, Boolean.FALSE}, {null, "!=", new Integer( 42 ), Boolean.TRUE}};
+ {new Integer( 42 ), ">", new Integer( 100 ), Boolean.FALSE} };
runEvaluatorTest( data,
- ValueType.INTEGER_TYPE );
+ ValueType.PINTEGER_TYPE );
}
@@ -123,64 +124,55 @@
//Test data: Obj1, Operand, Obj2
final Object[][] data = {{new Short( (short) 42 ), "==", new Short( (short) 42 ), Boolean.TRUE}, {new Short( (short) 42 ), "<", new Short( (short) 43 ), Boolean.TRUE}, {new Short( (short) 42 ), ">=", new Short( (short) 41 ), Boolean.TRUE},
- {new Short( (short) 42 ), "!=", new Short( (short) 41 ), Boolean.TRUE}, {new Short( (short) 42 ), "!=", null, Boolean.TRUE}, {null, "==", null, Boolean.TRUE}, {null, "==", new Short( (short) 42 ), Boolean.FALSE},
- {null, "!=", null, Boolean.FALSE}, {null, "!=", new Short( (short) 42 ), Boolean.TRUE}};
+ {new Short( (short) 42 ), "!=", new Short( (short) 41 ), Boolean.TRUE}};
runEvaluatorTest( data,
- ValueType.SHORT_TYPE );
+ ValueType.PSHORT_TYPE );
}
public void testBoolean() {
//Test data: Obj1, Operand, Obj2
final Object[][] data = {{new Boolean( true ), "==", new Boolean( true ), Boolean.TRUE}, {new Boolean( false ), "!=", new Boolean( true ), Boolean.TRUE}, {new Boolean( true ), "==", new Boolean( false ), Boolean.FALSE},
- {new Boolean( true ), "!=", new Boolean( false ), Boolean.TRUE}, {new Boolean( true ), "==", null, Boolean.FALSE}, {new Boolean( true ), "!=", null, Boolean.TRUE}, {null, "==", new Boolean( true ), Boolean.FALSE},
- {null, "!=", new Boolean( true ), Boolean.TRUE}, {null, "==", null, Boolean.TRUE}
+ {new Boolean( true ), "!=", new Boolean( false ), Boolean.TRUE}};
- };
-
runEvaluatorTest( data,
- ValueType.BOOLEAN_TYPE );
+ ValueType.PBOOLEAN_TYPE );
}
public void testDouble() {
final Object[][] data = {{new Double( 42 ), "==", new Double( 42 ), Boolean.TRUE}, {new Double( 42 ), "<", new Double( 43 ), Boolean.TRUE}, {new Double( 42 ), ">=", new Double( 41 ), Boolean.TRUE},
{new Double( 42 ), "!=", new Double( 41 ), Boolean.TRUE}, {new Double( 42 ), ">", new Double( 41 ), Boolean.TRUE}, {new Double( 42 ), ">=", new Double( 41 ), Boolean.TRUE}, {new Double( 42 ), ">=", new Double( 42 ), Boolean.TRUE},
- {new Double( 42 ), ">=", new Double( 100 ), Boolean.FALSE}, {new Double( 42 ), "<", new Double( 1 ), Boolean.FALSE}, {new Double( 42 ), "==", null, Boolean.FALSE}, {new Double( 42 ), "!=", null, Boolean.TRUE},
- {null, "==", null, Boolean.TRUE}, {null, "==", new Double( 42 ), Boolean.FALSE}, {null, "!=", null, Boolean.FALSE}, {null, "!=", new Double( 42 ), Boolean.TRUE}};
+ {new Double( 42 ), ">=", new Double( 100 ), Boolean.FALSE}, {new Double( 42 ), "<", new Double( 1 ), Boolean.FALSE}};
runEvaluatorTest( data,
- ValueType.DOUBLE_TYPE );
+ ValueType.PDOUBLE_TYPE );
}
public void testFloat() {
final Object[][] data = {{new Float( 42 ), "==", new Float( 42 ), Boolean.TRUE}, {new Float( 42 ), "<", new Float( 43 ), Boolean.TRUE}, {new Float( 42 ), ">=", new Float( 41 ), Boolean.TRUE},
{new Float( 42 ), "!=", new Float( 41 ), Boolean.TRUE}, {new Float( 42 ), ">", new Float( 41 ), Boolean.TRUE}, {new Float( 42 ), ">=", new Float( 41 ), Boolean.TRUE}, {new Float( 42 ), ">=", new Float( 42 ), Boolean.TRUE},
- {new Float( 42 ), ">=", new Float( 100 ), Boolean.FALSE}, {new Float( 42 ), "<", new Float( 1 ), Boolean.FALSE}, {new Float( 42 ), "==", null, Boolean.FALSE}, {new Float( 42 ), "!=", null, Boolean.TRUE},
- {null, "==", null, Boolean.TRUE}, {null, "==", new Float( 42 ), Boolean.FALSE}, {null, "!=", null, Boolean.FALSE}, {null, "!=", new Float( 42 ), Boolean.TRUE}};
+ {new Float( 42 ), ">=", new Float( 100 ), Boolean.FALSE}, {new Float( 42 ), "<", new Float( 1 ), Boolean.FALSE}};
runEvaluatorTest( data,
- ValueType.FLOAT_TYPE );
+ ValueType.PFLOAT_TYPE );
}
public void testLong() {
final Object[][] data = {{new Long( 42 ), "==", new Long( 42 ), Boolean.TRUE}, {new Long( 42 ), "<", new Long( 43 ), Boolean.TRUE}, {new Long( 42 ), ">=", new Long( 41 ), Boolean.TRUE}, {new Long( 42 ), "!=", new Long( 41 ), Boolean.TRUE},
{new Long( 42 ), ">", new Long( 41 ), Boolean.TRUE}, {new Long( 42 ), ">=", new Long( 41 ), Boolean.TRUE}, {new Long( 42 ), ">=", new Long( 42 ), Boolean.TRUE}, {new Long( 42 ), ">=", new Long( 100 ), Boolean.FALSE},
- {new Long( 42 ), "<", new Long( 1 ), Boolean.FALSE}, {new Long( 42 ), "==", null, Boolean.FALSE}, {new Long( 42 ), "!=", null, Boolean.TRUE}, {null, "==", null, Boolean.TRUE}, {null, "==", new Long( 42 ), Boolean.FALSE},
- {null, "!=", null, Boolean.FALSE}, {null, "!=", new Long( 42 ), Boolean.TRUE}};
+ {new Long( 42 ), "<", new Long( 1 ), Boolean.FALSE}};
runEvaluatorTest( data,
- ValueType.LONG_TYPE );
+ ValueType.PLONG_TYPE );
}
public void testCharacter() {
final Object[][] data = {{new Character( 'a' ), "==", new Character( 'a' ), Boolean.TRUE}, {new Character( 'a' ), "<", new Character( 'b' ), Boolean.TRUE}, {new Character( 'a' ), ">=", new Character( 'a' ), Boolean.TRUE},
{new Character( 'a' ), "!=", new Character( 'Z' ), Boolean.TRUE}, {new Character( 'z' ), ">", new Character( 'a' ), Boolean.TRUE}, {new Character( 'z' ), ">=", new Character( 'z' ), Boolean.TRUE},
- {new Character( 'z' ), ">=", new Character( 'a' ), Boolean.TRUE}, {new Character( 'a' ), ">=", new Character( 'z' ), Boolean.FALSE}, {new Character( 'z' ), "<", new Character( 'a' ), Boolean.FALSE},
- {new Character( 'z' ), "==", null, Boolean.FALSE}, {new Character( 'z' ), "!=", null, Boolean.TRUE}, {null, "==", null, Boolean.TRUE}, {null, "==", new Character( 'z' ), Boolean.FALSE}, {null, "!=", null, Boolean.FALSE},
- {null, "!=", new Character( 'z' ), Boolean.TRUE}};
+ {new Character( 'z' ), ">=", new Character( 'a' ), Boolean.TRUE}, {new Character( 'a' ), ">=", new Character( 'z' ), Boolean.FALSE}, {new Character( 'z' ), "<", new Character( 'a' ), Boolean.FALSE}};
runEvaluatorTest( data,
- ValueType.CHAR_TYPE );
+ ValueType.PCHAR_TYPE );
}
public void testDate() throws Exception {
@@ -192,9 +184,8 @@
final Object[][] data = {{df.parse( "10-Jul-1974" ), "==", df.parse( "10-Jul-1974" ), Boolean.TRUE}, {df.parse( "10-Jul-1974" ), "<", df.parse( "11-Jul-1974" ), Boolean.TRUE},
{df.parse( "10-Jul-1974" ), ">=", df.parse( "10-Jul-1974" ), Boolean.TRUE}, {df.parse( "10-Jul-1974" ), "!=", df.parse( "11-Jul-1974" ), Boolean.TRUE}, {df.parse( "10-Jul-2000" ), ">", df.parse( "10-Jul-1974" ), Boolean.TRUE},
{df.parse( "10-Jul-1974" ), ">=", df.parse( "10-Jul-1974" ), Boolean.TRUE}, {df.parse( "11-Jul-1974" ), ">=", df.parse( "10-Jul-1974" ), Boolean.TRUE}, {df.parse( "10-Jul-1974" ), ">=", df.parse( "11-Jul-1974" ), Boolean.FALSE},
- {df.parse( "10-Jul-2000" ), "<", df.parse( "10-Jul-1974" ), Boolean.FALSE}, {df.parse( "10-Jul-1974" ), "<", "11-Jul-1974", Boolean.TRUE}, {df.parse( "10-Jul-1974" ), ">=", "10-Jul-1974", Boolean.TRUE},
- {df.parse( "10-Jul-1974" ), "!=", "11-Jul-1974", Boolean.TRUE}, {df.parse( "10-Jul-2000" ), ">", "10-Jul-1974", Boolean.TRUE}, {df.parse( "10-Jul-1974" ), ">=", "10-Jul-1974", Boolean.TRUE},
- {df.parse( "11-Jul-1974" ), ">=", "10-Jul-1974", Boolean.TRUE}, {df.parse( "10-Jul-1974" ), ">=", "11-Jul-1974", Boolean.FALSE}, {df.parse( "10-Jul-1974" ), "==", null, Boolean.FALSE},
+ {df.parse( "10-Jul-2000" ), "<", df.parse( "10-Jul-1974" ), Boolean.FALSE}, {df.parse( "10-Jul-1974" ), "<", df.parse("11-Jul-1974"), Boolean.TRUE},
+ {df.parse( "10-Jul-1974" ), "==", null, Boolean.FALSE},
{df.parse( "10-Jul-1974" ), "!=", null, Boolean.TRUE}, {null, "==", null, Boolean.TRUE}, {null, "==", df.parse( "10-Jul-1974" ), Boolean.FALSE}, {null, "!=", null, Boolean.FALSE}, {null, "!=", df.parse( "10-Jul-1974" ), Boolean.TRUE}};
runEvaluatorTest( data,
ValueType.DATE_TYPE );
@@ -202,10 +193,9 @@
public void testByte() {
final Object[][] data = {{new Byte( "1" ), "==", new Byte( "1" ), Boolean.TRUE}, {new Byte( "1" ), "==", new Byte( "2" ), Boolean.FALSE}, {new Byte( "1" ), "!=", new Byte( "2" ), Boolean.TRUE},
- {new Byte( "1" ), "!=", new Byte( "1" ), Boolean.FALSE}, {new Byte( "1" ), "<=", new Byte( "1" ), Boolean.TRUE}, {new Byte( "1" ), "==", null, Boolean.FALSE}, {new Byte( "1" ), "!=", null, Boolean.TRUE},
- {null, "==", null, Boolean.TRUE}, {null, "==", new Byte( "1" ), Boolean.FALSE}, {null, "!=", null, Boolean.FALSE}, {null, "!=", new Byte( "1" ), Boolean.TRUE}};
+ {new Byte( "1" ), "!=", new Byte( "1" ), Boolean.FALSE}, {new Byte( "1" ), "<=", new Byte( "1" ), Boolean.TRUE}};
runEvaluatorTest( data,
- ValueType.BYTE_TYPE );
+ ValueType.PBYTE_TYPE );
}
@@ -216,10 +206,13 @@
*/
private void runEvaluatorTest(final Object[][] data,
final ValueType valueType) {
+ Extractor extractor = new MockExtractor();
for ( int i = 0; i < data.length; i++ ) {
final Object[] row = data[i];
final Evaluator evaluator = valueType.getEvaluator( Operator.determineOperator( (String) row[1] ) );
- final boolean result = evaluator.evaluate( row[0],
+ final boolean result = evaluator.evaluate( extractor,
+ row[0],
+ extractor,
row[2] );
final String message = "The evaluator type: [" + valueType + "] incorrectly returned " + result + " for [" + row[0] + " " + row[1] + " " + row[2] + "]. It was asserted to return " + row[3];
@@ -236,7 +229,64 @@
}
}
+
+ private static class MockExtractor implements Extractor {
+ public boolean getBooleanValue(Object object) {
+ return ((Boolean)object).booleanValue();
+ }
+
+ public byte getByteValue(Object object) {
+ return ((Number)object).byteValue();
+ }
+
+ public char getCharValue(Object object) {
+ return ((Character)object).charValue();
+ }
+
+ public double getDoubleValue(Object object) {
+ return ((Number)object).doubleValue();
+ }
+
+ public Class getExtractToClass() {
+ return null;
+ }
+
+ public float getFloatValue(Object object) {
+ return ((Number)object).floatValue();
+ }
+
+ public int getHashCode(Object object) {
+ return 0;
+ }
+
+ public int getIntValue(Object object) {
+ return ((Number)object).intValue();
+ }
+
+ public long getLongValue(Object object) {
+ return ((Number)object).longValue();
+ }
+
+ public Method getNativeReadMethod() {
+ return null;
+ }
+
+ public short getShortValue(Object object) {
+ return ((Number)object).shortValue();
+ }
+
+ public Object getValue(Object object) {
+ return object;
+ }
+
+ public ValueType getValueType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ }
+
// public void testRegexFoo() {
// Pattern p = Pattern.compile( ".*foo" );
// boolean b;
Deleted: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/FieldImplTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/FieldImplTest.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/FieldImplTest.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -1,78 +0,0 @@
-package org.drools.base;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-public class FieldImplTest extends TestCase {
- FieldImpl field1;
- FieldImpl field2;
- FieldImpl field3;
- FieldImpl field4;
- FieldImpl field5;
-
- protected void setUp() throws Exception {
- super.setUp();
- this.field1 = new FieldImpl( null );
- this.field2 = new FieldImpl( null );
- this.field3 = new FieldImpl( "A" );
- this.field4 = new FieldImpl( "A" );
- this.field5 = new FieldImpl( "B" );
-
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- Assert.assertEquals( this.field1,
- this.field1 );
- Assert.assertEquals( this.field1,
- this.field2 );
- Assert.assertEquals( this.field3,
- this.field3 );
- Assert.assertEquals( this.field3,
- this.field4 );
- Assert.assertFalse( this.field1.equals( this.field3 ) );
- Assert.assertFalse( this.field3.equals( this.field1 ) );
- Assert.assertFalse( this.field3.equals( this.field5 ) );
- }
-
- /*
- * Test method for 'org.drools.base.FieldImpl.hashCode()'
- */
- public void testHashCode() {
- Assert.assertEquals( this.field1.hashCode(),
- this.field1.hashCode() );
- Assert.assertEquals( this.field1.hashCode(),
- this.field2.hashCode() );
- Assert.assertEquals( this.field3.hashCode(),
- this.field3.hashCode() );
- Assert.assertEquals( this.field3.hashCode(),
- this.field4.hashCode() );
- Assert.assertFalse( this.field1.hashCode() == this.field3.hashCode() );
- Assert.assertFalse( this.field3.hashCode() == this.field1.hashCode() );
- Assert.assertFalse( this.field3.hashCode() == this.field5.hashCode() );
- }
-
- /*
- * Test method for 'org.drools.base.FieldImpl.equals(Object)'
- */
- public void testEqualsObject() {
-
- }
-
-}
\ No newline at end of file
Copied: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/FieldValueTest.java (from rev 7250, labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/FieldImplTest.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/FieldImplTest.java 2006-10-31 20:24:23 UTC (rev 7250)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/FieldValueTest.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -0,0 +1,79 @@
+package org.drools.base;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.spi.FieldValue;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+public class FieldValueTest extends TestCase {
+ FieldValue field1;
+ FieldValue field2;
+ FieldValue field3;
+ FieldValue field4;
+ FieldValue field5;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.field1 = FieldFactory.getFieldValue( null );
+ this.field2 = FieldFactory.getFieldValue( null );
+ this.field3 = FieldFactory.getFieldValue( "A" );
+ this.field4 = FieldFactory.getFieldValue( "A" );
+ this.field5 = FieldFactory.getFieldValue( "B" );
+
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /*
+ * Test method for 'org.drools.base.FieldValue.hashCode()'
+ */
+ public void testHashCode() {
+ Assert.assertEquals( this.field1.hashCode(),
+ this.field1.hashCode() );
+ Assert.assertEquals( this.field1.hashCode(),
+ this.field2.hashCode() );
+ Assert.assertEquals( this.field3.hashCode(),
+ this.field3.hashCode() );
+ Assert.assertEquals( this.field3.hashCode(),
+ this.field4.hashCode() );
+ Assert.assertFalse( this.field1.hashCode() == this.field3.hashCode() );
+ Assert.assertFalse( this.field3.hashCode() == this.field1.hashCode() );
+ Assert.assertFalse( this.field3.hashCode() == this.field5.hashCode() );
+ }
+
+ /*
+ * Test method for 'org.drools.base.FieldValue.equals(Object)'
+ */
+ public void testEqualsObject() {
+ Assert.assertEquals( this.field1,
+ this.field1 );
+ Assert.assertEquals( this.field1,
+ this.field2 );
+ Assert.assertEquals( this.field3,
+ this.field3 );
+ Assert.assertEquals( this.field3,
+ this.field4 );
+ Assert.assertFalse( this.field1.equals( this.field3 ) );
+ Assert.assertFalse( this.field3.equals( this.field1 ) );
+ Assert.assertFalse( this.field3.equals( this.field5 ) );
+ }
+
+}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ByteClassFieldExtractorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ByteClassFieldExtractorTest.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ByteClassFieldExtractorTest.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -91,9 +91,8 @@
public void testGetValue() {
try {
- Assert.assertEquals( new Byte( (byte) 1 ),
- this.extractor.getValue( this.bean ) );
- Assert.assertTrue( this.extractor.getValue( this.bean ) instanceof Byte );
+ Assert.assertEquals( 1 ,
+ ((Number) this.extractor.getValue( this.bean )).byteValue() );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/CharClassFieldExtractorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/CharClassFieldExtractorTest.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/CharClassFieldExtractorTest.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -26,10 +26,10 @@
public void testGetByteValue() {
try {
- this.extractor.getByteValue( this.bean );
- fail( "Should have throw an exception" );
+ Assert.assertEquals( 'a',
+ this.extractor.getByteValue( this.bean ) );
} catch ( final Exception e ) {
- // success
+ fail( "Should not throw exception" );
}
}
@@ -44,54 +44,53 @@
public void testGetDoubleValue() {
try {
- this.extractor.getDoubleValue( this.bean );
- fail( "Should have throw an exception" );
+ Assert.assertEquals( 'a',
+ (int) this.extractor.getDoubleValue( this.bean ) );
} catch ( final Exception e ) {
- // success
+ fail( "Should not throw exception" );
}
}
public void testGetFloatValue() {
try {
- this.extractor.getFloatValue( this.bean );
- fail( "Should have throw an exception" );
+ Assert.assertEquals( 'a',
+ (int) this.extractor.getFloatValue( this.bean ) );
} catch ( final Exception e ) {
- // success
+ fail( "Should not throw exception" );
}
}
public void testGetIntValue() {
try {
- this.extractor.getIntValue( this.bean );
- fail( "Should have throw an exception" );
+ Assert.assertEquals( 'a',
+ (int) this.extractor.getIntValue( this.bean ) );
} catch ( final Exception e ) {
- // success
+ fail( "Should not throw exception" );
}
}
public void testGetLongValue() {
try {
- this.extractor.getLongValue( this.bean );
- fail( "Should have throw an exception" );
+ Assert.assertEquals( 'a',
+ (int) this.extractor.getLongValue( this.bean ) );
} catch ( final Exception e ) {
- // success
+ fail( "Should not throw exception" );
}
}
public void testGetShortValue() {
try {
- this.extractor.getShortValue( this.bean );
- fail( "Should have throw an exception" );
+ Assert.assertEquals( 'a',
+ this.extractor.getShortValue( this.bean ) );
} catch ( final Exception e ) {
- // success
+ fail( "Should not throw exception" );
}
}
public void testGetValue() {
try {
- Assert.assertEquals( new Character( 'a' ),
- this.extractor.getValue( this.bean ) );
- Assert.assertTrue( this.extractor.getValue( this.bean ) instanceof Character );
+ Assert.assertEquals( 'a',
+ ((Number)this.extractor.getValue( this.bean )).intValue() );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/IntClassFieldExtractorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/IntClassFieldExtractorTest.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/IntClassFieldExtractorTest.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -93,9 +93,8 @@
public void testGetValue() {
try {
- Assert.assertEquals( new Integer( IntClassFieldExtractorTest.VALUE ),
- this.extractor.getValue( this.bean ) );
- Assert.assertTrue( this.extractor.getValue( this.bean ) instanceof Integer );
+ Assert.assertEquals( IntClassFieldExtractorTest.VALUE,
+ ((Number)this.extractor.getValue( this.bean )).intValue() );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ShortClassFieldExtractorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ShortClassFieldExtractorTest.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ShortClassFieldExtractorTest.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -93,9 +93,8 @@
public void testGetValue() {
try {
- Assert.assertEquals( new Short( ShortClassFieldExtractorTest.VALUE ),
- this.extractor.getValue( this.bean ) );
- Assert.assertTrue( this.extractor.getValue( this.bean ) instanceof Short );
+ Assert.assertEquals( ShortClassFieldExtractorTest.VALUE,
+ ((Number)this.extractor.getValue( this.bean )).shortValue() );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -43,7 +43,8 @@
// MockObjectSink so we can detect assertions and retractions
final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
new ClassObjectType( String.class ),
- rete );
+ rete,
+ 3 );
objectTypeNode.attach();
final MockObjectSink sink = new MockObjectSink();
objectTypeNode.addObjectSink( sink );
@@ -141,7 +142,8 @@
final Rete rete = new Rete();
final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 0,
new ClassObjectType( String.class ),
- rete );
+ rete,
+ 3 );
objectTypeNode.attach();
final MockObjectSink sink = new MockObjectSink();
objectTypeNode.addObjectSink( sink );
@@ -205,7 +207,7 @@
// If assert behavior in working memory is IDENTITY,
// returned handles must not be the same
- if ( RuleBaseConfiguration.WM_BEHAVIOR_IDENTITY.equals( ((ReteooRuleBase) ruleBase).getConfiguration().getProperty( RuleBaseConfiguration.PROPERTY_ASSERT_BEHAVIOR ) ) ) {
+ if ( RuleBaseConfiguration.AssertBehaviour.IDENTITY == ((ReteooRuleBase) ruleBase).getConfiguration().getAssertBehaviour() ) {
assertNotSame( logicalHandle1,
logicalHandle2 );
@@ -228,7 +230,8 @@
final Rete rete = new Rete();
final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 0,
new ClassObjectType( String.class ),
- rete );
+ rete,
+ 3 );
objectTypeNode.attach();
final MockObjectSink sink = new MockObjectSink();
objectTypeNode.addObjectSink( sink );
@@ -360,7 +363,8 @@
final Rete rete = new Rete();
final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 0,
new ClassObjectType( String.class ),
- rete );
+ rete,
+ 3 );
objectTypeNode.attach();
final MockObjectSink sink = new MockObjectSink();
objectTypeNode.addObjectSink( sink );
@@ -368,8 +372,7 @@
new MockTupleSource( 2 ),
rule1 );
final RuleBaseConfiguration conf = new RuleBaseConfiguration();
- conf.setProperty( RuleBaseConfiguration.PROPERTY_LOGICAL_OVERRIDE_BEHAVIOR,
- RuleBaseConfiguration.WM_BEHAVIOR_PRESERVE );
+ conf.setLogicalOverride( RuleBaseConfiguration.LogicalOverride.PRESERVE );
final RuleBase ruleBase = new ReteooRuleBase( conf );
final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
@@ -449,7 +452,8 @@
final Rete rete = new Rete();
final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 0,
new ClassObjectType( String.class ),
- rete );
+ rete,
+ 3 );
objectTypeNode.attach();
final MockObjectSink sink = new MockObjectSink();
objectTypeNode.addObjectSink( sink );
@@ -544,7 +548,8 @@
// MockObjectSink so we can detect assertions and retractions
final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
new ClassObjectType( String.class ),
- rete );
+ rete,
+ 3 );
objectTypeNode.attach();
final MockObjectSink sink = new MockObjectSink();
objectTypeNode.addObjectSink( sink );
@@ -668,7 +673,8 @@
final Rete rete = new Rete();
final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 0,
new ClassObjectType( String.class ),
- rete );
+ rete,
+ 3 );
objectTypeNode.attach();
final MockObjectSink sink = new MockObjectSink();
objectTypeNode.addObjectSink( sink );
@@ -727,7 +733,7 @@
// If assert behavior in working memory is IDENTITY,
// we need to retract object 2 times before being able to
// succesfully logically assert a new fact
- if ( RuleBaseConfiguration.WM_BEHAVIOR_IDENTITY.equals( ((ReteooRuleBase) ruleBase).getConfiguration().getProperty( RuleBaseConfiguration.PROPERTY_ASSERT_BEHAVIOR ) ) ) {
+ if ( RuleBaseConfiguration.AssertBehaviour.IDENTITY == ((ReteooRuleBase) ruleBase).getConfiguration().getAssertBehaviour() ) {
workingMemory.retractObject( statedHandle2 );
@@ -765,7 +771,8 @@
final Rete rete = new Rete();
final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 0,
new ClassObjectType( String.class ),
- rete );
+ rete,
+ 3);
objectTypeNode.attach();
final MockObjectSink sink = new MockObjectSink();
objectTypeNode.addObjectSink( sink );
Deleted: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/OrTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/OrTest.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/OrTest.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -1,363 +0,0 @@
-package org.drools.rule;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-
-import junit.framework.TestCase;
-
-import org.drools.RuleBase;
-import org.drools.RuleBaseFactory;
-import org.drools.WorkingMemory;
-import org.drools.base.ClassFieldExtractor;
-import org.drools.base.ClassObjectType;
-import org.drools.base.FieldFactory;
-import org.drools.base.ValueType;
-import org.drools.base.evaluators.Operator;
-import org.drools.examples.waltz.Edge;
-import org.drools.examples.waltz.Stage;
-import org.drools.spi.AlphaNodeFieldConstraint;
-import org.drools.spi.BetaNodeFieldConstraint;
-import org.drools.spi.Consequence;
-import org.drools.spi.ConsequenceException;
-import org.drools.spi.Evaluator;
-import org.drools.spi.FieldExtractor;
-import org.drools.spi.FieldValue;
-import org.drools.spi.KnowledgeHelper;
-import org.drools.spi.Tuple;
-
-/**
- * This test demonstrate the following failures:
- * 1. Or constraint to produce matches when Or constraint is specified at the beging.
- * I suspect it has something to do with regular columns having higher indexes
- *
- * 2. Resolve an object that has Or condition defined for it in consequence
- *
- *
- * @author Alexander Bagerman
- *
- */
-public class OrTest extends TestCase {
-
- private Evaluator integerEqualEvaluator;
- private Evaluator integerNotEqualEvaluator;
-
- private ClassObjectType stageType;
-
- private ClassObjectType edgeType;
-
- protected Package pkg;
-
- private Stage markStage;
-
- protected void setUp() throws Exception {
- super.setUp();
- this.stageType = new ClassObjectType( Stage.class );
- this.edgeType = new ClassObjectType( Edge.class );
- this.integerEqualEvaluator = ValueType.PINTEGER_TYPE.getEvaluator( Operator.EQUAL );
- this.integerNotEqualEvaluator = ValueType.PINTEGER_TYPE.getEvaluator( Operator.NOT_EQUAL );
- this.pkg = new Package( "or" );
- }
-
- /*
- */
- public void testReteooNeverGetsToConsequenceOrder() throws Exception {
-
- this.pkg.addRule( this.getNeverGetsToConsequenceRule() );
-
- final RuleBase ruleBase = RuleBaseFactory.newRuleBase( RuleBase.RETEOO );
- ruleBase.addPackage( this.pkg );
- final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
- workingMemory.assertObject( new Stage( Stage.LABELING ) );
- workingMemory.assertObject( new Edge( 1000,
- 1,
- false,
- Edge.NIL,
- Edge.NIL ) );
- workingMemory.assertObject( new Edge( 1000,
- 2,
- false,
- Edge.NIL,
- Edge.NIL ) );
- workingMemory.assertObject( new Edge( 5555,
- 3,
- false,
- Edge.NIL,
- Edge.NIL ) );
- workingMemory.fireAllRules();
- workingMemory.assertObject( new Stage( Stage.DETECT_JUNCTIONS ) );
-
- workingMemory.fireAllRules();
- }
-
- /*
- */
- public void testReteooWorkingButCanNotResolveOrObjectInConsequenceOrder() throws Exception {
-
- this.pkg.addRule( this.getWorkingButCanNotResolveOrObjectInConsequenceOrder() );
-
- final RuleBase ruleBase = RuleBaseFactory.newRuleBase( RuleBase.RETEOO );
- ruleBase.addPackage( this.pkg );
- final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
- workingMemory.assertObject( new Stage( Stage.LABELING ) );
- workingMemory.assertObject( new Edge( 1000,
- 1,
- false,
- Edge.NIL,
- Edge.NIL ) );
- workingMemory.assertObject( new Edge( 1000,
- 2,
- false,
- Edge.NIL,
- Edge.NIL ) );
- workingMemory.assertObject( new Edge( 5555,
- 3,
- false,
- Edge.NIL,
- Edge.NIL ) );
- workingMemory.fireAllRules();
- workingMemory.assertObject( new Stage( Stage.DETECT_JUNCTIONS ) );
-
- workingMemory.fireAllRules();
- }
-
- /*
- * Test method for
- * 'org.drools.leaps.ColumnConstraints.evaluateAlphas(FactHandleImpl, Token,
- * WorkingMemoryImpl)'
- */
- public Rule getNeverGetsToConsequenceRule() throws Exception {
- final Rule rule = new Rule( "NeverGetsToConsequence" );
-
- final Column stageColumn1 = new Column( 0,
- this.stageType,
- "stage" );
- stageColumn1.addConstraint( getLiteralConstraint( stageColumn1,
- "value",
- new Integer( Stage.DETECT_JUNCTIONS ),
- this.integerEqualEvaluator ) );
-
- final Column stageColumn2 = new Column( 0,
- this.stageType,
- "stage" );
- stageColumn2.addConstraint( getLiteralConstraint( stageColumn2,
- "value",
- new Integer( Stage.LABELING ),
- this.integerEqualEvaluator ) );
- final Or or = new Or();
- or.addChild( stageColumn1 );
- or.addChild( stageColumn2 );
- rule.addPattern( or );
- final Declaration stageDeclaration = rule.getDeclaration( "stage" );
-
- final Column edgeColumn1 = new Column( 1,
- this.edgeType,
- "edge1" );
- setFieldDeclaration( edgeColumn1,
- "p1",
- "edge1p1" );
- setFieldDeclaration( edgeColumn1,
- "p2",
- "edge1p2" );
- rule.addPattern( edgeColumn1 );
- final Declaration edge1Declaration = rule.getDeclaration( "edge1" );
- final Declaration edge1P1Declaration = rule.getDeclaration( "edge1p1" );
- final Declaration edge1P2Declaration = rule.getDeclaration( "edge1p2" );
-
- final Column edgeColumn2 = new Column( 2,
- this.edgeType,
- "edge2" );
- rule.addPattern( edgeColumn2 );
- final Declaration edge2Declaration = rule.getDeclaration( "edge2" );
- edgeColumn2.addConstraint( getBoundVariableConstraint( edgeColumn2,
- "p1",
- edge1P1Declaration,
- this.integerEqualEvaluator ) );
- edgeColumn2.addConstraint( getBoundVariableConstraint( edgeColumn2,
- "p2",
- edge1P2Declaration,
- this.integerNotEqualEvaluator ) );
-
- final Consequence consequence = new Consequence() {
- /**
- *
- */
- private static final long serialVersionUID = -9201168516267126280L;
-
- public void evaluate(KnowledgeHelper drools,
- WorkingMemory workingMemory) throws ConsequenceException {
- try {
- Rule rule = drools.getRule();
- Tuple tuple = drools.getTuple();
-
- Stage stage = (Stage) drools.get( stageDeclaration );
-
- OrTest.this.markStage = stage;
- } catch ( Exception e ) {
- e.printStackTrace();
- throw new ConsequenceException( e );
- }
- }
-
- };
- rule.setConsequence( consequence );
-
- return rule;
- }
-
- /*
- * Test method for
- * 'org.drools.leaps.ColumnConstraints.evaluateAlphas(FactHandleImpl, Token,
- * WorkingMemoryImpl)'
- */
- public Rule getWorkingButCanNotResolveOrObjectInConsequenceOrder() throws Exception {
- final Rule rule = new Rule( "WorkingButCanNotResolveOrObjectInConsequence" );
-
- final Column edgeColumn1 = new Column( 0,
- this.edgeType,
- "edge1" );
- setFieldDeclaration( edgeColumn1,
- "p1",
- "edge1p1" );
- setFieldDeclaration( edgeColumn1,
- "p2",
- "edge1p2" );
- rule.addPattern( edgeColumn1 );
- final Declaration edge1Declaration = rule.getDeclaration( "edge1" );
- final Declaration edge1P1Declaration = rule.getDeclaration( "edge1p1" );
- final Declaration edge1P2Declaration = rule.getDeclaration( "edge1p2" );
-
- final Column edgeColumn2 = new Column( 1,
- this.edgeType,
- "edge2" );
- rule.addPattern( edgeColumn2 );
- final Declaration edge2Declaration = rule.getDeclaration( "edge2" );
- edgeColumn2.addConstraint( getBoundVariableConstraint( edgeColumn2,
- "p1",
- edge1P1Declaration,
- this.integerEqualEvaluator ) );
- edgeColumn2.addConstraint( getBoundVariableConstraint( edgeColumn2,
- "p2",
- edge1P2Declaration,
- this.integerNotEqualEvaluator ) );
-
- final Column stageColumn1 = new Column( 2,
- this.stageType,
- "stage1" );
- stageColumn1.addConstraint( getLiteralConstraint( stageColumn1,
- "value",
- new Integer( Stage.DETECT_JUNCTIONS ),
- this.integerEqualEvaluator ) );
-
- final Column stageColumn2 = new Column( 2,
- this.stageType,
- "stage" );
- stageColumn2.addConstraint( getLiteralConstraint( stageColumn2,
- "value",
- new Integer( Stage.LABELING ),
- this.integerEqualEvaluator ) );
- final Or or = new Or();
- or.addChild( stageColumn1 );
- or.addChild( stageColumn2 );
- rule.addPattern( or );
- final Declaration stageDeclaration = rule.getDeclaration( "stage" );
-
- final Consequence consequence = new Consequence() {
- /**
- *
- */
- private static final long serialVersionUID = -4956304333289545872L;
-
- public void evaluate(KnowledgeHelper drools,
- WorkingMemory workingMemory) throws ConsequenceException {
- try {
- Rule rule = drools.getRule();
- Tuple tuple = drools.getTuple();
-
- Stage stage = (Stage) drools.get( stageDeclaration );
- OrTest.this.markStage = stage;
- } catch ( Exception e ) {
- e.printStackTrace();
- throw new ConsequenceException( e );
- }
- }
-
- };
- rule.setConsequence( consequence );
-
- return rule;
- }
-
- private void setFieldDeclaration(final Column column,
- final String fieldName,
- final String identifier) throws IntrospectionException {
- final Class clazz = ((ClassObjectType) column.getObjectType()).getClassType();
-
- final FieldExtractor extractor = new ClassFieldExtractor( clazz,
- fieldName );
-
- column.addDeclaration( identifier,
- extractor );
- }
-
- private AlphaNodeFieldConstraint getLiteralConstraint(final Column column,
- final String fieldName,
- final Object fieldValue,
- final Evaluator evaluator) throws IntrospectionException {
- final Class clazz = ((ClassObjectType) column.getObjectType()).getClassType();
-
- final int index = getIndex( clazz,
- fieldName );
-
- final FieldValue field = FieldFactory.getFieldValue( fieldValue );
-
- final FieldExtractor extractor = new ClassFieldExtractor( clazz,
- fieldName );
-
- return new LiteralConstraint( extractor,
- evaluator,
- field );
- }
-
- private BetaNodeFieldConstraint getBoundVariableConstraint(final Column column,
- final String fieldName,
- final Declaration declaration,
- final Evaluator evaluator) throws IntrospectionException {
- final Class clazz = ((ClassObjectType) column.getObjectType()).getClassType();
-
- final FieldExtractor extractor = new ClassFieldExtractor( clazz,
- fieldName );
-
- return new VariableConstraint( extractor,
- declaration,
- evaluator );
- }
-
- public static int getIndex(final Class clazz,
- final String name) throws IntrospectionException {
- final PropertyDescriptor[] descriptors = Introspector.getBeanInfo( clazz ).getPropertyDescriptors();
- for ( int i = 0; i < descriptors.length; i++ ) {
- if ( descriptors[i].getName().equals( name ) ) {
- return i;
- }
- }
- return -1;
- }
-
-}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/BinaryHeapPriorityQueueTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/BinaryHeapPriorityQueueTest.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/BinaryHeapPriorityQueueTest.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -23,8 +23,6 @@
import junit.framework.TestCase;
-import org.apache.commons.collections.BinaryHeap;
-
public class BinaryHeapPriorityQueueTest extends TestCase {
public void testOptimised() {
final Random random = new Random();
@@ -61,11 +59,12 @@
System.out.println( "elapsedDequeue = " + elapsedDequeue );
}
- public void xxxtestBasic() {
+ public void testBasic() {
final Random random = new Random();
final List items = new LinkedList();
- final BinaryHeap queue = new BinaryHeap();
+ final BinaryHeapQueue queue = new BinaryHeapQueue(NaturalComparator.INSTANCE,
+ 100000 );
for ( int i = 0; i < 100000; ++i ) {
items.add( new LongQueueable( random.nextLong() ) );
@@ -74,7 +73,7 @@
final long startEnqueue = System.currentTimeMillis();
for ( final Iterator i = items.iterator(); i.hasNext(); ) {
- queue.add( i.next() );
+ queue.enqueue( (Queueable) i.next() );
}
final long elapsedEnqueue = System.currentTimeMillis() - startEnqueue;
@@ -82,7 +81,7 @@
final long startDequeue = System.currentTimeMillis();
for ( final Iterator i = items.iterator(); i.hasNext(); ) {
- queue.remove( i.next() );
+ queue.enqueue( (Queueable) i.next() );
}
// while (!queue.isEmpty()) {
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -11,160 +11,160 @@
public class FieldIndexEntryTest extends TestCase {
- public void testSingleEntry() {
- final ClassFieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
- "type" );
-
- final FieldIndexEntry index = new FieldIndexEntry( extractor,
- extractor.getIndex(),
- "stilton".hashCode() );
-
- // Test initial construction
- assertNull( index.getValue() );
- assertNull( index.getFirst() );
- assertEquals( "stilton".hashCode(),
- index.hashCode() );
-
- final Cheese stilton1 = new Cheese( "stilton",
- 35 );
- final InternalFactHandle h1 = new DefaultFactHandle( 1,
- stilton1 );
-
- // test add
- index.add( h1 );
- assertEquals( "stilton",
- index.getValue() );
- final FactEntry entry1 = index.getFirst();
- assertSame( h1,
- entry1.getFactHandle() );
- assertNull( entry1.getNext() );
- assertSame( entry1,
- index.get( h1 ) );
-
- // test get
- final FactEntry entry2 = index.get( h1 );
- assertSame( entry1,
- entry2 );
-
- // test remove
- index.remove( h1 );
- assertNull( index.getFirst() );
- assertNull( index.getValue() );
- }
-
- public void testTwoEntries() {
- final ClassFieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
- "type" );
- final FieldIndexEntry index = new FieldIndexEntry( extractor,
- extractor.getIndex(),
- "stilton".hashCode() );
-
- final Cheese stilton1 = new Cheese( "stilton",
- 35 );
- final InternalFactHandle h1 = new DefaultFactHandle( 1,
- stilton1 );
- final Cheese stilton2 = new Cheese( "stilton",
- 59 );
- final InternalFactHandle h2 = new DefaultFactHandle( 2,
- stilton2 );
-
- // test add
- index.add( h1 );
- index.add( h2 );
- assertEquals( h2,
- index.getFirst().getFactHandle() );
- assertEquals( h1,
- ((FactEntry) index.getFirst().getNext()).getFactHandle() );
-
- // test get
- assertEquals( h1,
- index.get( h1 ).getFactHandle() );
- assertEquals( h2,
- index.get( h2 ).getFactHandle() );
-
- // test removal for combinations
- // remove first
- index.remove( h2 );
- assertEquals( h1,
- index.getFirst().getFactHandle() );
-
- // remove second
- index.add( h2 );
- index.remove( h1 );
- assertEquals( h2,
- index.getFirst().getFactHandle() );
-
- // check index type does not change, as this fact is removed
- stilton1.setType( "cheddar" );
- assertEquals( "stilton",
- index.getValue() );
- }
-
- public void testThreeEntries() {
- final ClassFieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
- "type" );
- final FieldIndexEntry index = new FieldIndexEntry( extractor,
- extractor.getIndex(),
- "stilton".hashCode() );
-
- final Cheese stilton1 = new Cheese( "stilton",
- 35 );
- final InternalFactHandle h1 = new DefaultFactHandle( 1,
- stilton1 );
- final Cheese stilton2 = new Cheese( "stilton",
- 59 );
- final InternalFactHandle h2 = new DefaultFactHandle( 2,
- stilton2 );
- final Cheese stilton3 = new Cheese( "stilton",
- 59 );
- final InternalFactHandle h3 = new DefaultFactHandle( 3,
- stilton3 );
-
- // test add
- index.add( h1 );
- index.add( h2 );
- index.add( h3 );
- assertEquals( h3,
- index.getFirst().getFactHandle() );
- assertEquals( h2,
- ((FactEntry) index.getFirst().getNext()).getFactHandle() );
- assertEquals( h1,
- ((FactEntry) index.getFirst().getNext().getNext()).getFactHandle() );
-
- // test get
- assertEquals( h1,
- index.get( h1 ).getFactHandle() );
- assertEquals( h2,
- index.get( h2 ).getFactHandle() );
- assertEquals( h3,
- index.get( h3 ).getFactHandle() );
-
- // test removal for combinations
- //remove first
- index.remove( h3 );
- assertEquals( h2,
- index.getFirst().getFactHandle() );
- assertEquals( h1,
- ((FactEntry) index.getFirst().getNext()).getFactHandle() );
-
- index.add( h3 );
- index.remove( h2 );
- assertEquals( h3,
- index.getFirst().getFactHandle() );
- assertEquals( h1,
- ((FactEntry) index.getFirst().getNext()).getFactHandle() );
-
- index.add( h2 );
- index.remove( h1 );
- assertEquals( h2,
- index.getFirst().getFactHandle() );
- assertEquals( h3,
- ((FactEntry) index.getFirst().getNext()).getFactHandle() );
-
- index.remove( index.getFirst().getFactHandle() );
- // check index type does not change, as this fact is removed
- stilton2.setType( "cheddar" );
- assertEquals( "stilton",
- index.getValue() );
- }
+// public void testSingleEntry() {
+// final ClassFieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
+// "type" );
+//
+// final FieldIndexEntry index = new FieldIndexEntry( extractor,
+// extractor.getIndex(),
+// "stilton".hashCode() );
+//
+// // Test initial construction
+// assertNull( index.getValue() );
+// assertNull( index.getFirst() );
+// assertEquals( "stilton".hashCode(),
+// index.hashCode() );
+//
+// final Cheese stilton1 = new Cheese( "stilton",
+// 35 );
+// final InternalFactHandle h1 = new DefaultFactHandle( 1,
+// stilton1 );
+//
+// // test add
+// index.add( h1 );
+// assertEquals( "stilton",
+// index.getValue() );
+// final FactEntry entry1 = index.getFirst();
+// assertSame( h1,
+// entry1.getFactHandle() );
+// assertNull( entry1.getNext() );
+// assertSame( entry1,
+// index.get( h1 ) );
+//
+// // test get
+// final FactEntry entry2 = index.get( h1 );
+// assertSame( entry1,
+// entry2 );
+//
+// // test remove
+// index.remove( h1 );
+// assertNull( index.getFirst() );
+// assertNull( index.getValue() );
+// }
+//
+// public void testTwoEntries() {
+// final ClassFieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
+// "type" );
+// final FieldIndexEntry index = new FieldIndexEntry( extractor,
+// extractor.getIndex(),
+// "stilton".hashCode() );
+//
+// final Cheese stilton1 = new Cheese( "stilton",
+// 35 );
+// final InternalFactHandle h1 = new DefaultFactHandle( 1,
+// stilton1 );
+// final Cheese stilton2 = new Cheese( "stilton",
+// 59 );
+// final InternalFactHandle h2 = new DefaultFactHandle( 2,
+// stilton2 );
+//
+// // test add
+// index.add( h1 );
+// index.add( h2 );
+// assertEquals( h2,
+// index.getFirst().getFactHandle() );
+// assertEquals( h1,
+// ((FactEntry) index.getFirst().getNext()).getFactHandle() );
+//
+// // test get
+// assertEquals( h1,
+// index.get( h1 ).getFactHandle() );
+// assertEquals( h2,
+// index.get( h2 ).getFactHandle() );
+//
+// // test removal for combinations
+// // remove first
+// index.remove( h2 );
+// assertEquals( h1,
+// index.getFirst().getFactHandle() );
+//
+// // remove second
+// index.add( h2 );
+// index.remove( h1 );
+// assertEquals( h2,
+// index.getFirst().getFactHandle() );
+//
+// // check index type does not change, as this fact is removed
+// stilton1.setType( "cheddar" );
+// assertEquals( "stilton",
+// index.getValue() );
+// }
+//
+// public void testThreeEntries() {
+// final ClassFieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
+// "type" );
+// final FieldIndexEntry index = new FieldIndexEntry( extractor,
+// extractor.getIndex(),
+// "stilton".hashCode() );
+//
+// final Cheese stilton1 = new Cheese( "stilton",
+// 35 );
+// final InternalFactHandle h1 = new DefaultFactHandle( 1,
+// stilton1 );
+// final Cheese stilton2 = new Cheese( "stilton",
+// 59 );
+// final InternalFactHandle h2 = new DefaultFactHandle( 2,
+// stilton2 );
+// final Cheese stilton3 = new Cheese( "stilton",
+// 59 );
+// final InternalFactHandle h3 = new DefaultFactHandle( 3,
+// stilton3 );
+//
+// // test add
+// index.add( h1 );
+// index.add( h2 );
+// index.add( h3 );
+// assertEquals( h3,
+// index.getFirst().getFactHandle() );
+// assertEquals( h2,
+// ((FactEntry) index.getFirst().getNext()).getFactHandle() );
+// assertEquals( h1,
+// ((FactEntry) index.getFirst().getNext().getNext()).getFactHandle() );
+//
+// // test get
+// assertEquals( h1,
+// index.get( h1 ).getFactHandle() );
+// assertEquals( h2,
+// index.get( h2 ).getFactHandle() );
+// assertEquals( h3,
+// index.get( h3 ).getFactHandle() );
+//
+// // test removal for combinations
+// //remove first
+// index.remove( h3 );
+// assertEquals( h2,
+// index.getFirst().getFactHandle() );
+// assertEquals( h1,
+// ((FactEntry) index.getFirst().getNext()).getFactHandle() );
+//
+// index.add( h3 );
+// index.remove( h2 );
+// assertEquals( h3,
+// index.getFirst().getFactHandle() );
+// assertEquals( h1,
+// ((FactEntry) index.getFirst().getNext()).getFactHandle() );
+//
+// index.add( h2 );
+// index.remove( h1 );
+// assertEquals( h2,
+// index.getFirst().getFactHandle() );
+// assertEquals( h3,
+// ((FactEntry) index.getFirst().getNext()).getFactHandle() );
+//
+// index.remove( index.getFirst().getFactHandle() );
+// // check index type does not change, as this fact is removed
+// stilton2.setType( "cheddar" );
+// assertEquals( "stilton",
+// index.getValue() );
+// }
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexHashTableTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexHashTableTest.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexHashTableTest.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -21,505 +21,505 @@
public class FieldIndexHashTableTest extends TestCase {
- public void testSingleEntry() throws Exception {
- final FieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
- "type" );
+// public void testSingleEntry() throws Exception {
+// final FieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
+// "type" );
+//
+// final Column column = new Column( 0,
+// new ClassObjectType( Cheese.class ) );
+//
+// final Declaration declaration = new Declaration( "typeOfCheese",
+// extractor,
+// column );
+//
+// final FactHandleIndexHashTable map = new FactHandleIndexHashTable( extractor,
+// declaration );
+//
+// final Cheese cheddar = new Cheese( "cheddar",
+// 10 );
+// final InternalFactHandle cheddarHandle1 = new DefaultFactHandle( 0,
+// cheddar );
+//
+// assertEquals( 0,
+// map.size() );
+// assertNull( map.get( new ReteTuple( cheddarHandle1 ) ) );
+//
+// final Cheese stilton1 = new Cheese( "stilton",
+// 35 );
+// final InternalFactHandle stiltonHandle1 = new DefaultFactHandle( 1,
+// stilton1 );
+// map.add( stiltonHandle1 );
+//
+// assertEquals( 1,
+// map.size() );
+// assertEquals( 1,
+// tablePopulationSize( map ) );
+//
+// final Cheese stilton2 = new Cheese( "stilton",
+// 80 );
+// final InternalFactHandle stiltonHandle2 = new DefaultFactHandle( 2,
+// stilton2 );
+//
+// final FieldIndexEntry stiltonEntry = map.get( new ReteTuple( stiltonHandle2 ) );
+// assertSame( stiltonHandle1,
+// stiltonEntry.getFirst().getFactHandle() );
+// assertNull( stiltonEntry.getFirst().getNext() );
+// }
+//
+// public void testTwoDifferentEntries() throws Exception {
+// final FieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
+// "type" );
+//
+// final Column column = new Column( 0,
+// new ClassObjectType( Cheese.class ) );
+//
+// final Declaration declaration = new Declaration( "typeOfCheese",
+// extractor,
+// column );
+//
+// final FactHandleIndexHashTable map = new FactHandleIndexHashTable( extractor,
+// declaration );
+//
+// assertEquals( 0,
+// map.size() );
+//
+// final Cheese stilton1 = new Cheese( "stilton",
+// 35 );
+// final InternalFactHandle stiltonHandle1 = new DefaultFactHandle( 1,
+// stilton1 );
+// map.add( stiltonHandle1 );
+//
+// final Cheese cheddar1 = new Cheese( "cheddar",
+// 35 );
+// final InternalFactHandle cheddarHandle1 = new DefaultFactHandle( 2,
+// cheddar1 );
+// map.add( cheddarHandle1 );
+//
+// assertEquals( 2,
+// map.size() );
+// assertEquals( 2,
+// tablePopulationSize( map ) );
+//
+// final Cheese stilton2 = new Cheese( "stilton",
+// 77 );
+// final InternalFactHandle stiltonHandle2 = new DefaultFactHandle( 2,
+// stilton2 );
+// final FieldIndexEntry stiltonEntry = map.get( new ReteTuple( stiltonHandle2 ) );
+// assertSame( stiltonHandle1,
+// stiltonEntry.getFirst().getFactHandle() );
+// assertNull( stiltonEntry.getFirst().getNext() );
+//
+// final Cheese cheddar2 = new Cheese( "cheddar",
+// 5 );
+// final InternalFactHandle cheddarHandle2 = new DefaultFactHandle( 2,
+// cheddar2 );
+// final FieldIndexEntry cheddarEntry = map.get( new ReteTuple( cheddarHandle2 ) );
+// assertSame( cheddarHandle1,
+// cheddarEntry.getFirst().getFactHandle() );
+// assertNull( cheddarEntry.getFirst().getNext() );
+// }
+//
+// public void testTwoEqualEntries() throws Exception {
+// final FieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
+// "type" );
+//
+// final Column column = new Column( 0,
+// new ClassObjectType( Cheese.class ) );
+//
+// final Declaration declaration = new Declaration( "typeOfCheese",
+// extractor,
+// column );
+//
+// final FactHandleIndexHashTable map = new FactHandleIndexHashTable( extractor,
+// declaration );
+//
+// assertEquals( 0,
+// map.size() );
+//
+// final Cheese stilton1 = new Cheese( "stilton",
+// 35 );
+// final InternalFactHandle stiltonHandle1 = new DefaultFactHandle( 1,
+// stilton1 );
+// map.add( stiltonHandle1 );
+//
+// final Cheese cheddar1 = new Cheese( "cheddar",
+// 35 );
+// final InternalFactHandle cheddarHandle1 = new DefaultFactHandle( 2,
+// cheddar1 );
+// map.add( cheddarHandle1 );
+//
+// final Cheese stilton2 = new Cheese( "stilton",
+// 81 );
+// final InternalFactHandle stiltonHandle2 = new DefaultFactHandle( 3,
+// stilton2 );
+// map.add( stiltonHandle2 );
+//
+// // Two siltons are in the same index bucket, so it won't increase the map size
+// assertEquals( 2,
+// map.size() );
+// assertEquals( 2,
+// tablePopulationSize( map ) );
+//
+// // Check they are correctly chained to the same FieldIndexEntry
+// final Cheese stilton3 = new Cheese( "stilton",
+// 89 );
+// final InternalFactHandle stiltonHandle3 = new DefaultFactHandle( 4,
+// stilton2 );
+//
+// final FieldIndexEntry stiltonEntry = map.get( new ReteTuple( stiltonHandle3 ) );
+// assertSame( stiltonHandle2,
+// stiltonEntry.getFirst().getFactHandle() );
+// assertSame( stiltonHandle1,
+// ((FactEntry) stiltonEntry.getFirst().getNext()).getFactHandle() );
+// }
+//
+// public void testTwoDifferentEntriesSameHashCode() throws Exception {
+// final FieldExtractor extractor = new ClassFieldExtractor( TestClass.class,
+// "object" );
+//
+// final Column column = new Column( 0,
+// new ClassObjectType( TestClass.class ) );
+//
+// final Declaration declaration = new Declaration( "theObject",
+// extractor,
+// column );
+//
+// final FactHandleIndexHashTable map = new FactHandleIndexHashTable( extractor,
+// declaration );
+//
+// final TestClass c1 = new TestClass( 0,
+// new TestClass( 20,
+// "stilton" ) );
+//
+// final InternalFactHandle ch1 = new DefaultFactHandle( 1,
+// c1 );
+//
+// map.add( ch1 );
+//
+// final TestClass c2 = new TestClass( 0,
+// new TestClass( 20,
+// "cheddar" ) );
+// final InternalFactHandle ch2 = new DefaultFactHandle( 2,
+// c2 );
+// map.add( ch2 );
+//
+// // same hashcode, but different values, so it should result in a size of 2
+// assertEquals( 2,
+// map.size() );
+//
+// // however both are in the same table bucket
+// assertEquals( 1,
+// tablePopulationSize( map ) );
+//
+// // this table bucket will have two FieldIndexEntries, as they are actually two different values
+// final FieldIndexEntry entry = (FieldIndexEntry) getEntries( map )[0];
+//
+// assertEquals( c2.getObject(),
+// entry.getValue() );
+// assertEquals( c1.getObject(),
+// ((FieldIndexEntry) entry.getNext()).getValue() );
+// }
+//
+// public void testRemove() throws Exception {
+// final FieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
+// "type" );
+//
+// final Column column = new Column( 0,
+// new ClassObjectType( Cheese.class ) );
+//
+// final Declaration declaration = new Declaration( "typeOfCheese",
+// extractor,
+// column );
+//
+// final FactHandleIndexHashTable map = new FactHandleIndexHashTable( extractor,
+// declaration );
+//
+// assertEquals( 0,
+// map.size() );
+//
+// final Cheese stilton1 = new Cheese( "stilton",
+// 35 );
+// final InternalFactHandle stiltonHandle1 = new DefaultFactHandle( 1,
+// stilton1 );
+// map.add( stiltonHandle1 );
+//
+// final Cheese cheddar1 = new Cheese( "cheddar",
+// 35 );
+// final InternalFactHandle cheddarHandle1 = new DefaultFactHandle( 2,
+// cheddar1 );
+// map.add( cheddarHandle1 );
+//
+// final Cheese stilton2 = new Cheese( "stilton",
+// 81 );
+// final InternalFactHandle stiltonHandle2 = new DefaultFactHandle( 3,
+// stilton2 );
+// map.add( stiltonHandle2 );
+//
+// // Two siltons are in the same index bucket, so it won't increase the map size
+// assertEquals( 2,
+// map.size() );
+// assertEquals( 2,
+// tablePopulationSize( map ) );
+//
+// // cheddar is in its own buccket, which should be removed once empty. We cannot have
+// // empty FieldIndexEntries in the Map, as they get their value from the first FactEntry.
+// map.remove( cheddarHandle1 );
+// assertEquals( 1,
+// map.size() );
+// assertEquals( 1,
+// tablePopulationSize( map ) );
+//
+// // We remove t he stiltonHandle2, but there is still one more stilton, so size should be the same
+// map.remove( stiltonHandle2 );
+// assertEquals( 1,
+// map.size() );
+// assertEquals( 1,
+// tablePopulationSize( map ) );
+//
+// // No more stiltons, so the table should be empty
+// map.remove( stiltonHandle1 );
+// assertEquals( 0,
+// map.size() );
+// assertEquals( 0,
+// tablePopulationSize( map ) );
+// }
+//
+// public void testResize() throws Exception {
+// final FieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
+// "type" );
+//
+// final Column column = new Column( 0,
+// new ClassObjectType( Cheese.class ) );
+//
+// final Declaration declaration = new Declaration( "typeOfCheese",
+// extractor,
+// column );
+//
+// final FactHandleIndexHashTable map = new FactHandleIndexHashTable( extractor,
+// declaration );
+//
+// assertEquals( 0,
+// map.size() );
+//
+// final Cheese stilton1 = new Cheese( "stilton",
+// 35 );
+// map.add( new DefaultFactHandle( 1,
+// stilton1 ) );
+//
+// final Cheese stilton2 = new Cheese( "stilton",
+// 81 );
+// map.add( new DefaultFactHandle( 2,
+// stilton2 ) );
+//
+// final Cheese cheddar1 = new Cheese( "cheddar",
+// 35 );
+// map.add( new DefaultFactHandle( 3,
+// cheddar1 ) );
+//
+// final Cheese cheddar2 = new Cheese( "cheddar",
+// 38 );
+// map.add( new DefaultFactHandle( 4,
+// cheddar2 ) );
+//
+// final Cheese brie = new Cheese( "brie",
+// 293 );
+// map.add( new DefaultFactHandle( 5,
+// brie ) );
+//
+// final Cheese mozerella = new Cheese( "mozerella",
+// 15 );
+// map.add( new DefaultFactHandle( 6,
+// mozerella ) );
+//
+// final Cheese dolcelatte = new Cheese( "dolcelatte",
+// 284 );
+// map.add( new DefaultFactHandle( 7,
+// dolcelatte ) );
+//
+// final Cheese camembert1 = new Cheese( "camembert",
+// 924 );
+// map.add( new DefaultFactHandle( 8,
+// camembert1 ) );
+//
+// final Cheese camembert2 = new Cheese( "camembert",
+// 765 );
+// map.add( new DefaultFactHandle( 9,
+// camembert2 ) );
+//
+// final Cheese redLeicestor = new Cheese( "red leicestor",
+// 23 );
+// map.add( new DefaultFactHandle( 10,
+// redLeicestor ) );
+//
+// final Cheese wensleydale = new Cheese( "wensleydale",
+// 20 );
+// map.add( new DefaultFactHandle( 11,
+// wensleydale ) );
+//
+// final Cheese edam = new Cheese( "edam",
+// 12 );
+// map.add( new DefaultFactHandle( 12,
+// edam ) );
+//
+// final Cheese goude1 = new Cheese( "goude",
+// 93 );
+// map.add( new DefaultFactHandle( 13,
+// goude1 ) );
+//
+// final Cheese goude2 = new Cheese( "goude",
+// 88 );
+// map.add( new DefaultFactHandle( 14,
+// goude2 ) );
+//
+// final Cheese gruyere = new Cheese( "gruyere",
+// 82 );
+// map.add( new DefaultFactHandle( 15,
+// gruyere ) );
+//
+// final Cheese emmental = new Cheese( "emmental",
+// 98 );
+// map.add( new DefaultFactHandle( 16,
+// emmental ) );
+//
+// // At this point we have 16 facts but only 12 different types of cheeses
+// // so no table resize and thus its size is 16
+//
+// assertEquals( 12,
+// map.size() );
+//
+// Entry[] table = map.getTable();
+// assertEquals( 16,
+// table.length );
+//
+// final Cheese feta = new Cheese( "feta",
+// 48 );
+// map.add( new DefaultFactHandle( 2,
+// feta ) );
+//
+// // This adds our 13th type of cheese. The map is set with an initial capacity of 16 and
+// // a threshold of 75%, that after 12 it should resize the map to 32.
+// assertEquals( 13,
+// map.size() );
+//
+// table = map.getTable();
+// assertEquals( 32,
+// table.length );
+//
+// final Cheese haloumi = new Cheese( "haloumi",
+// 48 );
+// map.add( new DefaultFactHandle( 2,
+// haloumi ) );
+//
+// final Cheese chevre = new Cheese( "chevre",
+// 48 );
+// map.add( new DefaultFactHandle( 2,
+// chevre ) );
+//
+// }
+//
+// public static class TestClass {
+// private int hashCode;
+// private Object object;
+//
+// public TestClass() {
+//
+// }
+//
+// public TestClass(final int hashCode,
+// final Object object) {
+// this.hashCode = hashCode;
+// this.object = object;
+// }
+//
+// public Object getObject() {
+// return this.object;
+// }
+//
+// public void setObject(final Object object) {
+// this.object = object;
+// }
+//
+// public void setHashCode(final int hashCode) {
+// this.hashCode = hashCode;
+// }
+//
+// public int hashCode() {
+// return this.hashCode;
+// }
+//
+// public boolean equals(final Object obj) {
+// if ( this == obj ) {
+// return true;
+// }
+// if ( obj == null ) {
+// return false;
+// }
+// if ( getClass() != obj.getClass() ) {
+// return false;
+// }
+// final TestClass other = (TestClass) obj;
+//
+// if ( this.object == null ) {
+// if ( other.object != null ) {
+// return false;
+// }
+// } else if ( !this.object.equals( other.object ) ) {
+// return false;
+// }
+// return true;
+// }
+// }
+//
+// private int tablePopulationSize(final AbstractHashTable map) throws Exception {
+// final Field field = AbstractHashTable.class.getDeclaredField( "table" );
+// field.setAccessible( true );
+// final Entry[] array = (Entry[]) field.get( map );
+// int size = 0;
+// for ( int i = 0, length = array.length; i < length; i++ ) {
+// if ( array[i] != null ) {
+// size++;
+// }
+// }
+// return size;
+// }
+//
+// private Entry[] getEntries(final AbstractHashTable map) throws Exception {
+// final Field field = AbstractHashTable.class.getDeclaredField( "table" );
+// field.setAccessible( true );
+// final List list = new ArrayList();
+//
+// final Entry[] array = (Entry[]) field.get( map );
+// for ( int i = 0, length = array.length; i < length; i++ ) {
+// if ( array[i] != null ) {
+// list.add( array[i] );
+// }
+// }
+// return (Entry[]) list.toArray( new Entry[list.size()] );
+// }
+//
+// public void testEmptyIterator() {
+// final FieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
+// "type" );
+//
+// final Column column = new Column( 0,
+// new ClassObjectType( Cheese.class ) );
+//
+// final Declaration declaration = new Declaration( "typeOfCheese",
+// extractor,
+// column );
+//
+// final FactHandleIndexHashTable map = new FactHandleIndexHashTable( extractor,
+// declaration );
+//
+// final Cheese stilton = new Cheese( "stilton",
+// 55 );
+// final InternalFactHandle stiltonHandle = new DefaultFactHandle( 2,
+// stilton );
+//
+// final Iterator it = map.iterator( new ReteTuple( stiltonHandle ) );
+// for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
+// fail( "Map is empty, there should be no iteration" );
+// }
+// }
- final Column column = new Column( 0,
- new ClassObjectType( Cheese.class ) );
-
- final Declaration declaration = new Declaration( "typeOfCheese",
- extractor,
- column );
-
- final FactHandleIndexHashTable map = new FactHandleIndexHashTable( extractor,
- declaration );
-
- final Cheese cheddar = new Cheese( "cheddar",
- 10 );
- final InternalFactHandle cheddarHandle1 = new DefaultFactHandle( 0,
- cheddar );
-
- assertEquals( 0,
- map.size() );
- assertNull( map.get( new ReteTuple( cheddarHandle1 ) ) );
-
- final Cheese stilton1 = new Cheese( "stilton",
- 35 );
- final InternalFactHandle stiltonHandle1 = new DefaultFactHandle( 1,
- stilton1 );
- map.add( stiltonHandle1 );
-
- assertEquals( 1,
- map.size() );
- assertEquals( 1,
- tablePopulationSize( map ) );
-
- final Cheese stilton2 = new Cheese( "stilton",
- 80 );
- final InternalFactHandle stiltonHandle2 = new DefaultFactHandle( 2,
- stilton2 );
-
- final FieldIndexEntry stiltonEntry = map.get( new ReteTuple( stiltonHandle2 ) );
- assertSame( stiltonHandle1,
- stiltonEntry.getFirst().getFactHandle() );
- assertNull( stiltonEntry.getFirst().getNext() );
- }
-
- public void testTwoDifferentEntries() throws Exception {
- final FieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
- "type" );
-
- final Column column = new Column( 0,
- new ClassObjectType( Cheese.class ) );
-
- final Declaration declaration = new Declaration( "typeOfCheese",
- extractor,
- column );
-
- final FactHandleIndexHashTable map = new FactHandleIndexHashTable( extractor,
- declaration );
-
- assertEquals( 0,
- map.size() );
-
- final Cheese stilton1 = new Cheese( "stilton",
- 35 );
- final InternalFactHandle stiltonHandle1 = new DefaultFactHandle( 1,
- stilton1 );
- map.add( stiltonHandle1 );
-
- final Cheese cheddar1 = new Cheese( "cheddar",
- 35 );
- final InternalFactHandle cheddarHandle1 = new DefaultFactHandle( 2,
- cheddar1 );
- map.add( cheddarHandle1 );
-
- assertEquals( 2,
- map.size() );
- assertEquals( 2,
- tablePopulationSize( map ) );
-
- final Cheese stilton2 = new Cheese( "stilton",
- 77 );
- final InternalFactHandle stiltonHandle2 = new DefaultFactHandle( 2,
- stilton2 );
- final FieldIndexEntry stiltonEntry = map.get( new ReteTuple( stiltonHandle2 ) );
- assertSame( stiltonHandle1,
- stiltonEntry.getFirst().getFactHandle() );
- assertNull( stiltonEntry.getFirst().getNext() );
-
- final Cheese cheddar2 = new Cheese( "cheddar",
- 5 );
- final InternalFactHandle cheddarHandle2 = new DefaultFactHandle( 2,
- cheddar2 );
- final FieldIndexEntry cheddarEntry = map.get( new ReteTuple( cheddarHandle2 ) );
- assertSame( cheddarHandle1,
- cheddarEntry.getFirst().getFactHandle() );
- assertNull( cheddarEntry.getFirst().getNext() );
- }
-
- public void testTwoEqualEntries() throws Exception {
- final FieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
- "type" );
-
- final Column column = new Column( 0,
- new ClassObjectType( Cheese.class ) );
-
- final Declaration declaration = new Declaration( "typeOfCheese",
- extractor,
- column );
-
- final FactHandleIndexHashTable map = new FactHandleIndexHashTable( extractor,
- declaration );
-
- assertEquals( 0,
- map.size() );
-
- final Cheese stilton1 = new Cheese( "stilton",
- 35 );
- final InternalFactHandle stiltonHandle1 = new DefaultFactHandle( 1,
- stilton1 );
- map.add( stiltonHandle1 );
-
- final Cheese cheddar1 = new Cheese( "cheddar",
- 35 );
- final InternalFactHandle cheddarHandle1 = new DefaultFactHandle( 2,
- cheddar1 );
- map.add( cheddarHandle1 );
-
- final Cheese stilton2 = new Cheese( "stilton",
- 81 );
- final InternalFactHandle stiltonHandle2 = new DefaultFactHandle( 3,
- stilton2 );
- map.add( stiltonHandle2 );
-
- // Two siltons are in the same index bucket, so it won't increase the map size
- assertEquals( 2,
- map.size() );
- assertEquals( 2,
- tablePopulationSize( map ) );
-
- // Check they are correctly chained to the same FieldIndexEntry
- final Cheese stilton3 = new Cheese( "stilton",
- 89 );
- final InternalFactHandle stiltonHandle3 = new DefaultFactHandle( 4,
- stilton2 );
-
- final FieldIndexEntry stiltonEntry = map.get( new ReteTuple( stiltonHandle3 ) );
- assertSame( stiltonHandle2,
- stiltonEntry.getFirst().getFactHandle() );
- assertSame( stiltonHandle1,
- ((FactEntry) stiltonEntry.getFirst().getNext()).getFactHandle() );
- }
-
- public void testTwoDifferentEntriesSameHashCode() throws Exception {
- final FieldExtractor extractor = new ClassFieldExtractor( TestClass.class,
- "object" );
-
- final Column column = new Column( 0,
- new ClassObjectType( TestClass.class ) );
-
- final Declaration declaration = new Declaration( "theObject",
- extractor,
- column );
-
- final FactHandleIndexHashTable map = new FactHandleIndexHashTable( extractor,
- declaration );
-
- final TestClass c1 = new TestClass( 0,
- new TestClass( 20,
- "stilton" ) );
-
- final InternalFactHandle ch1 = new DefaultFactHandle( 1,
- c1 );
-
- map.add( ch1 );
-
- final TestClass c2 = new TestClass( 0,
- new TestClass( 20,
- "cheddar" ) );
- final InternalFactHandle ch2 = new DefaultFactHandle( 2,
- c2 );
- map.add( ch2 );
-
- // same hashcode, but different values, so it should result in a size of 2
- assertEquals( 2,
- map.size() );
-
- // however both are in the same table bucket
- assertEquals( 1,
- tablePopulationSize( map ) );
-
- // this table bucket will have two FieldIndexEntries, as they are actually two different values
- final FieldIndexEntry entry = (FieldIndexEntry) getEntries( map )[0];
-
- assertEquals( c2.getObject(),
- entry.getValue() );
- assertEquals( c1.getObject(),
- ((FieldIndexEntry) entry.getNext()).getValue() );
- }
-
- public void testRemove() throws Exception {
- final FieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
- "type" );
-
- final Column column = new Column( 0,
- new ClassObjectType( Cheese.class ) );
-
- final Declaration declaration = new Declaration( "typeOfCheese",
- extractor,
- column );
-
- final FactHandleIndexHashTable map = new FactHandleIndexHashTable( extractor,
- declaration );
-
- assertEquals( 0,
- map.size() );
-
- final Cheese stilton1 = new Cheese( "stilton",
- 35 );
- final InternalFactHandle stiltonHandle1 = new DefaultFactHandle( 1,
- stilton1 );
- map.add( stiltonHandle1 );
-
- final Cheese cheddar1 = new Cheese( "cheddar",
- 35 );
- final InternalFactHandle cheddarHandle1 = new DefaultFactHandle( 2,
- cheddar1 );
- map.add( cheddarHandle1 );
-
- final Cheese stilton2 = new Cheese( "stilton",
- 81 );
- final InternalFactHandle stiltonHandle2 = new DefaultFactHandle( 3,
- stilton2 );
- map.add( stiltonHandle2 );
-
- // Two siltons are in the same index bucket, so it won't increase the map size
- assertEquals( 2,
- map.size() );
- assertEquals( 2,
- tablePopulationSize( map ) );
-
- // cheddar is in its own buccket, which should be removed once empty. We cannot have
- // empty FieldIndexEntries in the Map, as they get their value from the first FactEntry.
- map.remove( cheddarHandle1 );
- assertEquals( 1,
- map.size() );
- assertEquals( 1,
- tablePopulationSize( map ) );
-
- // We remove t he stiltonHandle2, but there is still one more stilton, so size should be the same
- map.remove( stiltonHandle2 );
- assertEquals( 1,
- map.size() );
- assertEquals( 1,
- tablePopulationSize( map ) );
-
- // No more stiltons, so the table should be empty
- map.remove( stiltonHandle1 );
- assertEquals( 0,
- map.size() );
- assertEquals( 0,
- tablePopulationSize( map ) );
- }
-
- public void testResize() throws Exception {
- final FieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
- "type" );
-
- final Column column = new Column( 0,
- new ClassObjectType( Cheese.class ) );
-
- final Declaration declaration = new Declaration( "typeOfCheese",
- extractor,
- column );
-
- final FactHandleIndexHashTable map = new FactHandleIndexHashTable( extractor,
- declaration );
-
- assertEquals( 0,
- map.size() );
-
- final Cheese stilton1 = new Cheese( "stilton",
- 35 );
- map.add( new DefaultFactHandle( 1,
- stilton1 ) );
-
- final Cheese stilton2 = new Cheese( "stilton",
- 81 );
- map.add( new DefaultFactHandle( 2,
- stilton2 ) );
-
- final Cheese cheddar1 = new Cheese( "cheddar",
- 35 );
- map.add( new DefaultFactHandle( 3,
- cheddar1 ) );
-
- final Cheese cheddar2 = new Cheese( "cheddar",
- 38 );
- map.add( new DefaultFactHandle( 4,
- cheddar2 ) );
-
- final Cheese brie = new Cheese( "brie",
- 293 );
- map.add( new DefaultFactHandle( 5,
- brie ) );
-
- final Cheese mozerella = new Cheese( "mozerella",
- 15 );
- map.add( new DefaultFactHandle( 6,
- mozerella ) );
-
- final Cheese dolcelatte = new Cheese( "dolcelatte",
- 284 );
- map.add( new DefaultFactHandle( 7,
- dolcelatte ) );
-
- final Cheese camembert1 = new Cheese( "camembert",
- 924 );
- map.add( new DefaultFactHandle( 8,
- camembert1 ) );
-
- final Cheese camembert2 = new Cheese( "camembert",
- 765 );
- map.add( new DefaultFactHandle( 9,
- camembert2 ) );
-
- final Cheese redLeicestor = new Cheese( "red leicestor",
- 23 );
- map.add( new DefaultFactHandle( 10,
- redLeicestor ) );
-
- final Cheese wensleydale = new Cheese( "wensleydale",
- 20 );
- map.add( new DefaultFactHandle( 11,
- wensleydale ) );
-
- final Cheese edam = new Cheese( "edam",
- 12 );
- map.add( new DefaultFactHandle( 12,
- edam ) );
-
- final Cheese goude1 = new Cheese( "goude",
- 93 );
- map.add( new DefaultFactHandle( 13,
- goude1 ) );
-
- final Cheese goude2 = new Cheese( "goude",
- 88 );
- map.add( new DefaultFactHandle( 14,
- goude2 ) );
-
- final Cheese gruyere = new Cheese( "gruyere",
- 82 );
- map.add( new DefaultFactHandle( 15,
- gruyere ) );
-
- final Cheese emmental = new Cheese( "emmental",
- 98 );
- map.add( new DefaultFactHandle( 16,
- emmental ) );
-
- // At this point we have 16 facts but only 12 different types of cheeses
- // so no table resize and thus its size is 16
-
- assertEquals( 12,
- map.size() );
-
- Entry[] table = map.getTable();
- assertEquals( 16,
- table.length );
-
- final Cheese feta = new Cheese( "feta",
- 48 );
- map.add( new DefaultFactHandle( 2,
- feta ) );
-
- // This adds our 13th type of cheese. The map is set with an initial capacity of 16 and
- // a threshold of 75%, that after 12 it should resize the map to 32.
- assertEquals( 13,
- map.size() );
-
- table = map.getTable();
- assertEquals( 32,
- table.length );
-
- final Cheese haloumi = new Cheese( "haloumi",
- 48 );
- map.add( new DefaultFactHandle( 2,
- haloumi ) );
-
- final Cheese chevre = new Cheese( "chevre",
- 48 );
- map.add( new DefaultFactHandle( 2,
- chevre ) );
-
- }
-
- public static class TestClass {
- private int hashCode;
- private Object object;
-
- public TestClass() {
-
- }
-
- public TestClass(final int hashCode,
- final Object object) {
- this.hashCode = hashCode;
- this.object = object;
- }
-
- public Object getObject() {
- return this.object;
- }
-
- public void setObject(final Object object) {
- this.object = object;
- }
-
- public void setHashCode(final int hashCode) {
- this.hashCode = hashCode;
- }
-
- public int hashCode() {
- return this.hashCode;
- }
-
- public boolean equals(final Object obj) {
- if ( this == obj ) {
- return true;
- }
- if ( obj == null ) {
- return false;
- }
- if ( getClass() != obj.getClass() ) {
- return false;
- }
- final TestClass other = (TestClass) obj;
-
- if ( this.object == null ) {
- if ( other.object != null ) {
- return false;
- }
- } else if ( !this.object.equals( other.object ) ) {
- return false;
- }
- return true;
- }
- }
-
- private int tablePopulationSize(final AbstractHashTable map) throws Exception {
- final Field field = AbstractHashTable.class.getDeclaredField( "table" );
- field.setAccessible( true );
- final Entry[] array = (Entry[]) field.get( map );
- int size = 0;
- for ( int i = 0, length = array.length; i < length; i++ ) {
- if ( array[i] != null ) {
- size++;
- }
- }
- return size;
- }
-
- private Entry[] getEntries(final AbstractHashTable map) throws Exception {
- final Field field = AbstractHashTable.class.getDeclaredField( "table" );
- field.setAccessible( true );
- final List list = new ArrayList();
-
- final Entry[] array = (Entry[]) field.get( map );
- for ( int i = 0, length = array.length; i < length; i++ ) {
- if ( array[i] != null ) {
- list.add( array[i] );
- }
- }
- return (Entry[]) list.toArray( new Entry[list.size()] );
- }
-
- public void testEmptyIterator() {
- final FieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
- "type" );
-
- final Column column = new Column( 0,
- new ClassObjectType( Cheese.class ) );
-
- final Declaration declaration = new Declaration( "typeOfCheese",
- extractor,
- column );
-
- final FactHandleIndexHashTable map = new FactHandleIndexHashTable( extractor,
- declaration );
-
- final Cheese stilton = new Cheese( "stilton",
- 55 );
- final InternalFactHandle stiltonHandle = new DefaultFactHandle( 2,
- stilton );
-
- final Iterator it = map.iterator( new ReteTuple( stiltonHandle ) );
- for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
- fail( "Map is empty, there should be no iteration" );
- }
- }
-
}
Deleted: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/PriorityQueueTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/PriorityQueueTest.java 2006-10-31 22:20:54 UTC (rev 7259)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/PriorityQueueTest.java 2006-11-01 00:09:04 UTC (rev 7260)
@@ -1,31 +0,0 @@
-package org.drools.util;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.Serializable;
-
-import junit.framework.TestCase;
-
-/**
- * @author <a href="mailto:simon at redhillconsulting.com.au">Simon Harris</a>
- * @version $Id: PriorityQueueTest.java,v 1.1 2005/07/26 01:06:34 mproctor Exp $
- */
-public class PriorityQueueTest extends TestCase {
- public void testIsSerializable() {
- assertTrue( Serializable.class.isAssignableFrom( PriorityQueue.class ) );
- }
-}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list