@@ -41,16 +41,39 @@ class TestPQEvaluator : public CxxTest::TestSuite
4141{
4242 private:
4343
44+ // data
4445 EpsilonEqual allclose;
46+ PDFCalculator mpdfcb;
47+ PDFCalculator mpdfco;
48+ QuantityType mzeros;
4549 AtomicStructureAdapterPtr mstru10;
4650 AtomicStructureAdapterPtr mstru10d1;
4751 AtomicStructureAdapterPtr mstru10r;
4852 AtomicStructureAdapterPtr mstru9;
4953
54+ // methods
55+ QuantityType pdfcdiff (StructureAdapterPtr stru)
56+ {
57+ mpdfcb.eval (stru);
58+ mpdfco.eval (stru);
59+ QuantityType gb = mpdfcb.getPDF ();
60+ QuantityType go = mpdfco.getPDF ();
61+ assert (mpdfcb.getRgrid () == mpdfco.getRgrid ());
62+ QuantityType rv (gb.size ());
63+ transform (gb.begin (), gb.end (), go.begin (),
64+ rv.begin (), minus<double >());
65+ return rv;
66+ }
67+
5068 public:
5169
5270 void setUp ()
5371 {
72+ // setup PDFCalculator instances and the zero vector for comparison
73+ mpdfcb.setEvaluatorType (BASIC);
74+ mpdfco.setEvaluatorType (OPTIMIZED);
75+ mzeros.assign (mpdfcb.getRgrid ().size (), 0.0 );
76+ // setup structure instances
5477 const int SZ = 10 ;
5578 mstru10 = boost::make_shared<AtomicStructureAdapter>();
5679 Atom ai;
@@ -74,80 +97,51 @@ class TestPQEvaluator : public CxxTest::TestSuite
7497
7598 void test_PDF_change_atom ()
7699 {
77- PDFCalculator pdfcb ;
78- PDFCalculator pdfco ;
79- pdfcb. setEvaluatorType (BASIC );
80- pdfco. setEvaluatorType (OPTIMIZED );
81- TS_ASSERT_EQUALS (NONE, pdfcb. getEvaluatorTypeUsed ( ));
82- TS_ASSERT_EQUALS (NONE, pdfco. getEvaluatorTypeUsed ());
83- pdfcb. eval (mstru10 );
84- pdfco. eval (mstru10 );
85- QuantityType gb = pdfcb. getPDF ();
86- QuantityType go = pdfco .getPDF ();
100+ TS_ASSERT_EQUALS (BASIC, mpdfcb. getEvaluatorType ()) ;
101+ TS_ASSERT_EQUALS (OPTIMIZED, mpdfco. getEvaluatorType ()) ;
102+ TS_ASSERT_EQUALS (NONE, mpdfcb. getEvaluatorTypeUsed () );
103+ TS_ASSERT_EQUALS (NONE, mpdfco. getEvaluatorTypeUsed () );
104+ TS_ASSERT_EQUALS (mzeros, this -> pdfcdiff (mstru10 ));
105+ // first call of mpdfco should use the BASIC evaluation
106+ TS_ASSERT_EQUALS (BASIC, mpdfcb. getEvaluatorTypeUsed () );
107+ TS_ASSERT_EQUALS (BASIC, mpdfco. getEvaluatorTypeUsed () );
108+ // verify there are some non-zero values in the PDF.
109+ QuantityType gb = mpdfcb .getPDF ();
87110 TS_ASSERT (!gb.empty ());
88- TS_ASSERT_EQUALS (gb, go);
89111 int cnonzero = count_if (gb.begin (), gb.end (),
90112 bind1st (not_equal_to<double >(), 0.0 ));
91113 TS_ASSERT (cnonzero);
92- TS_ASSERT_EQUALS (BASIC, pdfcb.getEvaluatorType ());
93- TS_ASSERT_EQUALS (OPTIMIZED, pdfco.getEvaluatorType ());
94- // first call of pdfco should use the BASIC evaluation
95- TS_ASSERT_EQUALS (BASIC, pdfcb.getEvaluatorTypeUsed ());
96- TS_ASSERT_EQUALS (BASIC, pdfco.getEvaluatorTypeUsed ());
97114 // test second call on the same structure
98- pdfco.eval (mstru10);
99- go = pdfco.getPDF ();
100- TS_ASSERT_EQUALS (gb, go);
101- TS_ASSERT_EQUALS (OPTIMIZED, pdfco.getEvaluatorTypeUsed ());
115+ mpdfco.eval (mstru10);
116+ TS_ASSERT_EQUALS (gb, mpdfco.getPDF ());
117+ TS_ASSERT_EQUALS (OPTIMIZED, mpdfco.getEvaluatorTypeUsed ());
102118 // test structure with one different atom
103- pdfcb.eval (mstru10d1);
104- pdfco.eval (mstru10d1);
105- QuantityType gb1 = pdfcb.getPDF ();
106- QuantityType go1 = pdfco.getPDF ();
119+ TS_ASSERT (allclose (mzeros, this ->pdfcdiff (mstru10d1)));
120+ TS_ASSERT_EQUALS (OPTIMIZED, mpdfco.getEvaluatorTypeUsed ());
121+ QuantityType gb1 = mpdfcb.getPDF ();
107122 TS_ASSERT (!allclose (gb, gb1));
108- TS_ASSERT_EQUALS (OPTIMIZED, pdfco.getEvaluatorTypeUsed ());
109- TS_ASSERT (allclose (gb1, go1));
110123 // change position of 1 atom
111124 mstru10d1->at (0 ).xyz_cartn [1 ] = 0.5 ;
112- pdfcb.eval (mstru10d1);
113- pdfco.eval (mstru10d1);
114- QuantityType gb2 = pdfcb.getPDF ();
115- QuantityType go2 = pdfco.getPDF ();
125+ TS_ASSERT (allclose (mzeros, this ->pdfcdiff (mstru10d1)));
126+ TS_ASSERT_EQUALS (OPTIMIZED, mpdfco.getEvaluatorTypeUsed ());
127+ QuantityType gb2 = mpdfcb.getPDF ();
116128 TS_ASSERT (!allclose (gb1, gb2));
117- TS_ASSERT_EQUALS (OPTIMIZED, pdfco.getEvaluatorTypeUsed ());
118- TS_ASSERT (allclose (gb2, go2));
119129 }
120130
121131
122132 void test_PDF_reverse_atoms ()
123133 {
124- PDFCalculator pdfcb;
125- PDFCalculator pdfco;
126- pdfcb.setEvaluatorType (BASIC);
127- pdfco.setEvaluatorType (OPTIMIZED);
128- pdfcb.eval (mstru10);
129- pdfco.eval (mstru10);
130- pdfco.eval (mstru10r);
131- QuantityType gb = pdfcb.getPDF ();
132- QuantityType go = pdfco.getPDF ();
133- TS_ASSERT_EQUALS (OPTIMIZED, pdfco.getEvaluatorTypeUsed ());
134- TS_ASSERT (allclose (gb, go));
134+ mpdfco.eval (mstru10);
135+ TS_ASSERT (allclose (mzeros, this ->pdfcdiff (mstru10r)));
136+ TS_ASSERT_EQUALS (OPTIMIZED, mpdfco.getEvaluatorTypeUsed ());
135137 }
136138
137139
138140 void test_PDF_remove_atom ()
139141 {
140- PDFCalculator pdfcb;
141- PDFCalculator pdfco;
142- pdfcb.setEvaluatorType (BASIC);
143- pdfco.setEvaluatorType (OPTIMIZED);
144- pdfcb.eval (mstru9);
145- pdfco.eval (mstru10);
146- pdfco.eval (mstru9);
147- QuantityType gb = pdfcb.getPDF ();
148- QuantityType go = pdfco.getPDF ();
149- TS_ASSERT_EQUALS (OPTIMIZED, pdfco.getEvaluatorTypeUsed ());
150- TS_ASSERT (allclose (gb, go));
142+ mpdfco.eval (mstru10);
143+ TS_ASSERT (allclose (mzeros, this ->pdfcdiff (mstru9)));
144+ TS_ASSERT_EQUALS (OPTIMIZED, mpdfco.getEvaluatorTypeUsed ());
151145 }
152146
153147
0 commit comments