Commits

Miguel Roman committed b516e03

Se agregaron los test de la función siguiente.

  • Participants
  • Parent commits 3623ad0

Comments (0)

Files changed (1)

File Tests/Servicios/GramaticaAnalyzerTests.cs

+using Compiladores.Entidades;
+using Compiladores.Servicios;
+using NUnit.Framework;
+
+namespace Tests.Servicios
+{
+    [TestFixture]
+    public class GramaticaAnalyzerTests
+    {
+        [Test]
+        public void Primero_ConReglasDefinidas_RetornaSoloTerminales()
+        {
+
+            var reglas = CrearReglas();
+
+            var servicio = new GramaticaAnalyzer();
+
+            var primeroDeA = servicio.Primero(reglas, new Variable("A"));
+            var primeroDeAprima = servicio.Primero(reglas, new Variable("A'"));
+            var primeroDeB = servicio.Primero(reglas, new Variable("B"));
+            var primeroDeC = servicio.Primero(reglas, new Variable("C"));
+            var primeroDeD = servicio.Primero(reglas, new Variable("D"));
+
+            Assert.That(primeroDeA, Is.EqualTo(new object[] { new Terminal(null), new Terminal("a"), new Terminal("b"), new Terminal("c"), new Terminal("d"), new Terminal("f") }));
+            Assert.That(primeroDeAprima, Is.EqualTo(new object[] { new Terminal(null), new Terminal("a") }));
+            Assert.That(primeroDeB, Is.EqualTo(new object[] { new Terminal(null), new Terminal("b") }));
+            Assert.That(primeroDeC, Is.EqualTo(new object[] { new Terminal(null), new Terminal("c") }));
+            Assert.That(primeroDeD, Is.EqualTo(new object[] { new Terminal(null), new Terminal("c"), new Terminal("d"), new Terminal("f") }));
+        }
+
+        private static ReglaGramatical[] CrearReglas()
+        {
+            var reglas = new[]{
+                new ReglaGramatical {
+                    Variable = new Variable("A"),
+                    Produccion = new object[] {
+                        new Variable("B"),
+                        new Variable("C"),
+                        new Variable("D"),
+                        new Variable("A'")
+                    }
+                },
+                new ReglaGramatical {
+                    Variable = new Variable("A'"),
+                    Produccion = new object[] {
+                        new Terminal("a"),
+                        new Variable("A'")
+                    }
+                },
+                new ReglaGramatical {
+                    Variable = new Variable("A'"),
+                    Produccion = new object[] {
+                        new Terminal(null)
+                    }
+                },
+                new ReglaGramatical {
+                    Variable = new Variable("B"),
+                    Produccion = new object[] {
+                        new Terminal("b")
+                    }
+                },
+                new ReglaGramatical {
+                    Variable = new Variable("B"),
+                    Produccion = new object[] {
+                        new Terminal(null)
+                    }
+                },
+                new ReglaGramatical {
+                    Variable = new Variable("C"),
+                    Produccion = new object[] {
+                        new Terminal("c")
+                    }
+                },
+                new ReglaGramatical {
+                    Variable = new Variable("C"),
+                    Produccion = new object[] {
+                        new Terminal(null)
+                    }
+                },
+                new ReglaGramatical {
+                    Variable = new Variable("D"),
+                    Produccion = new object[] {
+                        new Terminal("d")
+                    }
+                },
+                new ReglaGramatical {
+                    Variable = new Variable("D"),
+                    Produccion = new object[] {
+                        new Variable("C"),
+                        new Terminal("f")
+                    }
+                }
+            };
+            return reglas;
+        }
+    }
+}