void PartsTest::test_Box() { Position pos(0.0, 1.0, 2.0); Size sz(3.0, 4.0, 5.0); BoxParts box("box", pos, sz); Parts &parts = box; int n; char *data= parts.toBinary(n); ASSERT(data != NULL); { CParts * d = CParts::decode(data+2); ASSERT(d != NULL); ASSERT(strcmp(d->name(), "box") == 0); ASSERT(box.getType() == d->getType()); BoxPartsCmpnt *ext = (BoxPartsCmpnt*)( d->extdata()); ASSERT(ext != NULL); Size &sz_ = ext->size(); ASSERT_D_EQUAL(sz_.x(), sz.x(), EPS); ASSERT_D_EQUAL(sz_.y(), sz.y(), EPS); ASSERT_D_EQUAL(sz_.z(), sz.z(), EPS); delete d; } { // clone test CParts *clone = ( (CParts&)box ).clone(); ASSERT(clone != NULL); ASSERT(strcmp(clone->name(), "box") == 0); ASSERT(box.getType() == clone->getType()); BoxPartsCmpnt *ext = (BoxPartsCmpnt*)( clone->extdata()); ASSERT(ext != NULL); Size &sz_ = ext->size(); ASSERT_D_EQUAL(sz_.x(), sz.x(), EPS); ASSERT_D_EQUAL(sz_.y(), sz.y(), EPS); ASSERT_D_EQUAL(sz_.z(), sz.z(), EPS); delete clone; } }
void PartsTest::test_Sphere() { Position pos(0.0, 1.0, 2.0); const double RADIUS = 5.0; SphereParts sphere("sphere", pos, RADIUS); Parts &parts = sphere; int n; char *data = parts.toBinary(n); ASSERT(data != NULL); { CParts * d = CParts::decode(data+2); ASSERT(d != NULL); ASSERT(strcmp(d->name(), "sphere") == 0); ASSERT(sphere.getType() == d->getType()); SpherePartsCmpnt *ext = (SpherePartsCmpnt*)d->extdata(); ASSERT(ext != NULL); ASSERT_D_EQUAL(RADIUS, ext->radius(), EPS); delete d; } { CParts *clone = ( (CParts&)parts ).clone(); ASSERT(clone != NULL); ASSERT(strcmp(clone->name(), "sphere") == 0); ASSERT(sphere.getType() == clone->getType()); SpherePartsCmpnt *ext = (SpherePartsCmpnt*)clone->extdata(); ASSERT(ext != NULL); ASSERT_D_EQUAL(RADIUS, ext->radius(), EPS); delete clone; } }
void PartsTest::test_Cylinder() { Position pos(0.0, 1.0, 2.0); double rad = 0.1; double len = 1.5; CylinderParts cylinder("cylinder", pos, rad, len); Parts &parts = cylinder; int n; char *data= parts.toBinary(n); ASSERT(data != NULL); CParts * d = CParts::decode(data+2); ASSERT(d != NULL); ASSERT(strcmp(d->name(), "cylinder") == 0); ASSERT(cylinder.getType() == d->getType()); CylinderPartsCmpnt *ext = (CylinderPartsCmpnt*)( d->extdata()); ASSERT(ext != NULL); ASSERT_D_EQUAL(rad, ext->radius(), EPS); ASSERT_D_EQUAL(len, ext->length(), EPS); delete d; }