eval.pass.cpp (2095B)
1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // REQUIRES: long_tests 11 12 // <random> 13 14 // template<class RealType = double> 15 // class cauchy_distribution 16 17 // template<class _URNG> result_type operator()(_URNG& g); 18 19 #include <random> 20 #include <cassert> 21 #include <vector> 22 #include <algorithm> 23 24 double 25 f(double x, double a, double b) 26 { 27 return 1/3.1415926535897932 * std::atan((x - a)/b) + .5; 28 } 29 30 int main() 31 { 32 { 33 typedef std::cauchy_distribution<> D; 34 typedef std::mt19937 G; 35 G g; 36 const double a = 10; 37 const double b = .5; 38 D d(a, b); 39 const int N = 1000000; 40 std::vector<D::result_type> u; 41 for (int i = 0; i < N; ++i) 42 u.push_back(d(g)); 43 std::sort(u.begin(), u.end()); 44 for (int i = 0; i < N; ++i) 45 assert(std::abs(f(u[i], a, b) - double(i)/N) < .001); 46 } 47 { 48 typedef std::cauchy_distribution<> D; 49 typedef std::mt19937 G; 50 G g; 51 const double a = -1.5; 52 const double b = 1; 53 D d(a, b); 54 const int N = 1000000; 55 std::vector<D::result_type> u; 56 for (int i = 0; i < N; ++i) 57 u.push_back(d(g)); 58 std::sort(u.begin(), u.end()); 59 for (int i = 0; i < N; ++i) 60 assert(std::abs(f(u[i], a, b) - double(i)/N) < .001); 61 } 62 { 63 typedef std::cauchy_distribution<> D; 64 typedef std::mt19937 G; 65 G g; 66 const double a = .5; 67 const double b = 2; 68 D d(a, b); 69 const int N = 1000000; 70 std::vector<D::result_type> u; 71 for (int i = 0; i < N; ++i) 72 u.push_back(d(g)); 73 std::sort(u.begin(), u.end()); 74 for (int i = 0; i < N; ++i) 75 assert(std::abs(f(u[i], a, b) - double(i)/N) < .001); 76 } 77 }