Qucs-core  0.0.19
Math.cpp
Go to the documentation of this file.
00001 /*
00002  * Math.cpp - Unit test for math operations
00003  *
00004  * Copyright (C) 2015 Guilherme Brondani Torri <guitorri@gmail.com>
00005  *
00006  * This is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2, or (at your option)
00009  * any later version.
00010  *
00011  * This software is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this package; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "qucs_typedefs.h"
00024 #include "real.h"
00025 #include "complex.h"
00026 
00027 #include "testDefine.h"   // constants used on tests
00028 #include "gtest/gtest.h"  // Google Test
00029 
00030 TEST(Real, sqrt) {
00031   ASSERT_EQ (18.0, qucs::sqrt (324.0));
00032   ASSERT_EQ (0.0, qucs::sqrt (0.0));
00033   //ASSERT_EQ (-1, qucs::sqrt(-22.0)); //error NaN (depending on implementation)
00034 }
00035 
00036 TEST(Real, round) {
00037   ASSERT_EQ (1.0, qucs::round (1.4));
00038 }
00039 TEST(real, trunc) {
00040   ASSERT_EQ (2.0, qucs::round (2.3));
00041 }
00042 
00043 TEST(Real, jn_BesselFistKind) {
00044   // FIXME not in qucs::
00045   EXPECT_NEAR ( 0.44, jn (1, 1), 0.0001);
00046 }
00047 
00048 TEST(Real, Factorial) {
00049   ASSERT_EQ ( 479001600, qucs::factorial (12) );
00050 }
00051 
00052 TEST (Complex, cos) {
00053   nr_complex_t z = nr_complex_t (1.0, 1.0);
00054   EXPECT_NEAR ( 0.83373002, qucs::cos (z).real(), tol);
00055   EXPECT_NEAR (-0.98889770, qucs::cos (z).imag(), tol);
00056 }
00057 
00058 TEST (Complex, jn_BesselFistKind) {
00059   nr_complex_t z = nr_complex_t (1.0, 1.0);
00060   EXPECT_NEAR ( 0.61416033492290361, qucs::jn (1, z).real(), tol);
00061   EXPECT_NEAR ( 0.36502802882708778, qucs::jn (1, z).imag(), tol);
00062 }