[cc276e] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
---|
[94d5ac6] | 5 | *
|
---|
| 6 | *
|
---|
| 7 | * This file is part of MoleCuilder.
|
---|
| 8 | *
|
---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
[cc276e] | 21 | */
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | * MPQCCommandJobUnitTest.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: Feb 08, 2012
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | #include <cppunit/CompilerOutputter.h>
|
---|
| 36 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 37 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 38 |
|
---|
| 39 | // include headers that implement a archive in simple text format
|
---|
| 40 | #include <boost/archive/text_oarchive.hpp>
|
---|
| 41 | #include <boost/archive/text_iarchive.hpp>
|
---|
| 42 |
|
---|
| 43 | #include <vector>
|
---|
| 44 |
|
---|
| 45 | #include "MPQCCommandJobUnitTest.hpp"
|
---|
| 46 |
|
---|
| 47 | #include "Jobs/MPQCCommandJob.hpp"
|
---|
| 48 |
|
---|
| 49 | #include "CodePatterns/Assert.hpp"
|
---|
| 50 | #include "CodePatterns/Log.hpp"
|
---|
| 51 |
|
---|
| 52 | #ifdef HAVE_TESTRUNNER
|
---|
| 53 | #include "UnitTestMain.hpp"
|
---|
| 54 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 55 |
|
---|
| 56 | /********************************************** Test classes **************************************/
|
---|
| 57 |
|
---|
| 58 | const std::string resultstring="\
|
---|
| 59 | \n\
|
---|
[306f60] | 60 | HOMO is 5 A = -0.498625\n\
|
---|
| 61 | LUMO is 6 A = 0.251360\n\
|
---|
[cc276e] | 62 | \n\
|
---|
[306f60] | 63 | total scf energy = -75.5133625967\n\
|
---|
| 64 | \n\
|
---|
| 65 | Memory used for integral intermediates: 56628 Bytes\n\
|
---|
| 66 | \n\
|
---|
| 67 | 10 -0.02171957 3 A 3 A -> 6 A 6 A (+-+-)\n\
|
---|
| 68 | \n\
|
---|
| 69 | RHF energy [au]: -75.513362596662\n\
|
---|
| 70 | MP2 correlation energy [au]: -0.124136686358\n\
|
---|
| 71 | MP2 energy [au]: -75.637499283020\n\
|
---|
| 72 | \n\
|
---|
| 73 | D1(MP2) = 0.01063314\n\
|
---|
| 74 | \n\
|
---|
| 75 | CPHF: iter = 7 rms(P) = 0.0000000011 eps = 0.0000000100\n\
|
---|
| 76 | \n\
|
---|
| 77 | Total MP2 gradient [au]:\n\
|
---|
| 78 | 1 O 0.1100072224 0.0000000000 -0.0000000000\n\
|
---|
| 79 | 2 H -0.0550036112 -0.0000000000 -0.1562140155\n\
|
---|
| 80 | 3 H -0.0550036112 -0.0000000000 0.1562140155\n\
|
---|
| 81 | \n\
|
---|
| 82 | Value of the MolecularEnergy: -75.6374992830\n\
|
---|
[cc276e] | 83 | \n\
|
---|
| 84 | ";
|
---|
| 85 |
|
---|
| 86 | // Registers the fixture into the 'registry'
|
---|
| 87 | CPPUNIT_TEST_SUITE_REGISTRATION( MPQCCommandJobTest );
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 | void MPQCCommandJobTest::setUp()
|
---|
| 91 | {
|
---|
| 92 | // Throw assertions
|
---|
| 93 | ASSERT_DO(Assert::Throw);
|
---|
| 94 |
|
---|
[306f60] | 95 | setVerbosity(4);
|
---|
[cc276e] | 96 |
|
---|
| 97 | job = new MPQCCommandJob(std::string("empty"), 1);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 |
|
---|
| 101 | void MPQCCommandJobTest::tearDown()
|
---|
| 102 | {
|
---|
| 103 | delete job;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | /** UnitTest for extractString()
|
---|
| 107 | */
|
---|
| 108 | void MPQCCommandJobTest::extractStringTest()
|
---|
| 109 | {
|
---|
| 110 | // prepare result container
|
---|
| 111 | MPQCData data;
|
---|
[a9558f] | 112 | data.energies.total = -75.637499283020;
|
---|
[cc276e] | 113 | std::vector<double> force;
|
---|
| 114 | std::vector< std::vector<double> > forces;
|
---|
[306f60] | 115 | // 1 O 0.1100072224 0.0000000000 -0.0000000000
|
---|
| 116 | force.push_back(0.1100072224);
|
---|
| 117 | force.push_back(0.0000000000);
|
---|
| 118 | force.push_back(-0.0000000000);
|
---|
| 119 | data.forces.push_back( force );
|
---|
| 120 | // 2 H -0.0550036112 -0.0000000000 -0.1562140155
|
---|
| 121 | force.clear();
|
---|
| 122 | force.push_back(-0.0550036112);
|
---|
| 123 | force.push_back(-0.0000000000);
|
---|
| 124 | force.push_back(-0.1562140155);
|
---|
[cc276e] | 125 | data.forces.push_back( force );
|
---|
[306f60] | 126 | // 3 H -0.0550036112 -0.0000000000 0.1562140155
|
---|
[cc276e] | 127 | force.clear();
|
---|
[306f60] | 128 | force.push_back(-0.0550036112);
|
---|
| 129 | force.push_back(-0.0000000000);
|
---|
| 130 | force.push_back(0.1562140155);
|
---|
[cc276e] | 131 | data.forces.push_back( force );
|
---|
| 132 |
|
---|
| 133 | // extract and check
|
---|
| 134 | FragmentResult::ptr result = job->extractResult(resultstring);
|
---|
| 135 | std::stringstream returnstream(result->result);
|
---|
| 136 |
|
---|
| 137 | // deserialize
|
---|
| 138 | MPQCData extractedData;
|
---|
| 139 | boost::archive::text_iarchive ia(returnstream);
|
---|
| 140 | ia >> extractedData;
|
---|
| 141 |
|
---|
| 142 | CPPUNIT_ASSERT( data == extractedData );
|
---|
| 143 | }
|
---|
[545446] | 144 |
|
---|
| 145 | /** UnitTest for operator==()
|
---|
| 146 | */
|
---|
| 147 | void MPQCCommandJobTest::operatorTest()
|
---|
| 148 | {
|
---|
| 149 | MPQCCommandJob otherJob(std::string("empty"), 1);
|
---|
| 150 |
|
---|
| 151 | // ascertain equality
|
---|
| 152 | CPPUNIT_ASSERT( *job == otherJob );
|
---|
| 153 |
|
---|
| 154 | // parse results
|
---|
| 155 | FragmentResult::ptr result = job->extractResult(resultstring);
|
---|
| 156 |
|
---|
| 157 | // ascertain unequality as now data should differ
|
---|
| 158 | CPPUNIT_ASSERT( *job != otherJob );
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | /** UnitTest for serialization
|
---|
| 162 | */
|
---|
| 163 | void MPQCCommandJobTest::serializationTest()
|
---|
| 164 | {
|
---|
| 165 | // parse results
|
---|
| 166 | FragmentResult::ptr result = job->extractResult(resultstring);
|
---|
| 167 |
|
---|
| 168 | // serialize
|
---|
| 169 | std::stringstream outputstream;
|
---|
| 170 | boost::archive::text_oarchive oa(outputstream);
|
---|
| 171 | oa << job;
|
---|
| 172 |
|
---|
| 173 | // deserialize
|
---|
| 174 | MPQCCommandJob *extractedJob;
|
---|
| 175 | std::stringstream returnstream(outputstream.str());
|
---|
| 176 | boost::archive::text_iarchive ia(returnstream);
|
---|
| 177 | ia >> extractedJob;
|
---|
| 178 |
|
---|
| 179 | CPPUNIT_ASSERT( *job == *extractedJob );
|
---|
| 180 |
|
---|
| 181 | delete extractedJob;
|
---|
| 182 | }
|
---|