1 #include "TestStdDeviation.h" 2 #include <cmath> 3 using namespace std; 4 TestStdDeviation()5TestStdDeviation::TestStdDeviation() 6 { 7 } 8 ~TestStdDeviation()9TestStdDeviation::~TestStdDeviation() 10 { 11 } 12 run()13void TestStdDeviation::run() 14 { 15 testStdDeviationDouble(); 16 testStdDeviationArray(); 17 } 18 testStdDeviationDouble()19void TestStdDeviation::testStdDeviationDouble() 20 { 21 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 22 // Tests using the double constructor 23 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 24 25 // create a std deviation 26 StdDeviation double_stdd( 0.5 ); 27 _test( double_stdd.value() == 0.5 ); 28 } 29 testStdDeviationArray()30void TestStdDeviation::testStdDeviationArray() 31 { 32 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 33 // Tests using the array constructor 34 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 35 36 // create an array of values and use to 37 // create a std deviation then check 38 // the calculated std deviation 39 std::vector<double> numbers; 40 for( int i = 1; i <= 10; i++ ) { 41 42 numbers.push_back( (double)i ); 43 } 44 StdDeviation array_stdd( numbers ); 45 _test( closeEnough( array_stdd.value(), 3.02765, 0.0001 ) ); 46 } 47 48 49