File: EnergyProcessor_test.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 239,848 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; makefile: 93
file content (134 lines) | stat: -rw-r--r-- 2,917 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#include <BALL/CONCEPT/classTest.h>
#include <BALLTestConfig.h>

///////////////////////////
#include <BALL/CONCEPT/processor.h>
#include <BALL/FORMAT/HINFile.h>
#include <BALL/KERNEL/system.h>
#include <BALL/ENERGY/energyProcessor.h>
///////////////////////////

START_TEST(EnergyProcessor)

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

using namespace BALL;


/** Test class.
 * 	The energy is calculated as:
 * 	(fragment_.countAtomContainers() + 1) * fragment_.countAtoms()
 * 	The additive 1 comes from the fact that countAtomContainers() does not
 * 	count the container from which it was called while operator () () runs
 * 	over *all* containers including the System which it was applied to.
 */
 class MyEnergyProcessor
	: public EnergyProcessor
{
	public:
		
	MyEnergyProcessor()
		: count(0)
	{
	}
		
	virtual bool start() throw()
	{
		count = 0;
		return true;
	}

	virtual Processor::Result operator () (AtomContainer& fragment) throw()
	{
		count++;
		EnergyProcessor::operator() (fragment);
		return BALL::Processor::CONTINUE;
	}
	
	virtual bool finish() throw()
	{
		energy_ = fragment_->countAtoms() * count;
		return true;
	}

	Size count;
};

HINFile f(BALL_TEST_DATA_PATH(AnisotropyShiftProcessor_test.hin));
System S;
f >> S;

EnergyProcessor* ep_ptr = 0;

CHECK(EnergyProcessor::EnergyProcessor())
	ep_ptr = new EnergyProcessor;
	TEST_NOT_EQUAL(ep_ptr, 0)
	TEST_EQUAL(ep_ptr->isValid(), true)
	TEST_REAL_EQUAL(ep_ptr->getEnergy(), 0)
RESULT

CHECK(EnergyProcessor::~EnergyProcessor())
	delete ep_ptr;
RESULT

bool test = false;

CHECK(EnergyProcessor::EnergyProcessor(const EnergyProcessor& proc))
	EnergyProcessor ep;
	EnergyProcessor ep2(ep);
	test = (ep == ep2);
	TEST_EQUAL(test, true)
RESULT

CHECK(EnergyProcessor::clear())
	EnergyProcessor ep1;
  ep1.clear();
	EnergyProcessor ep2;
	test = (ep1 == ep2);
	TEST_EQUAL(test, true)
RESULT


CHECK(EnergyProcessor::EnergyProcessor& operator = (const EnergyProcessor& proc))
	Fragment fragment;
	EnergyProcessor ep1;
	EnergyProcessor ep2 = ep1;
	test = (ep1 == ep2);
	TEST_EQUAL(test, true)
RESULT


CHECK(EnergyProcessor::start())
	EnergyProcessor ep;
	TEST_EQUAL(ep.start(), true)
RESULT


CHECK(EnergyProcessor::Processor::Result operator () (BaseFragment& fragment))
	EnergyProcessor ep;
  TEST_EQUAL(S.apply(ep), true)
RESULT


CHECK(EnergyProcessor::getEnergy() const )
	EnergyProcessor ep;
  TEST_REAL_EQUAL(ep.getEnergy(), 0)
RESULT


CHECK(apply)
	MyEnergyProcessor mep;
	TEST_EQUAL(S.apply(mep), true)
	TEST_EQUAL(S.countAtoms(), 31)
	TEST_EQUAL(S.countAtomContainers(), 5)
	TEST_REAL_EQUAL(mep.getEnergy(), S.countAtoms() * (S.countAtomContainers() + 1))
RESULT

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST