示例#1
0
        public void MtchTest_C245()
        {
            //arrange Group, Components, CompSet, Rule
            var Im   = new IMIT();
            var rule = Im.IM_Rule();
            var syns = rule.synonyms[SType.Profile].ToList();

            Assert.AreEqual(syns[0], "угoлoк");
            Assert.AreEqual(syns[1], "l");
            Comp comp = rule.CompSet.Components[1];

            Assert.AreEqual(comp.Str(SType.Profile), "Уголок 20x5");
            Assert.AreEqual(comp.compDP.dpar[SType.Profile], "угoлoк20x5");
            var gr = Im.IM_Group("C245");

            Assert.AreEqual(gr.mat, "c245");
            Assert.AreEqual(gr.prf, "l20x5");
            //act
            Mtch m = new Mtch(gr, rule);

            //assert
            Assert.AreEqual(m.ok, Mtch.OK.Match);
            Assert.AreEqual(m.group.guids.Count, 2);
            Assert.AreEqual(m.component.Str(SType.Profile), "Уголок 20x5");
            Assert.AreEqual(m.group.totalPrice, 2020);
        }
示例#2
0
        void test_Mtch_2()
        {
            Log.set(" test_Mtch_2: Rule 15 и Group < B12,5 , 1900x1600 > ");
            rule = new Rule.Rule(15);
            ElmAttSet.ElmAttSet elB = new ElmAttSet.ElmAttSet(
                "ID56A7442F-0000-0D7B-3134-353338303236",
                "B12,5", "Concrete", "1900x1600", 0, 0, 0, 1000);
            Dictionary <string, ElmAttSet.ElmAttSet> els = new Dictionary <string, ElmAttSet.ElmAttSet>();

            els.Add(elB.guid, elB);
            List <string> guids = new List <string>(); guids.Add(elB.guid);
            var           model = new Model.Model();

            model.setElements(els);
            model.getGroups();
            var gr = model.elmGroups[0];

            TST.Eq(gr.guids.Count, 1);
            var match = new Mtch(gr, rule);

            TST.Eq(match.ok == OK.Match, true);
            var cmp = match.component;

//31/3            TST.Eq(cmp.fps[SType.Material].pars[0].par.ToString(), "b12,5");
            Log.exit();
        }
示例#3
0
        /// <summary>
        /// проверка, соответствует ли строка str набору синонимов и параметров
        /// !допустимы str без параметров; при этом pars == null
        /// !ограничение: str должен начинаться с непустого фрагмента текста, иначе Fatal Error
        /// </summary>
        /// <param name="str"></param>
        /// <param name="txs"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        /// <description> --- ОПИСАНИЕ ИДЕИ --------------------------
        /// Правило - это шаблон вида "tx1<par1>tx2<par2>"
        /// Правило уже разбрано в методе Rule.RuleParse, то есть на входе
        /// - str строка для обработки, она берется из прайс-листа или модели в САПР,
        /// - List<string> txts - список фрагментов текста, он 
        /// - Dictionary<string,strins>pars -словарь параметров с еще не заполненными значениями,
        ///      то есть pars = { {{par.name},""},..,..}. isStrMatch заполняет pars.Values
        /// Разбор Правила и заполнение значений параметров в isStrMatch делается с применением
        /// технологии Regular Expression. Здесь использован код из Reverse String Format
        /// http://stackoverflow.com/questions/5346158/parse-string-using-format-template
        /// </description>
        //////////        internal bool isSectionMatch(string str, List<string> txs, ref Dictionary<string, string> pars)
        //////////        {
        //////////            bool ok = false;
        //////////            if (string.IsNullOrWhiteSpace(str)) goto Exit;
        //////////            string reg = "";
        //////////            foreach (var s in txs) reg += s + "*";
        //////////            ok = Regex.IsMatch(str, reg);
        //////////            if (!ok || pars == null) goto Exit;
        //////////            //-- fill pars.Values in Dictionary
        //////////            string pattern = "^" + Regex.Replace(reg, @"\*", "(.*?)") + "$";
        //////////            Regex r = new Regex(pattern);
        //////////            Match m = r.Match(str);
        //////////            string[] parNam = new string[pars.Keys.Count];
        //////////            pars.Keys.CopyTo(parNam, 0);
        ////////////            string[] parNam = pars.Keys.ToArray();
        //////////            if (parNam.Length != m.Groups.Count - 1) Msg.F("Err: inconsystant Rule text/parameters");
        //////////            pars.Clear();
        //////////            for (int i = 1; i < m.Groups.Count; i++)
        //////////            {
        //////////                string name = parNam[i - 1];
        //////////                string val = m.Groups[i].Value;
        //////////                val = val.Trim();
        //////////                pars.Add(name, val);
        //////////            }
        //////////Exit:       return ok;
        //////////        }
        /// <summary>
        /// isRuleMatch(group, rule) - check if rule could be applied with group of elements gr
        /// </summary>
        /// <desctiption>
        /// для TRUE нужно, чтобы Правило содержало Синонимы, допустимые для этой Группы.
        /// пустой список Синонимов означает "любое значение".
        /// если у элемента списка Синонимов есть параметры, их сопоставляют с данными Группы
        /// с помощью Регулярных выражений
        /// </desctiption>
        /// <param name="gr"></param>
        /// <param name="rule"></param>
        /// <returns>true if could be in match</returns>
        //////////////private bool isRuleMatch(Group.Group gr, Rule.Rule rule)
        //////////////{
        //////////////    bool result = false;
        //////////////    throw new NotImplementedException();
        //////////////    return result;
        //////////////}

  //#region ------ test Matcher -----

        internal static void testMtch()
        {
            Log.set("testMtch");
            Mtch mtch = new Mtch();
            // 28/5            mtch.test_getSectionText();
            // 28/5            mtch.test_isSectionMatch();
            //////////////////mtch.test_Mtch_1();
            //// 28/3 ////////mtch.test_Mtch_2();
            //////////////////mtch.test_Mtch_3();
            Log.exit();
        }
示例#4
0
        public void MtchTest_B20()
        {
            var Im   = new IMIT();
            var rule = Im.IM_Rule("Mat: B*");
            var gr   = Im.IM_Group("B20");  //Prf "1900x1600" set in Im

            Assert.AreEqual(gr.mat, "b20");
            Assert.AreEqual(gr.prf, "1900x1600");

            Mtch m = new Mtch(gr, rule);

            Assert.AreEqual(m.ok, Mtch.OK.NoMatch);
        }
示例#5
0
        //////////////        private void test_getSectionText()
        //////////////        {
        //////////////            Log.set("test_getSectionTest(Section.Material, text");
        //28/5/////////////// 7/3/2017 /////////////////            TST.Eq(getSectionText(FP.Section.Material, "Профиль: L 20 x 5; M: C245; Price: 2690"), "c245");
        //////////////            Log.exit();
        //////////////        }

        //////////////private void test_isSectionMatch()
        //////////////{
        //////////////    Log.set("isSectionMatch(Section.Material, C245, rule.text)");

        //////////////    /////// 7/3/2017 ////            bool ok = isSectionMatch(FP.Section.Material, "C245", "Профиль: L * x * ст*; длина: * = * м; M: ст *;");

        //////////////    Log.exit();
        //////////////}

        private void test_Mtch_1()
        {
            Log.set(" test_Mtch_1: Rule 4 и Group<C255, L20x4>");
            Rule.Rule rule = new Rule.Rule(4);
            ElmAttSet.ElmAttSet el = new ElmAttSet.ElmAttSet(
                "ID56A7442F-0000-0D70-3134-353338303236",
                "C245", "Steel", "Уголок20X4", 0, 0, 0, 1000);
            Dictionary<string, ElmAttSet.ElmAttSet> els = new Dictionary<string, ElmAttSet.ElmAttSet>();
            els.Add(el.guid, el);
            List<string> guids = new List<string>(); guids.Add(el.guid);
            Group.Group gr = new Group.Group(els, "C245", "Уголок20X4", guids);
            Mtch match = new Mtch(gr, rule);
            //6/4/17            TST.Eq(match.ok == OK.Match, true);
            Log.exit();
        }