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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#include <BALL/CONCEPT/classTest.h>
#include <BALLTestConfig.h>
///////////////////////////
#include <BALL/KERNEL/PTE.h>
#include "ItemCollector.h"
///////////////////////////
START_TEST(Element)
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
using namespace BALL;
// tests for Element
Element* e;
CHECK(Element() throw())
e = new Element;
TEST_NOT_EQUAL(e, 0)
RESULT
CHECK(~Element() throw())
delete e;
RESULT
CHECK(Element(const Element& element) throw())
Element* e1 = new Element;
e1->setName("testname");
Element* e2 = new Element(*e1);
TEST_NOT_EQUAL(e2, 0)
if (e2 != 0)
{
TEST_EQUAL(e2->getName(), "testname")
delete e2;
}
delete e1;
RESULT
CHECK(Element(const String& name, const String& symbol, Group group, Period period, AtomicNumber atomic_umber, float atomic_weight, float atomic_radius, float covalent_radius, float van_der_waals_radius, float electronegativity) throw())
Element static_element("Aluminum", "Al", 13, 3, 13, 26.981539, 1.43, 1.25, 2.05, true, 1.61);
TEST_EQUAL(static_element.getName(), "Aluminum")
TEST_EQUAL(static_element.getSymbol(), "Al")
TEST_EQUAL(static_element.getGroup(), 13)
TEST_EQUAL(static_element.getPeriod(), 3)
TEST_EQUAL(static_element.getAtomicNumber(), 13)
TEST_REAL_EQUAL(static_element.getAtomicWeight(), 26.9815390)
TEST_REAL_EQUAL(static_element.getAtomicRadius(), 1.43)
TEST_REAL_EQUAL(static_element.getCovalentRadius(), 1.25)
TEST_REAL_EQUAL(static_element.getVanDerWaalsRadius(), 2.05)
TEST_EQUAL(static_element.isMetal(), true)
TEST_REAL_EQUAL(static_element.getElectronegativity(), 1.61)
Element* e1 = new Element("e1", "id", 2, 3, 25, 25.0, 2.0, 3.0, 4.0, false, 5.0);
TEST_NOT_EQUAL(e1, 0)
if (e1 != 0)
{
TEST_EQUAL(e1->getName(), "e1")
TEST_EQUAL(e1->getSymbol(), "id")
TEST_EQUAL(e1->getGroup(), 2)
TEST_EQUAL(e1->getPeriod(), 3)
TEST_EQUAL(e1->getAtomicNumber(), 25)
TEST_EQUAL(e1->getAtomicWeight(), 25.0)
TEST_EQUAL(e1->getAtomicRadius(), 2.0)
TEST_EQUAL(e1->getCovalentRadius(), 3.0)
TEST_EQUAL(e1->getVanDerWaalsRadius(), 4.0)
TEST_EQUAL(e1->isMetal(), false)
TEST_EQUAL(e1->getElectronegativity(), 5.0)
}
Element* e2 = new Element(*e1);
TEST_NOT_EQUAL(e2, 0)
if (e2 != 0)
{
TEST_EQUAL(e2->getName(), "e1")
TEST_EQUAL(e2->getSymbol(), "id")
TEST_EQUAL(e2->getGroup(), 2)
TEST_EQUAL(e2->getPeriod(), 3)
TEST_EQUAL(e2->getAtomicNumber(), 25)
TEST_EQUAL(e2->getAtomicWeight(), 25.0)
TEST_EQUAL(e2->getAtomicRadius(), 2.0)
TEST_EQUAL(e2->getCovalentRadius(), 3.0)
TEST_EQUAL(e2->getVanDerWaalsRadius(), 4.0)
TEST_EQUAL(e2->isMetal(), false)
TEST_EQUAL(e2->getElectronegativity(), 5.0)
delete e2;
}
delete e1;
RESULT
Element e1;
Element e2;
Element e3;
CHECK(void setName(const String& name) throw())
e1.setName("e1");
RESULT
CHECK(const String& getName() const throw())
TEST_EQUAL(e1.getName(), "e1")
TEST_EQUAL(e2.getName(), "Unknown")
RESULT
CHECK(void setSymbol(const String& symbol) throw())
e1.setSymbol("s");
RESULT
CHECK(const String& getSymbol() const throw())
TEST_EQUAL(e1.getSymbol(), "s")
TEST_EQUAL(e2.getSymbol(), "?")
RESULT
CHECK(void setGroup(Group group) throw())
e1.setGroup(2);
RESULT
CHECK(Group getGroup() const throw())
TEST_EQUAL(e1.getGroup(), 2)
TEST_EQUAL(e2.getGroup(), 0)
RESULT
CHECK(void setPeriod(Period period) throw())
e1.setPeriod(3);
RESULT
CHECK(Period getPeriod() const throw())
TEST_EQUAL(e1.getPeriod(), 3)
TEST_EQUAL(e2.getPeriod(), 0)
RESULT
CHECK(void setAtomicNumber(AtomicNumber atomic_number) throw())
e1.setAtomicNumber(4);
RESULT
CHECK(AtomicNumber getAtomicNumber() const throw())
TEST_EQUAL(e1.getAtomicNumber(), 4)
TEST_EQUAL(e2.getAtomicNumber(), 0)
RESULT
CHECK(void setAtomicWeight(float atomic_weight) throw())
e1.setAtomicWeight(5.0);
RESULT
CHECK(float getAtomicWeight() const throw())
TEST_EQUAL(e1.getAtomicWeight(), 5.0)
TEST_EQUAL(e2.getAtomicWeight(), 0.0)
RESULT
CHECK(void setAtomicRadius(float atomic_radius) throw())
e1.setAtomicRadius(6.0);
RESULT
CHECK(float getAtomicRadius() const throw())
TEST_EQUAL(e1.getAtomicRadius(), 6.0)
TEST_EQUAL(e2.getAtomicRadius(), 0.0)
RESULT
CHECK(void setCovalentRadius(float covalent_radius) throw())
e1.setCovalentRadius(7.0);
RESULT
CHECK(float getCovalentRadius() const throw())
TEST_EQUAL(e1.getCovalentRadius(), 7.0)
TEST_EQUAL(e2.getCovalentRadius(), 0.0)
RESULT
CHECK(void setVanDerWaalsRadius(float van_der_waals_radius) throw())
e1.setVanDerWaalsRadius(8.0);
RESULT
CHECK(float getVanDerWaalsRadius() const throw())
TEST_EQUAL(e1.getVanDerWaalsRadius(), 8.0)
TEST_EQUAL(e2.getVanDerWaalsRadius(), 0.0)
RESULT
CHECK(void setElectronegativity(float electronegativity) throw())
e1.setElectronegativity(9.0);
RESULT
CHECK(float getElectronegativity() const throw())
TEST_EQUAL(e1.getElectronegativity(), 9.0)
TEST_EQUAL(e2.getElectronegativity(), 0.0)
RESULT
CHECK(bool operator == (const Element& element) const throw())
TEST_EQUAL(e1 == e2, false)
TEST_EQUAL(e3 == e2, true)
RESULT
CHECK(bool operator != (const Element& element) const throw())
TEST_EQUAL(e3 != e1, true)
TEST_EQUAL(e3 != e2, false)
RESULT
CHECK(bool operator < (const Element& element) const throw())
TEST_EQUAL(e2 < e1, true)
TEST_EQUAL(e2 < e3, false)
RESULT
CHECK(bool operator <= (const Element& element) const throw())
TEST_EQUAL(e1 <= e2, false)
TEST_EQUAL(e3 <= e2, true)
TEST_EQUAL(e2 <= e1, true)
RESULT
CHECK(bool operator >= (const Element& element) const throw())
TEST_EQUAL(e2 >= e1, false)
TEST_EQUAL(e1 >= e2, true)
TEST_EQUAL(e2 >= e2, true)
RESULT
CHECK(bool operator >(const Element& element) const throw())
TEST_EQUAL(e2 > e1, false)
TEST_EQUAL(e1 > e2, true)
TEST_EQUAL(e2 > e3, false)
RESULT
CHECK(bool isUnknown() const throw())
TEST_EQUAL(e1.isUnknown(), false)
TEST_EQUAL(e2.isUnknown(), true)
RESULT
CHECK(BALL_CREATE(Element))
// Not to be tested
RESULT
CHECK(Element& operator = (const Element& element) throw())
Element rhs1("Aluminum", "Al", 13, 3, 13, 26.981539, 1.43, 1.25, 2.05, true, 1.61);
Element el;
el = rhs1;
TEST_EQUAL(el.getName(), "Aluminum")
TEST_EQUAL(el.getSymbol(), "Al")
TEST_EQUAL(el.getGroup(), 13)
TEST_EQUAL(el.getPeriod(), 3)
TEST_EQUAL(el.getAtomicNumber(), 13)
TEST_REAL_EQUAL(el.getAtomicWeight(), 26.9815390)
TEST_REAL_EQUAL(el.getAtomicRadius(), 1.43)
TEST_REAL_EQUAL(el.getCovalentRadius(), 1.25)
TEST_REAL_EQUAL(el.getVanDerWaalsRadius(), 2.05)
TEST_EQUAL(el.isMetal(), true)
TEST_REAL_EQUAL(el.getElectronegativity(), 1.61)
Element rhs2("ALUMINUM", "lA", 31, 5, 26, 27.333333, 2.45, 7.89, 1.12, true, 3.67);
el = rhs2;
TEST_EQUAL(el.getName(), rhs2.getName())
TEST_EQUAL(el.getSymbol(), rhs2.getSymbol())
TEST_EQUAL(el.getGroup(), rhs2.getGroup())
TEST_EQUAL(el.getPeriod(), rhs2.getPeriod())
TEST_EQUAL(el.getAtomicNumber(), rhs2.getAtomicNumber())
TEST_EQUAL(el.getAtomicWeight(), rhs2.getAtomicWeight())
TEST_EQUAL(el.getAtomicRadius(), rhs2.getAtomicRadius())
TEST_EQUAL(el.getCovalentRadius(), rhs2.getCovalentRadius())
TEST_EQUAL(el.getVanDerWaalsRadius(), rhs2.getVanDerWaalsRadius())
TEST_EQUAL(el.isMetal(), rhs2.isMetal())
TEST_EQUAL(el.getElectronegativity(), rhs2.getElectronegativity())
RESULT
String filename;
NEW_TMP_FILE(filename)
CHECK(friend std::ostream& operator << (std::ostream& s, const Element& element) throw())
std::ofstream outstr(filename.c_str(), std::ios::out);
outstr << e1;
outstr.close();
TEST_FILE(filename.c_str(), BALL_TEST_DATA_PATH(PTE_test.txt))
RESULT
// test for PTE_:
CHECK(static Element& getElement(Position position) throw())
TEST_EQUAL(PTE.getElement(13).getName(), "Aluminum")
TEST_EQUAL(PTE.getElement(13).getSymbol(), "Al")
TEST_EQUAL(PTE.getElement(13).getGroup(), 13)
TEST_EQUAL(PTE.getElement(13).getPeriod(), 3)
TEST_EQUAL(PTE.getElement(13).getAtomicNumber(), 13)
TEST_REAL_EQUAL(PTE.getElement(13).getAtomicWeight(), 26.9815390)
TEST_REAL_EQUAL(PTE.getElement(13).getAtomicRadius(), 1.43)
TEST_REAL_EQUAL(PTE.getElement(13).getCovalentRadius(), 1.25)
TEST_REAL_EQUAL(PTE.getElement(13).getVanDerWaalsRadius(), 2.05)
TEST_EQUAL(PTE.getElement(13).isMetal(), true)
TEST_REAL_EQUAL(PTE.getElement(13).getElectronegativity(), 1.61)
RESULT
CHECK(static Element& getElement(const String& symbol) throw())
TEST_EQUAL(PTE["B"].getName(), "Boron")
RESULT
CHECK(Element& operator [] (const String& symbol) throw())
PTE_ p(PTE);
p["B"].setName("MyLovelyBoron2");
TEST_EQUAL(p[Element::BORON].getName(), "MyLovelyBoron2")
RESULT
CHECK(Element& operator [] (Element::Symbol symbol) throw())
PTE_ p(PTE);
p[Element::B].setName("MyLovelyBoron3");
TEST_EQUAL(p[Element::BORON].getName(), "MyLovelyBoron3")
RESULT
CHECK(Element& operator [] (Position position) throw())
PTE_ p(PTE);
p[1].setName("MyLovelyHydrogen1");
TEST_EQUAL(p[1].getName(), "MyLovelyHydrogen1")
RESULT
CHECK(static bool apply(UnaryProcessor<Element>& applicator) throw())
ItemCollector<Element> myproc;
PTE.apply(myproc);
TEST_EQUAL(myproc.getSize(), 112)
TEST_EQUAL(myproc.getPointer()->getName(), "Actinium")
RESULT
CHECK(PTE_& operator = (const PTE_& /*pte*/) throw())
PTE_ p1, p2;
p1 = p2;
RESULT
CHECK(bool operator == (const PTE_& pte) const throw())
PTE_ p1, p2;
TEST_EQUAL(p1 == p2, true)
RESULT
CHECK(void clear() throw())
PTE_ p1;
p1.clear();
RESULT
CHECK(BALL_CREATE(PTE_))
PTE_* ptr = (PTE_*) PTE.create(true, false);
TEST_EQUAL((*ptr)[13].getName(), "Aluminum")
delete ptr;
RESULT
PTE_* p_ptr;
CHECK(PTE_() throw())
p_ptr = new PTE_;
RESULT
CHECK(~PTE_() throw())
delete p_ptr;
RESULT
CHECK(PTE_(const PTE_& pse) throw())
PTE_ p(PTE);
TEST_EQUAL(p[13].getName(), "Aluminum")
RESULT
CHECK(Element& operator [] (Element::Name name) throw())
PTE_ p(PTE);
p[Element::BORON].setName("MyLovelyBoron");
TEST_EQUAL(p[Element::BORON].getName(), "MyLovelyBoron")
RESULT
CHECK(const Element& operator [] (Element::Name name) const throw())
TEST_EQUAL(PTE[Element::BORON].getName(), "MyLovelyBoron")
RESULT
CHECK(const Element& operator [] (Element::Symbol symbol) const throw())
TEST_EQUAL(PTE[Element::H].getName(), "MyLovelyHydrogen1")
RESULT
CHECK(const Element& operator [] (Position position) const throw())
TEST_EQUAL(PTE[1].getName(), "MyLovelyHydrogen1")
TEST_EQUAL(PTE[113].isUnknown(), true)
RESULT
CHECK(const Element& operator [] (const String& symbol) const throw())
TEST_EQUAL(PTE[Element::H].getName(), "MyLovelyHydrogen1")
RESULT
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST
|