void TestGuidanceControl::fullRigth() { InternalMessage("Model","Model::TestGuidanceControl::basicTest entering") ; /// we construct a complete system on a ship std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestGuidanceControl::basicTest")) ; /// should be a PhysicalWorld Kernel::Object* system = model->createObject() ; CPPUNIT_ASSERT(system->getTrait<PhysicalWorld>()) ; Kernel::Object* ship = system->createObject() ; ship->addTrait(new Positionned()) ; ship->addTrait(new Oriented()) ; ship->addTrait(new Mobile()) ; ship->addTrait(new Massive(Mass::Kilogram(1000))) ; CPPUNIT_ASSERT(ship->getTrait<PhysicalObject>()) ; Kernel::Object* stick = ship->createObject() ; stick->addTrait(new Stick()) ; Kernel::Object* guidance_system = ship->createObject() ; guidance_system->addTrait(new GuidanceSystem(1)) ; Kernel::Object* guidance_control = ship->createObject() ; guidance_control->addTrait(new GuidanceControler()) ; connectStickControler(stick,guidance_control) ; connectControlerGuidanceSystem(guidance_control,guidance_system) ; // 100 on yaw means go rigth stick->call("Yaw",100) ; stick->getTrait<Stick>()->updateOrientation() ; CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().x == 0) ; CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().z == 0) ; CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().y < 0) ; stick->call("Yaw",0) ; stick->getTrait<Stick>()->updateOrientation() ; CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().x == 0) ; CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().z == 0) ; CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().y == 0) ; // 100 on pitch measn go down stick->call("Pitch",100) ; stick->getTrait<Stick>()->updateOrientation() ; CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().x < 0) ; CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().z == 0) ; CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().y == 0) ; }
void TestLaser::beamEnergy() { InternalMessage("Model","Model::TestLaser::beamEnergy entering") ; // we construct a complete system std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestLaser::testFire")) ; model->init() ; // should be a PhysicalWorld Kernel::Object* system = model->createObject() ; CPPUNIT_ASSERT(system->getTrait<PhysicalWorld>()) ; Kernel::Object* ship = system->createObject() ; ship->addTrait(new Positionned()) ; ship->addTrait(new Oriented()) ; ship->addTrait(new Mobile()) ; ship->addTrait(new Massive(Mass::Kilogram(1000))) ; ship->addTrait(new Laser(Position(),Orientation(),Energy::Joule(10))) ; CPPUNIT_ASSERT(ship->getTrait<PhysicalObject>()) ; CPPUNIT_ASSERT(ship->getTrait<PhysicalWorld>()) ; CPPUNIT_ASSERT(system->getChildren().size()==1) ; InternalMessage("Model","built ship") ; ship->call("fire") ; InternalMessage("Model","fire") ; CPPUNIT_ASSERT(system->getDescendants<LaserBeam>().size()==1) ; CPPUNIT_ASSERT(system->getDescendants<Shot>().size()==1) ; std::set<LaserBeam*> beams = system->getDescendants<LaserBeam>() ; LaserBeam* beam = *(beams.begin()) ; CPPUNIT_ASSERT(beam->getEnergy().Joule()==10) ; }