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, 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 (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; }