TEST(CompositeGraphics, addingTwoChildrenAndGetBoundingBox) { CompositeGraphics g; g.add(new SimpleGraphics(new Circle(0,0,1))); g.add(new SimpleGraphics(new Square(-2,-2,2))); LONGS_EQUAL(-2,g.getBoundingBox().llx()); LONGS_EQUAL(-2,g.getBoundingBox().lly()); LONGS_EQUAL(1,g.getBoundingBox().urx()); LONGS_EQUAL(1,g.getBoundingBox().ury()); }
TEST (DescVisitor, CompositeGraphics) { CompositeGraphics g; g.add(new SimpleGraphics(new Circle(0,0,1))); g.add(new SimpleGraphics(new Square(-2,-2,2))); DescriptionVisitor dv; g.accept(dv); std::string ans("Comp R(-2,-2,3,3)\n"); ans += std::string(" C(0,0,1)\n"); ans += std::string(" S(-2,-2,2)\n"); CHECK(ans==dv.getDescription()); // std::cout << dv.getDescription() << std::endl; }
TEST(AreaVisitor, derivedFromGraphicsVisitor) { CompositeGraphics g; g.add(new SimpleGraphics(new Circle(0,0,1))); g.add(new SimpleGraphics(new Square(-2,-2,2))); SimpleGraphics r(new Rectangle (-1,-1,1,3)); CompositeGraphics h; h.add(&g); h.add(&r); GraphicsVisitor * av = new AreaVisitor; h.accept(*av); LONGS_EQUAL(10, static_cast<AreaVisitor *>(av)->area()); }
TEST(CompositeGraphics, SimpleAndCompositeChildrenAndGetBoundingBox) { CompositeGraphics g; SimpleGraphics r(new Rectangle (-1,-1,1,3)); g.add(new SimpleGraphics(new Circle(0,0,1))); g.add(new SimpleGraphics(new Square(-2,-2,2))); CompositeGraphics h; h.add(&g); h.add(&r); LONGS_EQUAL(-2,h.getBoundingBox().llx()); LONGS_EQUAL(-2,h.getBoundingBox().lly()); LONGS_EQUAL(1,h.getBoundingBox().urx()); LONGS_EQUAL(2,h.getBoundingBox().ury()); }
void UnGroupCommand::unexecute(){ for(Graphics* sha : shapeHasBeenSelected){ removeSpecifiedElementInShapes(sha); } CompositeGraphics *com = dynamic_cast<CompositeGraphics*>(this->group); for(Graphics* selectedSha : shapeHasBeenSelected){ com->add(selectedSha); } shapes->push_back(com); }
TEST(CompositeGraphics, addingOneChild) { CompositeGraphics g; try { g.add(new SimpleGraphics(new Circle(0,0,2))); } catch (std::string s) { FAIL("Should not throw exception"); } LONGS_EQUAL(16,g.getBoundingBox().area()); }
TEST (AreaVisitor, Composite) { CompositeGraphics g; g.add(new SimpleGraphics(new Circle(0,0,1))); g.add(new SimpleGraphics(new Square(-2,-2,2))); AreaVisitor av; g.accept(av); LONGS_EQUAL(7,av.area()); SimpleGraphics r(new Rectangle (-1,-1,1,3)); CompositeGraphics h; h.add(&g); h.add(&r); AreaVisitor av2; h.accept(av2); LONGS_EQUAL(10,av2.area()); }
TEST (DescVisitor, CompositeGraphicsWithComposite) { CompositeGraphics g; g.add(new SimpleGraphics(new Circle(0,0,1))); g.add(new SimpleGraphics(new Square(-2,-2,2))); SimpleGraphics r(new Rectangle (-1,-1,1,3)); CompositeGraphics h; h.add(&g); h.add(&r); DescriptionVisitor dv; h.accept(dv); std::string ans("Comp R(-2,-2,3,4)\n"); ans += std::string(" Comp R(-2,-2,3,3)\n"); ans += std::string(" C(0,0,1)\n"); ans += std::string(" S(-2,-2,2)\n"); ans += std::string(" R(-1,-1,1,3)\n"); CHECK(ans==dv.getDescription()); // std::cout << dv.getDescription() << std::endl; }