⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basebetaleftmemorytestclass.java

📁 jboss规则引擎
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        this.memory.add( this.workingMemory,
                         wrapper1 );
        this.memory.add( this.workingMemory,
                         wrapper2 );
        Assert.assertEquals( "Memory should have size 3",
                             3,
                             this.memory.size() );

        this.memory.remove( this.workingMemory,
                            wrapper1 );
        Assert.assertEquals( "Memory should have size 2",
                             2,
                             this.memory.size() );

        this.memory.remove( this.workingMemory,
                            wrapper2 );
        Assert.assertEquals( "Memory should have size 1",
                             1,
                             this.memory.size() );

        this.memory.remove( this.workingMemory,
                            wrapper0 );
        Assert.assertEquals( "Memory should have size 0",
                             0,
                             this.memory.size() );
    }

    /*
     * Test method for 'org.drools.reteoo.beta.BetaLeftMemory.isEmpty()'
     */
    public void testIsEmpty() {
        Assert.assertTrue( "Memory should be empty",
                           this.memory.isEmpty() );

        this.memory.add( this.workingMemory,
                         this.tuple0 );
        Assert.assertFalse( "Memory should not be empty",
                            this.memory.isEmpty() );
    }

    /*
     * Test method for 'org.drools.reteoo.beta.BetaLeftMemory.size()'
     */
    public void testSize() {
        Assert.assertEquals( "Memory should have size 0",
                             0,
                             this.memory.size() );

        this.memory.add( this.workingMemory,
                         this.tuple0 );
        Assert.assertEquals( "Memory should have size 1",
                             1,
                             this.memory.size() );

        this.memory.add( this.workingMemory,
                         this.tuple1 );
        Assert.assertEquals( "Memory should have size 2",
                             2,
                             this.memory.size() );

        this.memory.remove( this.workingMemory,
                            this.tuple0 );
        Assert.assertEquals( "Memory should have size 1",
                             1,
                             this.memory.size() );

        this.memory.remove( this.workingMemory,
                            this.tuple1 );
        Assert.assertEquals( "Memory should have size 0",
                             0,
                             this.memory.size() );
    }

    public void testParameterlessIterator() {
        try {
            final DummyValueObject obj3 = new DummyValueObject( false,
                                                                "string2",
                                                                20,
                                                                "object2" );
            final DefaultFactHandle f3 = (DefaultFactHandle) this.factory.newFactHandle( obj3 );
            final ReteTuple tuple3 = new ReteTuple( f3 );

            this.memory.add( this.workingMemory,
                             this.tuple0 );
            this.memory.add( this.workingMemory,
                             this.tuple1 );
            this.memory.add( this.workingMemory,
                             this.tuple2 );
            this.memory.add( this.workingMemory,
                             tuple3 );
            Assert.assertEquals( "Memory should have size 4",
                                 4,
                                 this.memory.size() );

            final Iterator i = this.memory.iterator();
            Assert.assertTrue( "There should be a next tuple",
                               i.hasNext() );
            ReteTuple tuple = (ReteTuple) i.next();
            Assert.assertSame( "Wrong returned tuple",
                               this.tuple0,
                               tuple );

            Assert.assertTrue( "There should be a next tuple",
                               i.hasNext() );
            tuple = (ReteTuple) i.next();
            Assert.assertSame( "Wrong returned tuple",
                               this.tuple1,
                               tuple );

            Assert.assertTrue( "There should be a next tuple",
                               i.hasNext() );
            tuple = (ReteTuple) i.next();
            Assert.assertSame( "Wrong returned tuple",
                               this.tuple2,
                               tuple );

            Assert.assertTrue( "There should be a next tuple",
                               i.hasNext() );
            tuple = (ReteTuple) i.next();
            Assert.assertSame( "Wrong returned tuple",
                               tuple3,
                               tuple );

            Assert.assertFalse( "There should not be a next tuple",
                                i.hasNext() );
        } catch ( final UnsupportedOperationException e ) {
            Assert.fail( "Beta memory was not supposed to throw any exception: " + e.getMessage() );
        } catch ( final ClassCastException e ) {
            Assert.fail( "BetaRightMemory was not supposed to throw ClassCastException: " + e.getMessage() );
        }
    }

    public void testSelectPossibleMatches2() {
        final int counter = this.child.getCounter();
        this.memory.selectPossibleMatches( this.workingMemory,
                                           this.f0 );
        Assert.assertEquals( "Should have called inner memory",
                             counter + 1,
                             this.child.getCounter() );
    }

    public abstract void testIterator();

    public abstract void testSelectPossibleMatches();

    /**
     * Add an object to the index, then change indexed attribute, then do 
     * a remove;
     */
    public abstract void testModifyObjectAttribute();

    public static class MockBetaLeftMemory
        implements
        BetaLeftMemory {
        private int callCounter = 0;

        public void add(final WorkingMemory workingMemory,
                        final MultiLinkedListNodeWrapper tuple) {
            this.callCounter++;
        }

        public void add(final WorkingMemory workingMemory,
                        final ReteTuple tuple) {
            this.callCounter++;
        }

        public boolean isEmpty() {
            this.callCounter++;
            return false;
        }

        public boolean isPossibleMatch(final MultiLinkedListNodeWrapper tuple) {
            this.callCounter++;
            return true;
        }

        public Iterator iterator(final WorkingMemory workingMemory,
                                 final InternalFactHandle handle) {
            this.callCounter++;
            return null;
        }

        public Iterator iterator() {
            this.callCounter++;
            return null;
        }

        public void remove(final WorkingMemory workingMemory,
                           final MultiLinkedListNodeWrapper tuple) {
            this.callCounter++;
        }

        public void remove(final WorkingMemory workingMemory,
                           final ReteTuple tuple) {
            this.callCounter++;
        }

        public void selectPossibleMatches(final WorkingMemory workingMemory,
                                          final InternalFactHandle handle) {
            this.callCounter++;
        }

        public int size() {
            this.callCounter++;
            return 0;
        }

        public int getCounter() {
            return this.callCounter;
        }

        public BetaLeftMemory getInnerMemory() throws OperationNotSupportedException {
            return null;
        }

        public void setInnerMemory(final BetaLeftMemory innerMemory) throws OperationNotSupportedException {
        }
    };

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -