//============================================================================== // // Copyright (C) 2003 Dick van Oudheusden // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public // License as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public // License along with this library; if not, write to the Free // Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // //============================================================================== // // $Date: 2006/01/24 19:50:45 $ $Revision: 1.3 $ // //============================================================================== #include #include "ofc/config.h" #include "ofc/DFraction.h" #include "DInc.h" #include "DTest.h" //-DataTypes------------------------------------------------------------------- void DFraction_test() { DFraction *one = [DFraction alloc]; DFraction *two = [[DFraction alloc] init]; DFraction *three = [DFraction new]; char *pntr; char str1[] = "133/45-"; char str2[] = "0x7F/0123/"; char str3[] = "Hello"; STARTTEST(); [one init :6 :4]; TEST([one numerator ] == 3); TEST([one denominator] == 2); TEST([two numerator ] == 0); TEST([two denominator] == 1); [two numerator :4 ]; [two denominator :20]; [one move :two]; TEST([one numerator ] == 1); TEST([one denominator] == 5); TEST([[[[one set :6 :4 ] add :two] toText] icompare :"17/10" ] == 0); TEST([[[[one set :6 :-4] add :two] toText] icompare :"-13/10"] == 0); TEST([[[[one set :6 :4] sub :two] toText] icompare :"13/10" ] == 0); TEST([[[[one set :-6 :-4] sub :two] toText] icompare :"13/10" ] == 0); TEST([[[[one set :6 :4] mul :two] toText] icompare :"3/10" ] == 0); TEST([[[[one set :-6 :4] mul :two] toText] icompare :"-3/10" ] == 0); TEST([[[[one set :6 :4] invert ] toText] icompare :"2/3" ] == 0); TEST([[[[one set :6 :-4] invert ] toText] icompare :"-2/3" ] == 0); TEST([[[[one set :6 :4] div :two] toText] icompare :"15/2" ] == 0); TEST([[[[one set :-6 :4] div :two] toText] icompare :"-15/2" ] == 0); TEST([[one set :6 :4] toDouble] == 1.5); [one set :6 :4]; [two set :1 :5]; TEST([[[three add :one :two] toText] icompare :"17/10"] == 0); TEST([[[three sub :one :two] toText] icompare :"13/10"] == 0); TEST([[[three mul :one :two] toText] icompare :"3/10"] == 0); TEST([[[three div :one :two] toText] icompare :"15/2"] == 0); [one set :6 :4]; [two set :3 :2]; TEST([one compare :two] == 0); TEST([two compare :one] == 0); [one set :3 :4]; [two set :2 :3]; TEST([one compare :two] > 0); TEST([two compare :one] < 0); pntr = str1; TEST([one fromString :&pntr] == 0); TEST(*pntr == '-'); TEST([one numerator ] == 133); TEST([one denominator] == 45); pntr = str2; TEST([one fromString :&pntr] == 0); TEST(*pntr == '/'); TEST([one numerator ] == 127); TEST([one denominator] == 83); pntr = str3; TEST([one fromString :&pntr] == ENODATA); TEST(*pntr == 'H'); STOPTEST(); [one free]; [two free]; [three free]; }