[r7665]: test / trunk / ooRexx / base / class / collections / queue.testGroup Maximize Restore History

Download this file

queue.testGroup    275 lines (245 with data), 9.7 kB

#!/usr/bin/rexx
/*
  SVN Revision: $Rev: 6819 $
  Change Date:  $Date: 2011-03-02 13:04:21 +0000 (Wed, 02 Mar 2011) $
*/
/*----------------------------------------------------------------------------*/
/*                                                                            */
/* Copyright (c) 2007 - 2008 Rexx Language Association. All rights reserved.  */
/*                                                                            */
/* This program and the accompanying materials are made available under       */
/* the terms of the Common Public License v1.0 which accompanies this         */
/* distribution. A copy is also available at the following address:           */
/* http://www.oorexx.org/license.html                                         */
/*                                                                            */
/* Redistribution and use in source and binary forms, with or                 */
/* without modification, are permitted provided that the following            */
/* conditions are met:                                                        */
/*                                                                            */
/* Redistributions of source code must retain the above copyright             */
/* notice, this list of conditions and the following disclaimer.              */
/* Redistributions in binary form must reproduce the above copyright          */
/* notice, this list of conditions and the following disclaimer in            */
/* the documentation and/or other materials provided with the distribution.   */
/*                                                                            */
/* Neither the name of Rexx Language Association nor the names                */
/* of its contributors may be used to endorse or promote products             */
/* derived from this software without specific prior written permission.      */
/*                                                                            */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS        */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT          */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS          */
/* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   */
/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,      */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED   */
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,        */
/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY     */
/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING    */
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS         */
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.               */
/*                                                                            */
/*----------------------------------------------------------------------------*/
  parse source . . s
  group = .TestGroup~new(s)
  group~add(.Collection_queueMethod.testGroup)

  if group~isAutomatedTest then return group

  testResult = group~suite~execute~~print

return testResult

::requires 'ooTest.frm' -- load the ooRexxUnit classes

::class "Collection_queueMethod.testGroup" subclass ooTestCase public

::method "test_1"
   que = .queue~new()
   self~assertEquals('a Queue', que)
   self~assertEquals(0, que~items)
   que1 = .queue~of('Mike')
   self~assertEquals('a Queue', que1)
   self~assertEquals(1, que1~items)
   que2 = .queue~of('Mike', 'David', 'Tom')
   self~assertEquals('a Queue', que2)
   self~assertEquals(3, que2~items)
   que3 = .queue~of('Dick', .array~new())
   self~assertEquals('a Queue', que3)
   self~assertEquals(2, que3~items)

::method "test_2"
   que = .queue~of('Mike', 'David', 'Tom')
   self~assertEquals('Mike', que[1])
   self~assertEquals('David', que[2])
   self~assertEquals('Tom', que[3])
   que~put('Dick', 1)
   self~assertEquals(3, que~items)
   self~assertEquals('Dick', que~at(1))
   que[3] = 'Frank'
   self~assertEquals(3, que~items)
   self~assertEquals('Frank', que~at(3))
   self~assertEquals(.nil, que~at(4))
   self~assertEquals(.nil, que~at(5))

::method "test_3"
   que = .queue~of('Mike', 'David', 'Tom')
   que~append('Dick')
   self~assertEquals(4, que~items)
   self~assertEquals('Dick', que[4])
   que~queue('Frank')
   self~assertEquals(5, que~items)
   self~assertEquals('Frank', que[5])
   que~push('Linda')
   self~assertEquals(6, que~items)
   self~assertEquals('Linda', que[1])
   self~assertEquals('Mike', que[2])
   item = que~pull
   self~assertEquals(5, que~items)
   self~assertEquals('Linda', item)
   self~assertEquals('Mike', que[1])
   item = que~remove(1)
   self~assertEquals(4, que~items)
   self~assertEquals('Mike', item)
   item = que~remove(2)
   self~assertEquals(3, que~items)
   self~assertEquals('Tom', item)

   item = que~remove(4)
   self~assertEquals(3, que~items)
   self~assertEquals(3, que~size)
   self~assertNull(item)

::method "test_delete"
   que = .queue~of('Mike', 'David', 'Tom')
   item = que~delete(1)
   self~assertEquals(2, que~items)
   self~assertEquals(2, que~size)
   self~assertEquals('Mike', item)
   item = que~delete(2)
   self~assertEquals(1, que~items)
   self~assertEquals(1, que~size)
   self~assertEquals('Tom', item)

::method "test_4"
   que = .queue~of('Mike', 'David', 'Tom')
   self~assertEquals(3, que~items)
   self~assertEquals(0, que~isEmpty)
   que~empty()
   self~assertEquals(0, que~items)
   self~assertEquals(1, que~isEmpty)

::method "test_5"
   que = .queue~of('Mike', 'David', 'Tom')
   self~assertEquals(1, que~first)
   self~assertEquals(3, que~last)
   self~assertEquals(3, que~items)

::method "test_6"
   que = .queue~of('Mike', 'David', 'Tom')
   self~assertEquals(1, que~hasIndex(1))
   self~assertEquals(1, que~hasIndex(2))
   self~assertEquals(1, que~hasIndex(3))
   self~assertEquals(0, que~hasIndex(4))

::method "test_7"
   que = .queue~of('Mike', 'David', 'Tom')
   self~assertEquals(1, que~hasItem('Mike'))
   self~assertEquals(1, que~hasItem('David'))
   self~assertEquals(1, que~hasItem('Tom'))
   self~assertEquals(0, que~hasItem('MiKe'))
   self~assertEquals(0, que~hasItem('mIkE'))
   self~assertEquals(0, que~hasItem('Phil'))

::method "test_8"
   que = .queue~of('Mike', 'David', 'Tom')
   arr = que~allItems()
   self~assertEquals(3, arr~items)
   self~assertEquals('Mike', arr[1])
   self~assertEquals('David', arr[2])
   self~assertEquals('Tom', arr[3])

::method "test_9"
   que = .queue~of('Mike', 'David', 'Tom')
   arr = que~allIndexes()
   self~assertEquals(3, arr~items)
   self~assertEquals(1, arr[1])
   self~assertEquals(2, arr[2])
   self~assertEquals(3, arr[3])

::method "test_10"
   que = .queue~of('Mike', 'David', 'Tom', 'David')
   self~assertEquals(1, que~index('Mike'))
   self~assertEquals(2, que~index('David'))
   self~assertEquals(3, que~index('Tom'))

::method "test_11"
   que = .queue~of('Mike', 'David', 'Tom')
   idx = que~insert('Frank', .nil)
   self~assertEquals(4, que~items)
   self~assertEquals(1, idx)
   self~assertEquals('Frank', que[1])
   self~assertEquals('Mike', que[2])
   idx = que~insert('Linda', 2)
   self~assertEquals(3, idx)
   self~assertEquals(5, que~items)
   self~assertEquals('Frank', que[1])
   self~assertEquals('Mike', que[2])
   self~assertEquals('Linda', que[3])
   self~assertEquals('David', que[4])
   idx = que~insert('Karen', 5)
   self~assertEquals(6, idx)
   self~assertEquals(6, que~items)
   self~assertEquals('Karen', que[6])

::method "test_12"
   que = .queue~of('Mike', 'David', 'Tom')
   arr = que~makeArray()
   self~assertEquals(3, arr~items)
   self~assertEquals('Mike', arr[1])
   self~assertEquals('David', arr[2])
   self~assertEquals('Tom', arr[3])

::method "test_13"
   que = .queue~of('Mike', 'David', 'Tom')
   idx = que~next(1)
   self~assertEquals(2, idx)
   idx = que~next(3)
   self~assertEquals(.nil, idx)
   self~expectSyntax(93.966)
   idx = que~next(0)

::method "test_14"
   que = .queue~of('Mike', 'David', 'Tom')
   self~assertEquals('Mike', que~peek)
   self~assertEquals(3, que~items)

::method "test_15"
   que = .queue~of('Mike', 'David', 'Tom')
   idx = que~previous(1)
   self~assertEquals(.nil, idx)
   idx = que~previous(2)
   self~assertEquals(1, idx)
   idx = que~previous(3)
   self~assertEquals(2, idx)
   self~expectSyntax(93.966)
   idx = que~previous(4)

::method "test_16"
   que = .queue~of('Mike', 'David', 'Tom', 'David')
   item = que~removeItem('David')
   self~assertEquals('David', item)
   self~assertEquals(3, que~items)
   self~assertEquals('Mike', que[1])
   self~assertEquals('Tom', que[2])
   self~assertEquals('David', que[3])
   item = que~removeItem('Linda')
   self~assertEquals(.nil, item)
   self~assertEquals(3, que~items)

::method "test_17"
   que = .queue~of("David", "Rick")
   sup = que~supplier
   self~assertEquals('a Supplier', sup)
   self~assertEquals(1, sup~available)
   self~assertEquals(1, sup~index)
   self~assertEquals('David', sup~item)
   sup~next
   self~assertEquals(1, sup~available)
   self~assertEquals(2, sup~index)
   self~assertEquals('Rick', sup~item)
   sup~next
   self~assertEquals(0, sup~available)
   self~expectSyntax(93.937)
   sup~next

::method "test_18"
   que1 = .queue~of("Mike", "Rick", "Fred", "Rick")
   self~expectSyntax(93.966)
   t1 = que1[0]

::method "test_19"
   que1 = .queue~of("Mike", "Rick", "Fred", "Rick")
   self~expectSyntax(93.966)
   t1 = que1[-1]

::method "test_20"
   que1 = .queue~of("Mike", "Rick", "Fred", "Rick")
   self~expectSyntax(93.966)
   t1 = que1['Mike']

::method "test_21"
   que1 = .queue~of("Mike", "Rick", "Fred", "Rick")
   self~expectSyntax(93.966)
   t1 = que1[.nil]