Code-Eli  0.3.6
binomial_coefficient_test_suite.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2 * Copyright (c) 2013 David D. Marshall <ddmarsha@calpoly.edu>
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * David D. Marshall - initial code and implementation
11 ********************************************************************************/
12 
13 #ifndef dm_binomial_coefficient_test_suite_hpp
14 #define dm_binomial_coefficient_test_suite_hpp
15 
16 #include <typeinfo> // typeid
17 #include <string> // std::string
18 #include <sstream> // std::stringstream
19 #include <iomanip> // std::setw
20 #include <vector> // std::vector
21 #include <functional> // std::less
22 
25 
26 #include <string>
27 #include <vector>
28 
29 class binomial_coefficient_test_suite : public Test::Suite
30 {
31  protected:
32  void AddTests()
33  {
36  }
37 
38  public:
40  {
41  // add the tests
42  AddTests();
43  }
45  {
46  }
47 
48  private:
50  {
51  int iv;
52  double dv;
53 
54  eli::mutil::dm::n_choose_k(iv, 10, 7);
55  TEST_ASSERT(iv==120);
56 
57  eli::mutil::dm::n_choose_k(dv, 10, 7);
58 #if defined(__INTEL_COMPILER) && defined(NDEBUG)
59  TEST_ASSERT(std::abs(1-dv/120)<std::numeric_limits<double>::epsilon());
60 #else
61  TEST_ASSERT(dv==120);
62 #endif
63 
64  eli::mutil::dm::n_choose_k(iv, 20, 11);
65  TEST_ASSERT(iv==167960);
66 
67  eli::mutil::dm::n_choose_k(dv, 20, 11);
68  TEST_ASSERT(dv==167960);
69  }
70 
72  {
73  double dv;
74 
76 #if defined(__INTEL_COMPILER) && defined(NDEBUG)
77  TEST_ASSERT(std::abs(1-dv/120)<std::numeric_limits<double>::epsilon());
78 #else
79  TEST_ASSERT(dv==120);
80 #endif
81 
83 #if defined(__INTEL_COMPILER) && defined(NDEBUG)
84  TEST_ASSERT(std::abs(1-dv/167960)<2*std::numeric_limits<double>::epsilon());
85 #else
86  TEST_ASSERT(dv==167960);
87 #endif
88 
90  TEST_ASSERT(std::abs(dv-202.98)<1e-2);
91  }
92 };
93 
94 #endif
95 
void nchoosek_test()
Definition: binomial_coefficient_test_suite.hpp:49
Definition: binomial_coefficient_test_suite.hpp:29
void binomial_coefficient_test()
Definition: binomial_coefficient_test_suite.hpp:71
void n_choose_k(data__ &v, natural__ n, natural__ k)
Definition: binomial_coefficient.hpp:25
void AddTests()
Definition: binomial_coefficient_test_suite.hpp:32
~binomial_coefficient_test_suite()
Definition: binomial_coefficient_test_suite.hpp:44
void binomial_coefficient(data__ &v, const data__ &n, natural__ k)
Definition: binomial_coefficient.hpp:63
binomial_coefficient_test_suite()
Definition: binomial_coefficient_test_suite.hpp:39