[r8246]: test / trunk / ooRexx / base / class / String / floor.testgroup Maximize Restore History

Download this file

floor.testgroup    117 lines (101 with data), 5.6 kB

#!/usr/bin/rexx
/*
  SVN Revision: $Rev: 3371 $
  Change Date:  $Date: 2008-09-21 00:33:29 -0400 (Sun, 21 Sep 2008) $
*/
/*----------------------------------------------------------------------------*/
/*                                                                            */
/* Copyright (c) 2012 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(.String_floorMethod.testGroup)

  if group~isAutomatedTest then return group

  testResult = group~suite~execute~~print

return testResult

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

::class "String_floorMethod.testGroup" subclass ooTestCase public

::method 'testzero'
    self~assertSame(0, 0~floor())
    self~assertSame(0, '0'~floor())
    self~assertSame(0, 0.0~floor())
    self~assertSame(0, .00000000~floor())
    self~assertSame(0, '-0'~floor())
    self~assertSame(0, 0e0~floor())

::method 'testinteger'
    self~assertSame('1', 000001~floor())
    self~assertSame('-1', ('-000001')~floor())
    self~assertSame('5', '5'~floor())
    self~assertSame('-5', (-5)~floor())
    self~assertSame('5', 5~floor())
    self~assertSame('-5', (-5)~floor())
    self~assertSame('5', 5.00000~floor())
    self~assertSame('-5', (-5.00000)~floor())
    -- these will be truncated by rounding first, so the negative
    -- one will not go to -6
    self~assertSame('5', 5.000000001~floor())
    self~assertSame('-5', ('-5.000000001')~floor())

    self~assertSame('50', 5e1~floor())
    self~assertSame('-50', ('-5e1')~floor())

::method 'testnoninteger'
    self~assertSame('5', 5.1~floor)
    self~assertSame('-6', '-5.1'~floor)
    -- limit of default digits, so no rounding
    self~assertSame('5', 5.00000001~floor)
    self~assertSame('-6', '-5.00000001'~floor)
    -- these will round and carry into the significant
    -- digits, so there are decimals
    self~assertSame('5', '5.000000009'~floor)
    self~assertSame('-6', '-5.000000009'~floor)
    -- code has special checks for values between zero and one, so test this explicitly

    self~assertSame('0', 0.1~floor)
    self~assertSame('-1', '-0.1'~floor)
    -- limit of default digits, so no rounding
    self~assertSame('0', 0.111111111~floor)
    self~assertSame('-1', '-0.111111111'~floor)

::method 'testroundout'
    self~assertSame('9', '9.1'~floor)
    self~assertSame('-10', '-9.1'~floor)
    self~assertSame('99999', '99999.1'~floor)
    self~assertSame('-100000', '-99999.1'~floor)

::method 'testnoexp'
   self~assertSame('1000000000000', '1e12'~floor)
   self~assertSame('-1000000000000', '-1e12'~floor)

::method 'testnumericerror'
    self~expectSyntax(93.943)
    xre=nov~floor

::method 'testargerror'
    self~expectSyntax(93.902)
    xre=nov~floor(2)