Revision 1148
trunk/tests/gtests/atan2/atan2.dat (revision 1148)  

1 
0.977396 0.211418 
trunk/tests/gtests/atan2/atan2.tpl (revision 1148)  

1 
DATA_SECTION 

2 
init_vector s(1,2) 

3  
4 
PARAMETER_SECTION 

5 
init_vector ss(1,2) 

6 
LOCAL_CALCS 

7 
ss = s; 

8 
END_CALCS 

9  
10 
objective_function_value y 

11  
12 
PROCEDURE_SECTION 

13 
y = M_PIatan2(ss(1),ss(2)); 

14 


15 
REPORT_SECTION 

16 
report << ss << endl; 

17 
// wrong value 

18 
report<<"atan2(dvariable,dvariable)="<<atan2(ss[1],ss[2])<<endl; 

19 
//report << "atan(dvariable/dvariable)=" << atan(ss[1]/ss[2]) << endl; 

20  
21 
dvector st(1,2); 

22 
st[1] = value(ss[1]); 

23 
st[2] = value(ss[2]); 

24 
// correct value 

25 
report<<"atan2(double,double)="<<atan2(st[1], st[2])<<endl; 

26 
//report << "atan(double/double)=" << atan(st[1]/st[2]) << endl; 

27  
28 
//atan2(dvariable,dvariable)=1.35777 

29 
//atan2(double,double)=1.78382 
trunk/tests/gtests/test_atan2.cpp (revision 1148)  

1 
#include <gtest/gtest.h> 

2 
#include <fvar.hpp> 

3 
#include <cmath> 

4  
5 
extern "C" 

6 
{ 

7 
void test_ad_exit(const int exit_code) 

8 
{ 

9 
throw exit_code; 

10 
} 

11 
} 

12  
13 
class test_atan2: public ::testing::Test {}; 

14  
15 
gradient_structure gs(1500000L); 

16 
/** 

17 
* Test atan2 for x greater than zero. 

18 
*/ 

19 
TEST_F(test_atan2, x_greater_than_zero) 

20 
{ 

21 
dvariable y = 10.0; 

22 
dvariable x = 10.0; 

23 
const double v = value(atan2(y, x)); 

24 
const double expected = std::atan2(value(y), value(x)); 

25 
//const double v2 = 2.0 * std::atan((std::sqrt(value(x) * value(x) + value(y) * value(y))  value(x)) / value(y)); 

26 
//std::cout << v << ' ' << expected << ' ' << v2 << std::endl; 

27 
if (expected  0.000000001 < v && v < expected + 0.000000001) 

28 
{ 

29 
SUCCEED(); 

30 
return; 

31 
} 

32 
std::cout << v << ' ' << expected << std::endl; 

33 
FAIL(); 

34 
} 

35 
/** 

36 
* Test atan2 for x greater than zero. 

37 
*/ 

38 
TEST_F(test_atan2, y_greater_than_or_equal_zero_x_less_than_zero) 

39 
{ 

40 
dvariable y = 10.0; 

41 
dvariable x = 10.0; 

42 
//const double pi = std::atan(1.0)*4.0; 

43 
//const double v = value(atan2(y, x)) + pi ; 

44 
const double v = value(atan2(y, x)); 

45 
const double expected = std::atan2(value(y), value(x)); 

46 
//const double v2 = 2.0 * std::atan((std::sqrt(value(x) * value(x) + value(y) * value(y))  value(x)) / value(y)); 

47 
//std::cout << v << ' ' << expected << ' ' << v2 << std::endl; 

48 
if (v == expected) 

49 
{ 

50 
SUCCEED(); 

51 
return; 

52 
} 

53 
std::cout << v << ' ' << expected << std::endl; 

54 
FAIL(); 

55 
} 

56 
/** 
Also available in: Unified diff