//============================================================================== // // Copyright (C) 2006 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/22 08:34:52 $ $Revision: 1.1 $ // //============================================================================== #include #include "ofc/config.h" #include "ofc/DBigFraction.h" #include "DInc.h" #include "DTest.h" //-DataTypes------------------------------------------------------------------- void DBigFraction_test() { DBigFraction *one = [DBigFraction alloc]; DBigFraction *two = [[DBigFraction alloc] init]; DBigFraction *three = [DBigFraction new]; char str1[] = "375/245+1/2"; char *pntr1 = str1; char str2[] = "Hello"; char *pntr2 = str2; STARTTEST(); [one init :"6/4" :10]; TEST([one numerator ] == 3); TEST([one denominator] == 2); TEST([two numerator ] == 0); TEST([two denominator] == 1); [two fraction :4 :20]; [one move :two]; TEST([one numerator ] == 1); TEST([one denominator] == 5); [one set :0.375]; TEST([one numerator ] == 3); TEST([one denominator] == 8); [one fraction :17 :10]; TEST([one get] == 1.7); TEST([one toDouble] == 1.7); TEST([one set :"9898285092857149581049051084908109581841289045810985092/81274174987241294987598172945127663553252355255" :10]); TEST([[one get :10] icompare :"9898285092857149581049051084908109581841289045810985092/81274174987241294987598172945127663553252355255" ] == 0); TEST([[[[one fraction :6 :4 ] add :two] toText] icompare :"17/10" ] == 0); TEST([[[[one fraction :6 :-4] add :two] toText] icompare :"-13/10"] == 0); TEST([[[[one fraction :6 :4] sub :two] toText] icompare :"13/10" ] == 0); TEST([[[[one fraction :-6 :-4] sub :two] toText] icompare :"13/10" ] == 0); TEST([[[[one fraction :6 :4] mul :two] toText] icompare :"3/10" ] == 0); TEST([[[[one fraction :-6 :4] mul :two] toText] icompare :"-3/10" ] == 0); TEST([[[[one fraction :6 :4] invert ] toText] icompare :"2/3" ] == 0); TEST([[[[one fraction :6 :-4] invert ] toText] icompare :"-2/3" ] == 0); TEST([[[[one fraction :6 :4] div :two] toText] icompare :"15/2" ] == 0); TEST([[[[one fraction :-6 :4] div :two] toText] icompare :"-15/2" ] == 0); TEST([[one fraction :6 :4] toDouble] == 1.5); [one fraction :6 :4]; [two fraction :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 fraction :6 :4]; [two fraction :3 :2]; TEST([one compare :two] == 0); TEST([two compare :one] == 0); [one fraction :3 :4]; [two fraction :2 :3]; TEST([one compare :two] > 0); TEST([two compare :one] < 0); TEST([one fromString :&pntr1] == 0); TEST([one numerator ] == 75); TEST([one denominator] == 49); TEST(*pntr1 == '+'); TEST([one fromString :&pntr2] == ENODATA); TEST(*pntr2 == 'H'); STOPTEST(); [one free]; [two free]; [three free]; }