示例#1
0
        public ExpertSystemRule(string line)
        {
            Type = line.Contains("<=>") ? ImplicationType.EQUAL : ImplicationType.IMPLY;
            var notation = new ReversePolishNotation();

            string[] separator = { "=>", "<=>" };
            var      lines     = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);

            if (lines.Length != 2)
            {
                throw new Exception("ESRule error convert! " + line);
            }
            NpiLeft  = notation.Convert(lines[0]);
            NpiRight = notation.Convert(lines[1]);
            if (NpiRight.Contains("+!"))
            {
                throw new Exception("Format error!(right +!) " + line);
            }
            if (Type == ImplicationType.EQUAL && (NpiLeft.Contains('|') || NpiRight.Contains('|')))
            {
                throw new Exception("Format error!(| and <=>) " + line);
            }
            if (Type == ImplicationType.EQUAL && (NpiLeft.Contains("+!") || NpiRight.Contains("+!")))
            {
                throw new Exception("Format error!(+! and <=>) " + line);
            }
        }
        public void CheckNotation(string input, string expectedString)
        {
            var notation       = new ReversePolishNotation();
            var inputCopy      = input.PreProcess();
            var notationResult = notation.Convert(inputCopy);

            Assert.True(string.Equals(notationResult, expectedString));
        }
示例#3
0
        private void AnalysisEvent(object sender, RoutedEventArgs e)
        {
            try
            {
                string[] result = ReversePolishNotation.Convert(textInput.Text);

                StringBuilder sb = new StringBuilder();
                foreach (string item in result)
                {
                    sb.Append(item).Append(' ');
                }
                if (sb.Length >= 1)
                {
                    sb.Length -= 1;
                }

                textTransfer.Text = sb.ToString();
            }
            catch (FormatException)
            {
                MessageBox.Show(this, "数式の書式が不正です。", "解析エラー", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#4
0
 public void Analysis()
 {
     Transfer.Value = string.Join(' ', ReversePolishNotation.Convert(Input.Value));
 }
        public void ConvertInvalidFormula(string formula)
        {
            var result = ReversePolishNotation.Convert(formula);

            Assert.Throws <FormatException>(() => result.ToList());
        }
        public void ConvertNormalFormula(string formula, IEnumerable <string> expected)
        {
            var result = ReversePolishNotation.Convert(formula);

            Assert.Equal(expected, result);
        }
        public void ConvertNull()
        {
            var ex = Assert.Throws <ArgumentNullException>(() => ReversePolishNotation.Convert(null));

            Assert.Equal("formula", ex.ParamName);
        }