ProteoWizard
Functions | Variables
erfTest.cpp File Reference
#include "erf.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include <limits>
#include <cstring>
#include <cmath>

Go to the source code of this file.

Functions

void test_real ()
 
void test_series ()
 
void test_real_wrapper ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 
const double epsilon_ = numeric_limits<double>::epsilon()
 

Function Documentation

◆ test_real()

void test_real ( )

Definition at line 107 of file erfTest.cpp.

108{
109 // tests our complex erf against the not-so-standard gcc-provided double erf(double)
110
111 if (os_) *os_ << "test_real()\n";
112
113 double a = 10;
114 for (double x=-a; x<=a; x+=a/100)
115 {
116 complex<double> resultComplex = erf(complex<double>(x));
117 double resultReal = ((double(*)(double))::erf)(x);
118 if (os_) *os_ << x << " -> " << resultComplex << " " << resultReal << endl;
119 unit_assert_equal(resultComplex.real(), resultReal, 1e-12);
120 }
121
122 if (os_) *os_ << endl;
123}
KernelTraitsBase< Kernel >::space_type::abscissa_type x
ostream * os_
Definition erfTest.cpp:38
PWIZ_API_DECL double erf(double x)
real error function; calls gcc-provided erf, complex version (below) on msvc
#define unit_assert_equal(x, y, epsilon)
Definition unit.hpp:99

References pwiz::math::erf(), os_, unit_assert_equal, and x.

Referenced by main().

◆ test_series()

void test_series ( )

Definition at line 127 of file erfTest.cpp.

128{
129 if (os_) *os_ << "test_series()\n";
130
131 // erf_series2 matches erf in region [-2,2]x[-2,2] within 1e-10
132 double a = 2;
133 for (double x=-a; x<=a; x+=a/5.)
134 for (double y=-a; y<=a; y+=a/5.)
135 {
136 complex<double> z(x,y);
137 complex<double> result1 = erf(z);
138 complex<double> result2 = erf_series2(z);
139 if (os_) *os_ << z << ": " << abs(result1-result2) << endl;
140 unit_assert_equal(abs(result1-result2), 0, 1e-10);
141 }
142
143 if (os_) *os_ << endl;
144}
KernelTraitsBase< Kernel >::space_type::ordinate_type y
PWIZ_API_DECL std::complex< double > erf_series2(const std::complex< double > &z)
series implementation for testing

References pwiz::math::erf(), pwiz::math::erf_series2(), os_, unit_assert_equal, x, and y.

Referenced by main().

◆ test_real_wrapper()

void test_real_wrapper ( )

Definition at line 147 of file erfTest.cpp.

148{
149 if (os_) *os_ << "test_real_wrapper()\n";
150
151 double a = 10;
152 for (double x=-a; x<=a; x+=a/100)
153 {
154 double result_pwiz = pwiz::math::erf(x);
155 double result_std = ::erf(x);
156 if (os_) *os_ << x << " -> " << result_pwiz << " " << result_std << endl;
157 unit_assert_equal(result_pwiz, result_std, 1e-12);
158 }
159
160 if (os_) *os_ << endl;
161}

References pwiz::math::erf(), os_, unit_assert_equal, and x.

Referenced by main().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 164 of file erfTest.cpp.

165{
166 TEST_PROLOG(argc, argv)
167
168 try
169 {
170 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
171 if (os_) *os_ << "erfTest\n" << setprecision(20);
172 test_real();
173 test_series();
175 }
176 catch (exception& e)
177 {
178 TEST_FAILED(e.what())
179 }
180 catch (...)
181 {
182 TEST_FAILED("Caught unknown exception.")
183 }
184
186}
void test_real_wrapper()
Definition erfTest.cpp:147
void test_real()
Definition erfTest.cpp:107
void test_series()
Definition erfTest.cpp:127
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175

References os_, TEST_EPILOG, TEST_FAILED, TEST_PROLOG, test_real(), test_real_wrapper(), and test_series().

Variable Documentation

◆ os_

ostream* os_ = 0

Definition at line 38 of file erfTest.cpp.

Referenced by main(), test_real(), test_real_wrapper(), and test_series().

◆ epsilon_

const double epsilon_ = numeric_limits<double>::epsilon()

Definition at line 39 of file erfTest.cpp.