public void SimpleAddition() { var simple = new AdditionExpression(new Value(2), new Value(3)); var ep = new ExpressionPrinter(); ep.Visit(simple); Assert.That(ep.ToString(), Is.EqualTo("(2+3)")); }
public static void Main(string[] args) { var e = new AdditionExpression( new DoubleExpression(1), new AdditionExpression( new DoubleExpression(2), new DoubleExpression(3))); var ep = new ExpressionPrinter(); ep.Visit(e); Console.WriteLine(ep); var calc = new ExpressionCalculator(); calc.Visit(e); Console.WriteLine($"{ep} = {calc.Result}"); Console.WriteLine("Taxi Visitor!"); CustomerStructure o = new CustomerStructure(); o.Attach(new TaxiCustomer("Andrzej")); o.Attach(new TaxiCustomer("Seba")); o.Attach(new TaxiCustomer("Pudzian")); o.Attach(new RichCustomer("Musk")); o.Attach(new PoorCustomer("Żul")); Taxi t1 = new Taxi1(); Taxi t2 = new Taxi2(); o.Accept(t1); Console.WriteLine(); o.Accept(t2); Console.WriteLine("Acyclic visitor"); var expression = new AcyclicVisitor.AdditionExpression( new AcyclicVisitor.DoubleExpression(1), new AcyclicVisitor.AdditionExpression( new AcyclicVisitor.DoubleExpression(2), new AcyclicVisitor.DoubleExpression(3))); var acyclic_ep = new AcyclicVisitor.ExpressionPrinter(); acyclic_ep.Visit(expression); Console.WriteLine(acyclic_ep.ToString()); Console.WriteLine(); Console.WriteLine("Code exercise"); var simple = new Coding.Exercise.AdditionExpression(new Coding.Exercise.Value(2), new Coding.Exercise.Value(3)); var exercise_ep = new Coding.Exercise.ExpressionPrinter(); exercise_ep.Visit(simple); Console.WriteLine(exercise_ep.ToString()); Console.ReadLine(); }