public void CountNumberOfElementsInObjectStructure() { var sut = new CountVisitor(); var objectStructure = new Element( new Element( new ElementWithLink( new Element(new Element(new ElementWithLink(new Element(null), new Element(null)))), new Element(new Element(new Element(null)))))); sut.CountElements(objectStructure); Assert.That(sut.Count, Is.EqualTo(9), "elements"); }
public void Visit(Element element) { Count++; }
public void CountElements(Element element) { element.Accept(this); if (element.Link != null) CountElements(element.Link); if (element.Next != null) CountElements(element.Next); }