1 #include "TestOneWayANOVA.h" 2 #include "arrcmp.h" 3 4 #include <fstream> 5 #include <iostream> 6 #include <vector> 7 #include <string> 8 9 using namespace std; 10 11 TestOneWayANOVA()12TestOneWayANOVA::TestOneWayANOVA() 13 { 14 } 15 ~TestOneWayANOVA()16TestOneWayANOVA::~TestOneWayANOVA() 17 { 18 } 19 run()20void TestOneWayANOVA::run() 21 { 22 testConstructor(); 23 testGetANOVATables(); 24 } 25 testConstructor()26void TestOneWayANOVA::testConstructor(){ 27 28 std::string reference = ""; 29 reference.append("ANOVA Table for Factor 0\n"); 30 reference.append("Source of Sum of Mean Sum of \n"); 31 reference.append("Variation DoF Squares Squares Fdata p\n"); 32 reference.append("Between Groups 1 139.599 139.599 40.1621 0.0000\n"); 33 reference.append("Within Groups 8 27.807 3.47587\n"); 34 reference.append("Total 9 167.406\n"); 35 36 std::vector<int> dataInput(10); 37 std::vector<double> dataOutput(10); 38 dataInput[0] = 0; dataOutput[0]=11.06; 39 dataInput[1] = 0; dataOutput[1]=15.4; 40 dataInput[2] = 0; dataOutput[2]=11.81; 41 dataInput[3] = 1; dataOutput[3]=20.48; 42 dataInput[4] = 1; dataOutput[4]=20.32; 43 dataInput[5] = 0; dataOutput[5]=10.96; 44 dataInput[6] = 0; dataOutput[6]=15.86; 45 dataInput[7] = 0; dataOutput[7]=10.8; 46 dataInput[8] = 1; dataOutput[8]=19.73; 47 dataInput[9] = 1; dataOutput[9]=20.57; 48 49 DDaceMainEffects::Response response(dataOutput); 50 DDaceMainEffects::Factor factor = 51 DDaceMainEffects::Factor(dataInput, 2, response); 52 53 std::vector<DDaceMainEffects::Factor> factors; 54 factors.push_back(factor); 55 56 DDaceMainEffects::OneWayANOVA oneWayANOVA(factors); 57 58 oneWayANOVA.printANOVATables(); 59 std::string output = oneWayANOVA.getANOVATables(); 60 _test(output==reference); 61 62 } 63 testGetANOVATables()64void TestOneWayANOVA::testGetANOVATables() 65 { 66 67 std::string reference = ""; 68 reference.append("Source of Sum of Mean Sum of\n"); 69 reference.append("Variation DoF Squares Squares Fdata p \n"); 70 reference.append("Between Groups 1 139.599 139.599 40.1621 0.0000\n"); 71 reference.append("Within Groups 8 27.807 3.47587\n"); 72 reference.append("Total 9 167.406\n"); 73 74 std::vector<int> dataInput(10); 75 std::vector<double> dataOutput(10); 76 dataInput[0] = 0; dataOutput[0]=11.06; 77 dataInput[1] = 0; dataOutput[1]=15.4; 78 dataInput[2] = 0; dataOutput[2]=11.81; 79 dataInput[3] = 1; dataOutput[3]=20.48; 80 dataInput[4] = 1; dataOutput[4]=20.32; 81 dataInput[5] = 0; dataOutput[5]=10.96; 82 dataInput[6] = 0; dataOutput[6]=15.86; 83 dataInput[7] = 0; dataOutput[7]=10.8; 84 dataInput[8] = 1; dataOutput[8]=19.73; 85 dataInput[9] = 1; dataOutput[9]=20.57; 86 87 DDaceMainEffects::Response response(dataOutput); 88 DDaceMainEffects::Factor factor = DDaceMainEffects::Factor(dataInput, 2, response); 89 90 std::vector<DDaceMainEffects::Factor> factors; 91 factors.push_back(factor); 92 93 DDaceMainEffects::OneWayANOVA oneWayANOVA(factors); 94 95 std::string output = oneWayANOVA.getANOVATables(); 96 _test(output==reference); 97 98 } 99 100 101