Пример #1
0
        public IEnumerable <MusicalSymbol> ConvertSheet(Sheet sheet)
        {
            var visitor = new Visitor.Visitor();

            List <MusicalSymbol> symbols = new List <MusicalSymbol>();

            var clef = new Clef((ClefType)sheet.Key, 2);

            symbols.Add(clef);
            var timeSignature = new TimeSignature(TimeSignatureType.Numbers, sheet.Bars[0].UpperSignature, sheet.Bars[0].LowerSignature);

            symbols.Add(timeSignature);

            foreach (var bar in sheet.Bars)
            {
                foreach (var note in bar.Notes)
                {
                    note.Visit(visitor);
                    symbols.Add(visitor.Symbol);
                }
                symbols.Add(new Barline());
            }

            return(symbols);
        }
Пример #2
0
        public void Input_SumAndThenSum()
        {
            // Arrange
            var input = "1 2 3 * + ";
            var sut = new ExpressionParser();

            // Act
            IExpression actual = sut.Parse(input);

            var v = new Visitor.Visitor();
            ((BinaryExpression)actual).Accept(v);

            // Assert
            Assert.AreEqual(7, actual.Eval());
            Assert.AreEqual("1 + 2 * 3", v.ToString());
        }
Пример #3
0
        public void Input_SumAndThenSum()
        {
            // Arrange
            var input = "1 2 3 * + ";
            var sut   = new ExpressionParser();

            // Act
            IExpression actual = sut.Parse(input);

            var v = new Visitor.Visitor();

            ((BinaryExpression)actual).Accept(v);

            // Assert
            Assert.AreEqual(7, actual.Eval());
            Assert.AreEqual("1 + 2 * 3", v.ToString());
        }
Пример #4
0
        public void Eval_When_Sum_OneVariableAndOneConstants5and3_MustReturn_8()
        {
            // Arrange
            var sut = new SumExpression(new AssignmentExpression(
                                            new VariableExpression("P"),
                                            new ConstantExpression(5)),
                                        new ConstantExpression(3));
            var v = new Visitor.Visitor();

            sut.Accept(v);

            // Act
            var actual = sut.Eval();


            // Assert
            Assert.AreEqual(expected: 8, actual: actual);
            Assert.AreEqual("(P = 5) + 3", v.ToString());
        }
Пример #5
0
 public void Accept(Visitor.Visitor visitor)
 {
     visitor.Visit(this);
 }
Пример #6
0
 public void Accept(Visitor.Visitor v)
 {
     v.Visit(instance);
 }
Пример #7
0
        public void Eval_When_Sum_OneVariableAndOneConstants5and3_MustReturn_8()
        {
            // Arrange
            var sut = new SumExpression(new AssignmentExpression(
                                                new VariableExpression("P"),
                                                new ConstantExpression(5)),
                                            new ConstantExpression(3));
            var v = new Visitor.Visitor();
            sut.Accept(v);

            // Act
            var actual = sut.Eval();

            // Assert
            Assert.AreEqual(expected: 8, actual: actual);
            Assert.AreEqual("(P = 5) + 3", v.ToString());
        }