public void ParseRestrictionTest() { var tuple = EquatonParser.ParseRestriction("1x1 + 1x2 + 1x3 = 2", 4); Assert.AreEqual(2, tuple.Item2); Assert.IsTrue(tuple.Item1.SequenceEqual(new double[] { 1, 1, 1, 0 })); var tuple2 = EquatonParser.ParseRestriction("5X2+1X6 = 10"); Assert.AreEqual(10, tuple2.Item2); Assert.IsTrue(tuple2.Item1.SequenceEqual(new double[] { 0, 5, 0, 0, 0, 1 })); }
private void btnNext_Click(object sender, EventArgs e) { try { //определяем коэффициенты главной функции и количество неизвестных var mainCoefficients = EquatonParser.ParseMainFunction(boxMainFunction.Text); var unknowns = mainCoefficients.Length; //определяем коэффициенты и свободные члены ограничений var restrictionCoefficients = new List <double[]>(); var freeMembers = new List <double>(); foreach (var line in boxRestrictions.Lines) { var restriction = EquatonParser.ParseRestriction(line, unknowns); restrictionCoefficients.Add(restriction.Item1); freeMembers.Add(restriction.Item2); } //передаем данные дальше new BasisForm(unknowns, mainCoefficients, restrictionCoefficients.ToArray(), freeMembers.ToArray()) .Show(); } catch (Exception ex) { MessageBox.Show("Ошибка! Повторите ввод."); } }