//============================================================================== // // Copyright (C) 2002 Dick van Oudheusden // // This program 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 program 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 program; if not, write to the Free // Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // //============================================================================== // // $Date: 2006/09/11 18:08:00 $ $Revision: 1.3 $ // //============================================================================== #include #include "ofc/config.h" #include "ofc/DComplex.h" #include "DInc.h" #include "DTest.h" //-DataTypes------------------------------------------------------------------- void DComplex_test() { DComplex *one = [DComplex alloc]; DComplex *two = [DComplex alloc]; DComplex *three = [DComplex new]; STARTTEST(); [one init :3.0 :4.0]; TEST([one re] == 3.0); TEST([one im] == 4.0); TEST([one abs] == 5.0); [two init :-3.2 :-4.7]; TEST([[two toText] icompare :"-3.2-4.7j"] == 0); TEST([[[two cng] toText] icompare :"-3.2+4.7j"] == 0); // checked with python TEST([[[[one set :1.8 :-2.7] acos ] toText] icompare :"1.00409+1.87995j"] == 0); TEST([[[[one set :1.8 :-2.7] acosh] toText] icompare :"1.87995-1.00409j"] == 0); TEST([[[[one set :1.8 :-2.7] asin ] toText] icompare :"0.566702-1.87995j"] == 0); TEST([[[[one set :1.8 :-2.7] asinh] toText] icompare :"1.86177-0.960298j"] == 0); TEST([[[[one set :1.8 :-2.7] atan ] toText] icompare :"1.3902-0.253973j"] == 0); TEST([[[[one set :1.8 :-2.7] atanh] toText] icompare :"0.161507-1.31304j"] == 0); TEST([[[[one set :1.8 :-2.7] cos ] toText] icompare :"-1.69799+7.21257j"] == 0); TEST([[[[one set :1.8 :-2.7] cosh ] toText] icompare :"-2.80938-1.25743j"] == 0); TEST([[[[one set :1.8 :-2.7] exp ] toText] icompare :"-5.46932-2.5855j"] == 0); TEST([[[[one set :1.8 :-2.7] log ] toText] icompare :"1.17711-0.982794j"] == 0); TEST([[[[one set :1.8 :-2.7] sin ] toText] icompare :"7.27802+1.68272j"] == 0); TEST([[[[one set :1.8 :-2.7] sinh ] toText] icompare :"-2.65994-1.32807j"] == 0); TEST([[[[one set :1.8 :-2.7] sqrt ] toText] icompare :"1.58824-0.849999j"] == 0); TEST([[[[one set :1.8 :-2.7] tan ] toText] icompare :"-0.00402992-1.00813j"] == 0); TEST([[[[one set :1.8 :-2.7] tanh ] toText] icompare :"0.96506+0.0407846j"] == 0); // add, div, rmul, imul, mul, nrm, sqrt and sub are used in acos etc. // add,sub,mul,div (two operands) [one set : 3.0 :4.0]; [two set :-4.0 :5.0]; TEST([[[three add :one :two] toText] icompare :"-1+9j"] == 0); TEST([[[three sub :one :two] toText] icompare :"7-1j"] == 0); TEST([[[three mul :one :two] toText] icompare :"-32-1j"] == 0); TEST([[[three div :one :two] toText] icompare :"0.195122-0.756098j"] == 0); [one free]; [two free]; [three free]; STOPTEST(); }