public void TestScope2() { MemoryStream ms = Content.GenerateContent2(); MiniZincLexer scnr = new MiniZincLexer(ms); MiniZincParser pars = new MiniZincParser(scnr); pars.Parse(); ZincModel model = pars.Result; Assert.IsNotNull(model); model.CloseScope(null); ZincIdentNameRegister zinr = model.NameRegister; List <IZincIdent> iz = zinr.Elements().ToList(); List <string> result = iz.Select(x => x.Name).ToList(); List <string> expected = new List <string> (new string[] { "size", "d", "total", "end" }); Assert.AreEqual(expected.Count, result.Count); foreach (string si in expected) { Assert.Contains(si, result); } Assert.AreEqual(6, model.Items.Count()); Assert.AreEqual(5, model.Items.OfType <ZincVarDeclItem> ().Count()); Assert.AreEqual(1, model.Items.OfType <ZincSolveItem> ().Count()); List <ZincVarDeclItem> zvd = new List <ZincVarDeclItem> (); foreach (string si in expected) { ZincVarDeclItem zvdi = model.Items.OfType <ZincVarDeclItem> ().Where(x => x.DeclaredIdentifier.Name == si).FirstOrDefault(); Assert.NotNull(zvdi); Assert.Contains(zvdi.DeclaredIdentifier, iz); zvd.Add(zvdi); } }
public void TestGenerateModel2() { string model1 = string.Empty; string model2 = "include \"aninclude\";\n"; ZincModel zm = new ZincModel(); Assert.AreEqual(model1, zm.WriteString()); zm.AddItem(new ZincIncludeItem("aninclude")); Assert.AreEqual(model2, zm.WriteString()); }
public void TestParser0() { using (MemoryStream ms = Content.GenerateContent0()) { MiniZincLexer scnr = new MiniZincLexer(ms); MiniZincParser pars = new MiniZincParser(scnr); pars.Parse(); ZincModel model = pars.Result; Assert.IsNotNull(model); IZincItem[] items = model.Items.ToArray(); Assert.AreEqual(Content.NItems0, items.Length); } }
public void TestScope0() { MemoryStream ms = Content.GenerateContent0(); MiniZincLexer scnr = new MiniZincLexer(ms); MiniZincParser pars = new MiniZincParser(scnr); pars.Parse(); ZincModel model = pars.Result; Assert.IsNotNull(model); model.CloseScope(null); //TODO: finish test }
public void TestGenerateModel1() { string model01 = string.Empty; string model02 = "par int : size;\n"; string model03 = "par int : size;\npar array [ par 1 .. size , par 1 .. size ] of par int : d;\n"; ZincModel zm = new ZincModel(); Assert.AreEqual(model01, zm.WriteString()); ZincIdent size = new ZincIdent("size"); zm.AddItem(new ZincVarDeclItem(new ZincTypeInstExprAndIdent(new ZincTypeInstBaseExpression(new ZincScalarType(ZincScalar.Int)), size))); Assert.AreEqual(model02, zm.WriteString()); ZincTypeInstBaseExpression range = new ZincTypeInstBaseExpression(new ZincTypeInstRangeExpression(new ZincIntLiteral(1), size)); ZincIdent d = new ZincIdent("d"); zm.AddItem(new ZincVarDeclItem(new ZincTypeInstExprAndIdent(new ZincTypeInstBaseExpression(new ZincTypeInstArrayExpression(new ZincTypeInstBaseExpression(new ZincScalarType(ZincScalar.Int)), range, range)), d))); Assert.AreEqual(model03, zm.WriteString()); }