Source Code Cross Referenced for ComparatorTest.java in  » Rule-Engine » Mandarax » test » org » mandarax » comparators » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Rule Engine » Mandarax » test.org.mandarax.comparators 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:        package test.org.mandarax.comparators;
019:
020:        import java.util.Comparator;
021:        import java.util.List;
022:
023:        import junit.framework.TestCase;
024:
025:        import org.mandarax.kernel.ClauseSet;
026:        import org.mandarax.kernel.Fact;
027:        import org.mandarax.kernel.Predicate;
028:        import org.mandarax.kernel.Rule;
029:        import org.mandarax.kernel.SimplePredicate;
030:        import org.mandarax.reference.AdvancedKnowledgeBase;
031:        import org.mandarax.util.LogicFactorySupport;
032:        import org.mandarax.util.logging.LogCategories;
033:
034:        /**
035:         * An abstract test case class for testing the default comparator.
036:         * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
037:         * @version 3.4 <7 March 05>
038:         * @since 2.2
039:         */
040:        public abstract class ComparatorTest extends TestCase implements 
041:                LogCategories {
042:
043:            protected org.mandarax.kernel.ExtendedKnowledgeBase kb = new AdvancedKnowledgeBase();
044:            protected static LogicFactorySupport lfs = new LogicFactorySupport();
045:
046:            // some predicates 
047:            private static Predicate A = new SimplePredicate("A", new Class[] {
048:                    Integer.class, Integer.class });
049:            private static Predicate B = new SimplePredicate("B", new Class[] {
050:                    Integer.class, Integer.class });
051:            private static Predicate C = new SimplePredicate("C", new Class[] {
052:                    Integer.class, Integer.class });
053:
054:            // facts with 0,1 and 2 variables
055:            protected static Fact F0 = lfs.fact(A, new Integer(1), new Integer(
056:                    2));
057:            protected static Fact F1 = lfs.fact(A, lfs.variable("x",
058:                    Integer.class), new Integer(2));
059:            protected static Fact F2 = lfs.fact(A, lfs.variable("x",
060:                    Integer.class), lfs.variable("y", Integer.class));
061:
062:            // some rules 
063:
064:            // 1 prerequisite, 4 variables (occurrences), no negated prerequisite
065:            protected static Rule R0 = lfs.rule(lfs.prereq(B, lfs.variable("x",
066:                    Integer.class), lfs.variable("y", Integer.class)), lfs
067:                    .fact(A, lfs.variable("y", Integer.class), lfs.variable(
068:                            "x", Integer.class)));
069:            // 2 prerequisites, 6 variables (occurrences), no negated prerequisite	
070:            protected static Rule R1 = lfs.rule(lfs.prereq(B, lfs.variable("x",
071:                    Integer.class), lfs.variable("y", Integer.class)), lfs
072:                    .prereq(C, lfs.variable("y", Integer.class), lfs.variable(
073:                            "z", Integer.class)), lfs.fact(A, lfs.variable("x",
074:                    Integer.class), lfs.variable("z", Integer.class)));
075:            // 2 prerequisites, 6 variables (occurrences), 1 prerequisite is negated
076:            protected static Rule R2 = lfs.rule(lfs.prereq(C, lfs.variable("x",
077:                    Integer.class), lfs.variable("y", Integer.class)), lfs
078:                    .prereq(B, lfs.variable("y", Integer.class), lfs.variable(
079:                            "y", Integer.class), true), lfs.fact(A, lfs
080:                    .variable("x", Integer.class), lfs.variable("y",
081:                    Integer.class)));
082:
083:            /**
084:             * Constructor.
085:             * @param aKnowledgeBase a new, uninitialized knowledge base that will be used
086:             */
087:            public ComparatorTest() {
088:                super ("testComparator");
089:            }
090:
091:            /**
092:             * Get a description of this test case.
093:             * This is used by the <code>org.mandarax.demo</code>
094:             * package to display the test cases.
095:             * @return java.lang.String
096:             */
097:            public String getDescription() {
098:                return "test case " + getClass().getName();
099:            }
100:
101:            /**
102:             * Sets up the fixture.
103:             */
104:            protected void setUp() {
105:                ClauseSet[] clauses = getInputOrder();
106:                for (int i = 0; i < clauses.length; i++) {
107:                    kb.add(clauses[i]);
108:                }
109:                kb.setComparator(getComparator());
110:            }
111:
112:            /**
113:             * Get the expected order.
114:             * @return an array of clause sets
115:             */
116:            protected abstract ClauseSet[] getExpectedOrder();
117:
118:            /**
119:             * Get the input order.
120:             * @return an array of clause sets
121:             */
122:            protected abstract ClauseSet[] getInputOrder();
123:
124:            /**
125:             * Get the comparator.
126:             * @return a comparator
127:             */
128:            protected abstract Comparator getComparator();
129:
130:            /**
131:             * Run the test.
132:             */
133:            public void testComparator() {
134:                LOG_TEST.info("Start Testcase " + getClass().getName()
135:                        + " , test method: " + "testClauses()");
136:
137:                List clauses = kb.getClauseSets(A);
138:                ClauseSet[] expected = getExpectedOrder();
139:                for (int i = 0; i < clauses.size(); i++) {
140:                    if (clauses.get(i) != expected[i]) {
141:                        LOG_TEST.info("Clause set expected at position " + i
142:                                + " is " + expected[i] + " but is "
143:                                + clauses.get(i));
144:                        assertTrue(false);
145:                    }
146:                }
147:                assertTrue(true);
148:            }
149:
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.