#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using HeuristicLab.Grammars; namespace Test { [TestClass] public class TestGrammar { [TestMethod] public void TestSimpleGrammar() { var gStr = @"S -> A A->a B B ->S b | S a|B b B-> a aa aaa "; var g = HeuristicLab.Grammars.Grammar.FromString(gStr); Assert.AreEqual(g.StartSymbol, "S"); Assert.AreEqual(g.TerminalSymbols.Count(), 4); Assert.AreEqual(g.NonTerminalSymbols.Count(), 3); Assert.IsTrue(g.TerminalSymbols.Contains("aaa")); Assert.IsTrue(g.TerminalSymbols.Contains("aa")); Assert.IsTrue(g.NonTerminalSymbols.Contains("S")); Assert.IsTrue(g.NonTerminalSymbols.Contains("B")); Assert.IsTrue(g.NonTerminalSymbols.Contains("A")); } } }