Ejemplo n.º 1
0
        public void TestAccessors()
        {
            string str1 = "(\"S1\", \"Variable:/:S1\", -1)";
            EcellReference er1 = new EcellReference(str1);

            EcellReference er2 = new EcellReference();
            er2.Name = "S1";
            er2.FullID = "Variable:/:S1";
            er2.Coefficient = -1;
            er2.IsAccessor = 1;

            Assert.AreEqual(er1.Name, er2.Name, "Name is not expected value.");
            Assert.AreEqual(er1.FullID, er2.FullID, "FullID is not expected value.");
            Assert.AreEqual(er1.Key, er2.Key, "Key is not expected value.");
            Assert.AreEqual(er1.Coefficient, er2.Coefficient, "Coefficient is not expected value.");
            Assert.AreEqual(er1.IsAccessor, er2.IsAccessor, "IsAccessor is not expected value.");

            EcellReference er3 = new EcellReference();
            er3.Name = "S1";
            er3.Key = "/:S1";
            er3.Coefficient = -1;
            er3.IsAccessor = 1;

            Assert.AreEqual(er1.Name, er3.Name, "Name is not expected value.");
            Assert.AreEqual(er1.FullID, er3.FullID, "FullID is not expected value.");
            Assert.AreEqual(er1.Key, er3.Key, "Key is not expected value.");
            Assert.AreEqual(er1.Coefficient, er3.Coefficient, "Coefficient is not expected value.");
            Assert.AreEqual(er1.IsAccessor, er3.IsAccessor, "IsAccessor is not expected value.");

            try
            {
                EcellReference er4 = new EcellReference();
                er4.Name = "S1";
                er4.FullID = null;
                er4.Coefficient = -1;
                er4.IsAccessor = 1;

                string key = er4.Key;

                er4.FullID = "/S1";
                key = er4.Key;

                Assert.Fail("Failed to throw parsing error.");
            }
            catch(EcellException)
            {
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the list of reference from string.
        /// </summary>
        /// <param name="str">string.</param>
        /// <returns>the list of reference.</returns>
        public static List<EcellReference> ConvertFromString(string str)
        {
            List<EcellReference> list = new List<EcellReference>();
            if (str == null || str == "")
                return list;
            string text = str.Substring(1);
            text = text.Substring(0, text.Length - 1);
            Regex parser = new Regex(stringParse);
            MatchCollection coll = parser.Matches(text);

            IEnumerator iter = coll.GetEnumerator();
            while (iter.MoveNext())
            {
                Match match = (Match)iter.Current;
                EcellReference er = new EcellReference(match.Groups["refer"].Value);
                list.Add(er);
            }
            return list;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Check Selected reference
 /// </summary>
 /// <param name="er"></param>
 /// <param name="varKey"></param>
 /// <param name="changeType"></param>
 /// <param name="coefficient"></param>
 /// <returns></returns>
 private static bool CheckReference(EcellReference er, string varKey, RefChangeType changeType, int coefficient)
 {
     if (!varKey.Equals(er.Key))
         return false;
     if (changeType == RefChangeType.BiDir || coefficient == 0)
         return true;
     if (er.Coefficient == coefficient)
         return true;
     return false;
 }
Ejemplo n.º 4
0
        public void TestToString()
        {
            string expectedString;
            string resultString;
            EcellValue value;

            EcellReference er1 = new EcellReference("S1", "Variable:/:S1", 1, 0);
            value = new EcellValue(er1);
            expectedString = er1.ToString();
            resultString = value.ToString();
            Assert.AreEqual(expectedString, resultString, "ToString method returned unexpected result.");

            value = new EcellValue(new List<object>());
            expectedString = "()";
            resultString = value.ToString();
            Assert.AreEqual(expectedString, resultString, "ToString method returned unexpected result.");

            List<object> list = new List<object>();
            list.Add(0.001);
            list.Add("Test");
            value = new EcellValue(list);
            expectedString = "(0.001, \"Test\")";
            resultString = value.ToString();
            Assert.AreEqual(expectedString, resultString, "ToString method returned unexpected result.");

            value = new EcellValue(1);
            expectedString = "1";
            resultString = value.ToString();
            Assert.AreEqual(expectedString, resultString, "ToString method returned unexpected result.");

            value = new EcellValue(0.0002);
            expectedString = "0.0002";
            resultString = value.ToString();
            Assert.AreEqual(expectedString, resultString, "ToString method returned unexpected result.");

            value = new EcellValue("string");
            expectedString = "string";
            resultString = value.ToString();
            Assert.AreEqual(expectedString, resultString, "ToString method returned unexpected result.");

            expectedString = "((\"S1\", \"Variable:/:S1\", 1, 0), (\"S2\", \"Variable:/:S2\", 1, 1))";
            value = EcellValue.ConvertFromListString(expectedString);
            resultString = value.ToString();
            Assert.AreEqual(expectedString, resultString, "CastToList method returned unexpected result.");
        }
Ejemplo n.º 5
0
        public void TestConstructorEcellValueEr()
        {
            // EcellReference
            EcellReference er = new EcellReference("S1","Variable:/:S1",1,0);
            EcellValue testEcellValue = new EcellValue(er);
            Assert.IsNotNull(testEcellValue, "Constructor of type, EcellValue failed to create instance.");
            Assert.IsFalse(testEcellValue.IsInt, "IsInt is not expected value.");
            Assert.IsFalse(testEcellValue.IsDouble, "IsDouble is not expected value.");
            Assert.IsTrue(testEcellValue.IsList, "IsList is not expected value.");
            Assert.IsFalse(testEcellValue.IsString, "IsString is not expected value.");
            Assert.AreEqual(EcellValueType.List, testEcellValue.Type, "Type is not expected value.");
            Assert.AreEqual(er.ToString(), testEcellValue.ToString(), "ToString() is not expected value.");

            // List
            EcellValue temp = new EcellValue(er);
            List<EcellValue> list = new List<EcellValue>();
            list.Add(temp);
            EcellValue value = new EcellValue(list);
            Assert.IsNotNull(value, "Constructor of type, EcellValue failed to create instance.");
            Assert.IsFalse(value.IsInt, "IsInt is not expected value.");
            Assert.IsFalse(value.IsDouble, "IsDouble is not expected value.");
            Assert.IsTrue(value.IsList, "IsList is not expected value.");
            Assert.IsFalse(value.IsString, "IsString is not expected value.");
            Assert.AreEqual(EcellValueType.List, value.Type, "Type is not expected value.");
        }
Ejemplo n.º 6
0
        public void TestCastToList()
        {
            List<EcellReference> list = new List<EcellReference>();
            EcellReference er1 = new EcellReference("S1", "Variable:/:S1", 1, 0);
            EcellReference er2 = new EcellReference("S2", "Variable:/:S2", 1, 1);
            list.Add(er1);
            list.Add(er2);
            EcellValue resultValue = EcellReference.ConvertToEcellValue(list);
            List<object> expectedList = (List<object>)resultValue.Value;

            string str = "((\"S1\", \"Variable:/:S1\", 1, 0), (\"S2\", \"Variable:/:S2\", 1, 1))";
            EcellValue value = EcellValue.ConvertFromListString(str);
            List<object> resultList = (List<object>)value.Value;
            Assert.AreEqual(expectedList, resultList, "CastToList method returned unexpected result.");

            value = EcellValue.ConvertFromListString("");
            resultList = (List<object>)value.Value;
            Assert.IsEmpty(resultList, "resultList shold be empty.");
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="processKey">The key of process.</param>
 /// <param name="er">The reference of EcellObject.</param>
 public EdgeInfo(string processKey, EcellReference er)
 {
     m_proKey = processKey;
     // Set Relation
     int coef = er.Coefficient;
     if (coef < 0)
     {
         m_direction = EdgeDirection.Inward;
         m_type = LineType.Solid;
     }
     else if (coef == 0)
     {
         m_direction = EdgeDirection.None;
         m_type = LineType.Dashed;
     }
     else
     {
         m_direction = EdgeDirection.Outward;
         m_type = LineType.Solid;
     }
     m_varKey = er.Key;
 }
Ejemplo n.º 8
0
        public void TestConstructorEcellReference()
        {
            EcellReference er = null;
            er = new EcellReference();
            Assert.IsNotNull(er, "Constructor of type, EcellReference failed to create instance.");
            Assert.IsNull(er.Name, "Name is not null.");
            Assert.IsNull(er.FullID, "FullID is not null.");
            Assert.IsNull(er.Key, "Key is not null.");
            Assert.AreEqual(0, er.Coefficient, "Coefficient is not expected value.");
            Assert.AreEqual(0, er.IsAccessor, "IsAccessor is not expected value.");

            er = null;
            er = new EcellReference(
                "S1",
                "Variable:/:S1",
                1,
                0);
            Assert.IsNotNull(er, "Constructor of type, EcellReference failed to create instance.");
            Assert.AreEqual("S1", er.Name, "Name is not expected value.");
            Assert.AreEqual("Variable:/:S1", er.FullID, "FullID is not expected value.");
            Assert.AreEqual("/:S1", er.Key, "Key is not expected value.");
            Assert.AreEqual(1, er.Coefficient, "Coefficient is not expected value.");
            Assert.AreEqual(0, er.IsAccessor, "IsAccessor is not expected value.");
        }
Ejemplo n.º 9
0
 public void TestConstructorEcellReferenceNameFullIDCoefAccessor()
 {
     string name = "S1";
     string fullID = "Variable:/:S1";
     int coef = 1;
     int accessor = 0;
     EcellReference er = new EcellReference(name, fullID, coef, accessor);
     Assert.IsNotNull(er, "Constructor of type, EcellReference failed to create instance.");
     Assert.AreEqual("S1", er.Name, "Name is not expected value.");
     Assert.AreEqual("Variable:/:S1", er.FullID, "FullID is not expected value.");
     Assert.AreEqual("/:S1", er.Key, "Key is not expected value.");
     Assert.AreEqual(1, er.Coefficient, "Coefficient is not expected value.");
     Assert.AreEqual(0, er.IsAccessor, "IsAccessor is not expected value.");
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Creates a new "EcellValue" instance with an EcellReference.
 /// </summary>
 /// <param name="er">The reference object.</param>
 public EcellValue(EcellReference er)
 {
     List<object> list = new List<object>();
     list.Add(er.Name);
     list.Add(er.FullID);
     list.Add(er.Coefficient);
     list.Add(er.IsAccessor);
     this.m_value = Normalize(list);
 }
Ejemplo n.º 11
0
        public void TestClone()
        {
            string str = "(\"S1\", \"Variable:/:S1\", 1, 0)";

            EcellReference er1 = new EcellReference(str);
            EcellReference er2 = er1.Clone();
            Assert.AreEqual(er1.Name, er2.Name);
            Assert.AreEqual(er1.FullID, er2.FullID);
            Assert.AreEqual(er1.Coefficient, er2.Coefficient);
            Assert.AreEqual(er1.IsAccessor, er2.IsAccessor);
            Assert.AreEqual(er1, er2, "Copy method returned unexpected result.");

            List<EcellReference> list1 = new List<EcellReference>();
            EcellReference er3 = (EcellReference)((ICloneable)er1).Clone();
            Assert.AreEqual(er1.Name, er3.Name);
            Assert.AreEqual(er1.FullID, er3.FullID);
            Assert.AreEqual(er1.Coefficient, er3.Coefficient);
            Assert.AreEqual(er1.IsAccessor, er3.IsAccessor);
            Assert.AreEqual(er1, er3, "Copy method returned unexpected result.");
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Varidate Each EcellReference.
        /// </summary>
        private void ValidateReferences()
        {
            List<String> nameList = new List<string>();
            List<EcellReference> refList = new List<EcellReference>();
            for (int i = 0; i < this.dgv.RowCount; i++)
            {
                // Check FullID
                string fullID = (string)this.dgv[0, i].Value;
                if (string.IsNullOrEmpty(fullID))
                {
                    throw new EcellException(MessageResources.ErrInvalidID);
                }

                // Check Molar weight.
                float coef;
                try
                {
                    coef = (float)Convert.ToDouble(this.dgv[1, i].Value);
                }
                catch (Exception ex)
                {
                    throw new EcellException(MessageResources.ErrNoNumber, ex);
                }

                // Create EcellReference.
                EcellReference er = new EcellReference();
                er.Name = coef.ToString();
                er.FullID = fullID;
                er.Coefficient = 0;
                refList.Add(er);
            }
            // Set new list.
            this.m_refList = refList;
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Add new EcennReference.
 /// </summary>
 /// <param name="er">Reference object.</param>
 private void AddReference(EcellReference er)
 {
     dgv.Rows.Add(new object[] { er.FullID, er.Name });
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Create a copy of this EcellReference.
        /// </summary>
        /// <returns>EcellValue</returns>
        public EcellReference Clone()
        {
            EcellReference er = new EcellReference(
                this.Name,
                this.FullID,
                this.Coefficient,
                this.IsAccessor);

            return er;
        }
Ejemplo n.º 15
0
 public void SetUp()
 {
     _unitUnderTest = new EcellReference();
 }
Ejemplo n.º 16
0
        public void TestConstructorEcellReferenceStr()
        {
            string str1 = "(\"S1\", \"Variable:/:S1\", \"1\", \"0\")";
            EcellReference er1 = new EcellReference(str1);
            Assert.IsNotNull(er1, "Constructor of type, EcellReference failed to create instance.");
            Assert.AreEqual("S1", er1.Name, "Name is not expected value.");
            Assert.AreEqual("Variable:/:S1", er1.FullID, "FullID is not expected value.");
            Assert.AreEqual("/:S1", er1.Key, "Key is not expected value.");
            Assert.AreEqual(1, er1.Coefficient, "Coefficient is not expected value.");
            Assert.AreEqual(0, er1.IsAccessor, "IsAccessor is not expected value.");

            string str2 = "(\"S1\", \"Variable:/:S1\", 1, 0)";
            EcellReference er2 = new EcellReference(str2);
            Assert.IsNotNull(er2, "Constructor of type, string failed to create instance.");
            Assert.AreEqual("S1", er2.Name, "Name is not expected value.");
            Assert.AreEqual("Variable:/:S1", er2.FullID, "FullID is not expected value.");
            Assert.AreEqual("/:S1", er2.Key, "Key is not expected value.");
            Assert.AreEqual(1, er2.Coefficient, "Coefficient is not expected value.");
            Assert.AreEqual(0, er2.IsAccessor, "IsAccessor is not expected value.");

            string str3 = "(\"S1\", \"Variable:/:S1\", \"1\")";
            EcellReference er3 = new EcellReference(str3);
            Assert.IsNotNull(er3, "Constructor of type, EcellReference failed to create instance.");
            Assert.AreEqual("S1", er3.Name, "Name is not expected value.");
            Assert.AreEqual("Variable:/:S1", er3.FullID, "FullID is not expected value.");
            Assert.AreEqual("/:S1", er3.Key, "Key is not expected value.");
            Assert.AreEqual(1, er3.Coefficient, "Coefficient is not expected value.");
            Assert.AreEqual(1, er3.IsAccessor, "IsAccessor is not expected value.");

            string str4 = "(\"S1\", \"Variable:/:S1\", 1)";
            EcellReference er4 = new EcellReference(str4);
            Assert.IsNotNull(er2, "Constructor of type, EcellReference failed to create instance.");
            Assert.AreEqual("S1", er4.Name, "Name is not expected value.");
            Assert.AreEqual("Variable:/:S1", er4.FullID, "FullID is not expected value.");
            Assert.AreEqual("/:S1", er4.Key, "Key is not expected value.");
            Assert.AreEqual(1, er4.Coefficient, "Coefficient is not expected value.");
            Assert.AreEqual(1, er4.IsAccessor, "IsAccessor is not expected value.");

            string str5 = "(\"S1\", \"Variable:/:S1\")";
            EcellReference er5 = new EcellReference(str5);
            Assert.IsNotNull(er5, "Constructor of type, EcellReference failed to create instance.");
            Assert.AreEqual("S1", er5.Name, "Name is not expected value.");
            Assert.AreEqual("Variable:/:S1", er5.FullID, "FullID is not expected value.");
            Assert.AreEqual("/:S1", er5.Key, "Key is not expected value.");
            Assert.AreEqual(0, er5.Coefficient, "Coefficient is not expected value.");
            Assert.AreEqual(1, er5.IsAccessor, "IsAccessor is not expected value.");

            try
            {
                string strNull = null;
                EcellReference er6 = new EcellReference(strNull);
                Assert.Fail("Failed to check null.");
            }
            catch (EcellException)
            {
            }

            try
            {
                EcellReference er7 = new EcellReference("");
                Assert.Fail("Failed to check empty.");
            }
            catch (EcellException)
            {
            }

            try
            {
                EcellReference er8 = new EcellReference("hoge");
                Assert.Fail("Failed to throw parsing error.");
            }
            catch (EcellException)
            {
            }
        }
Ejemplo n.º 17
0
 public void TearDown()
 {
     _unitUnderTest = null;
 }
Ejemplo n.º 18
0
        public void TestConstructorEcellReferenceValue()
        {
            string str1 = "(\"S1\", \"Variable:/:S1\", \"1\", \"0\")";
            EcellReference er1 = new EcellReference(str1);
            EcellValue value = new EcellValue(er1);

            EcellReference er2 = new EcellReference(value);
            Assert.IsNotNull(er2, "Constructor of type, EcellReference failed to create instance.");
            Assert.AreEqual("S1", er2.Name, "Name is not expected value.");
            Assert.AreEqual("Variable:/:S1", er2.FullID, "FullID is not expected value.");
            Assert.AreEqual("/:S1", er2.Key, "Key is not expected value.");
            Assert.AreEqual(1, er2.Coefficient, "Coefficient is not expected value.");
            Assert.AreEqual(0, er2.IsAccessor, "IsAccessor is not expected value.");

            try
            {
                EcellReference er3 = new EcellReference(new EcellValue(0));
                Assert.Fail("Failed to throw parsing error.");
            }
            catch (EcellException)
            {
            }

            try
            {
                List<object> list = null;
                EcellReference er4 = new EcellReference((IEnumerator<object>)list);
                Assert.Fail("Failed to throw parsing error.");
            }
            catch (EcellException)
            {
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="processKey"></param>
        /// <param name="list"></param>
        /// <param name="er"></param>
        public EdgeInfo(string processKey, List<EcellReference> list, EcellReference er)
        {
            m_isEndNode = CheckEndNode(list);
            bool bidir = CheckBidir(list, er);

            m_proKey = processKey;
            m_varKey = er.Key;
            // Set Relation
            int l_coef = er.Coefficient;
            if (bidir)
            {
                m_direction = EdgeDirection.Bidirection;
                m_type = LineType.Solid;
            }
            else if (l_coef < 0)
            {
                m_direction = EdgeDirection.Inward;
                m_type = LineType.Solid;
            }
            else if (l_coef == 0)
            {
                m_direction = EdgeDirection.None;
                m_type = LineType.Dashed;
            }
            else
            {
                m_direction = EdgeDirection.Outward;
                m_type = LineType.Solid;
            }
        }
Ejemplo n.º 20
0
        public void TestConvertFromString()
        {
            List<EcellReference> expectedList = new List<EcellReference>();
            EcellReference er1 = new EcellReference("S1", "Variable:/:S1", 1, 0);
            EcellReference er2 = new EcellReference("S2", "Variable:/:S2", 1, 1);
            expectedList.Add(er1);
            expectedList.Add(er2);

            string str = "((\"S1\", \"Variable:/:S1\", 1, 0), (\"S2\", \"Variable:/:S2\", 1, 1))";
            List<EcellReference> resultList = EcellReference.ConvertFromString(str);

            Assert.AreEqual(expectedList, resultList, "ConvertFromString method returned unexpected result.");
            Assert.AreEqual(expectedList[0], resultList[0], "EcellReference is not expected value.");
            Assert.AreEqual(expectedList[1], resultList[1], "EcellReference is not expected value.");

            List<EcellReference> empty = EcellReference.ConvertFromString("");
            Assert.IsEmpty(empty, "Returned List shold be empty.");
        }
Ejemplo n.º 21
0
 private static bool CheckBidir(List<EcellReference> list, EcellReference er)
 {
     bool bidir = false;
     foreach (EcellReference er1 in list)
     {
         if (er.Key.Equals(er1.Key) &&
             er.Coefficient != 0 &&
             er.Coefficient == -1 * er1.Coefficient)
         {
             bidir = true;
             break;
         }
     }
     return bidir;
 }
Ejemplo n.º 22
0
        public void TestConvertToEcellValue()
        {
            string str = "((\"S1\", \"Variable:/:S1\", -1, 0), (\"S2\", \"Variable:/:S2\", -1, 1))";
            EcellValue expectedEcellValue = EcellValue.ConvertFromListString(str);

            List<EcellReference> list = new List<EcellReference>();
            EcellReference er1 = new EcellReference("S1", "Variable:/:S1", -1, 0);
            EcellReference er2 = new EcellReference("S2", "Variable:/:S2", -1, 1);
            list.Add(er1);
            list.Add(er2);
            EcellValue resultEcellValue = EcellReference.ConvertToEcellValue(list);

            Assert.IsTrue(expectedEcellValue.Equals(resultEcellValue), "ConvertToEcellValue method returned unexpected result.");
            Assert.AreEqual(expectedEcellValue.ToString(), resultEcellValue.ToString(), "ConvertToEcellValue method returned unexpected result.");

            EcellValue empty1 = EcellReference.ConvertToEcellValue(new List<EcellReference>());
            Assert.IsEmpty((List<object>)empty1.Value, "Returned List shold be empty.");

            EcellValue empty2 = EcellReference.ConvertToEcellValue(null);
            Assert.IsEmpty((List<object>)empty2.Value, "Returned List shold be empty.");
        }
Ejemplo n.º 23
0
        public void TestCastToString()
        {
            string expectedString;
            string resultString;
            EcellValue value;

            EcellReference er1 = new EcellReference("S1", "Variable:/:S1", 1, 0);
            value = new EcellValue(er1);
            expectedString = er1.ToString();
            resultString = (string)value;
            Assert.AreEqual(expectedString, resultString, "CastToString method returned unexpected result.");

            value = new EcellValue(1);
            expectedString = "1";
            resultString = (string)value;
            Assert.AreEqual(expectedString, resultString, "CastToString method returned unexpected result.");

            value = new EcellValue(0.0002);
            expectedString = "0.0002";
            resultString = (string)value;
            Assert.AreEqual(expectedString, resultString, "CastToString method returned unexpected result.");

            value = new EcellValue("string");
            expectedString = "string";
            resultString = (string)value;
            Assert.AreEqual(expectedString, resultString, "CastToString method returned unexpected result.");
        }
Ejemplo n.º 24
0
        public void TestEquals()
        {
            string str1 = "(\"S1\", \"Variable:/:S1\", 1, 0)";
            EcellReference er1 = new EcellReference(str1);
            Assert.IsFalse(er1.Equals(null), "Equals method returns unexpected value.");

            string str2 = "(\"S2\", \"Variable:/:S1\", 1, 0)";
            EcellReference er2 = new EcellReference(str2);
            Assert.IsFalse(er1.Equals(er2), "Equals method returns unexpected value.");

            string str3 = "(\"S1\", \"Variable:/:S2\", 1, 0)";
            EcellReference er3 = new EcellReference(str3);
            Assert.IsFalse(er1.Equals(er3), "Equals method returns unexpected value.");

            string str4 = "(\"S1\", \"Variable:/:S1\", -1, 0)";
            EcellReference er4 = new EcellReference(str4);
            Assert.IsFalse(er1.Equals(er4), "Equals method returns unexpected value.");

            string str5 = "(\"S1\", \"Variable:/:S1\", 1, 1)";
            EcellReference er5 = new EcellReference(str5);
            Assert.IsFalse(er1.Equals(er5), "Equals method returns unexpected value.");

            string str6 = "(\"S1\", \"Variable:/:S1\", 1, 0)";
            EcellReference er6 = new EcellReference(str6);
            Assert.IsTrue(er1.Equals(er6), "Equals method returns unexpected value.");
        }
Ejemplo n.º 25
0
        public void TestConvertFromListString()
        {
            List<EcellReference> list = new List<EcellReference>();
            EcellReference er1 = new EcellReference("S1", "Variable:/:S1", 1, 0);
            EcellReference er2 = new EcellReference("S2", "Variable:/:S2", 1, 1);
            list.Add(er1);
            list.Add(er2);
            EcellValue value = EcellReference.ConvertToEcellValue(list);
            List<object> expectedList = (List<object>)value.Value;

            string str = "((\"S1\", \"Variable:/:S1\", 1, 0), (\"S2\", \"Variable:/:S2\", 1, 1))";
            value = EcellValue.ConvertFromListString(str);
            List<object> resultList = (List<object>)value.Value;
            Assert.AreEqual(expectedList, resultList, "CastToList method returned unexpected result.");

            Assert.IsFalse(value.IsInt, "IsInt is not expected value.");
            Assert.IsFalse(value.IsDouble, "IsDouble is not expected value.");
            Assert.IsTrue(value.IsList, "IsList is not expected value.");
            Assert.IsFalse(value.IsString, "IsString is not expected value.");

            str = "";
            value = EcellValue.ConvertFromListString(str);
            expectedList = new List<object>();
            resultList = (List<object>)value.Value;
            Assert.AreEqual(expectedList, resultList, "CastToList method returned unexpected result.");
        }
Ejemplo n.º 26
0
        public void TestGetHashCode()
        {
            string str1 = "(\"S1\", \"Variable:/:S1\", 1, 0)";
            EcellReference er1 = new EcellReference(str1);

            string str2 = "(\"S2\", \"Variable:/:S1\", 1, 0)";
            EcellReference er2 = new EcellReference(str2);

            string str3 = "(\"S1\", \"Variable:/:S2\", 1, 0)";
            EcellReference er3 = new EcellReference(str3);

            string str4 = "(\"S1\", \"Variable:/:S1\", -1, 0)";
            EcellReference er4 = new EcellReference(str4);

            string str5 = "(\"S1\", \"Variable:/:S1\", 1, 1)";
            EcellReference er5 = new EcellReference(str5);

            string str6 = "(\"S1\", \"Variable:/:S1\", 1, 0)";
            EcellReference er6 = new EcellReference(str6);

            Assert.AreNotEqual(er1.GetHashCode(), er2.GetHashCode(), "GetHashCode() method returns unexpected value.");
            Assert.AreNotEqual(er1.GetHashCode(), er3.GetHashCode(), "GetHashCode() method returns unexpected value.");
            Assert.AreNotEqual(er1.GetHashCode(), er4.GetHashCode(), "GetHashCode() method returns unexpected value.");
            Assert.AreNotEqual(er1.GetHashCode(), er5.GetHashCode(), "GetHashCode() method returns unexpected value.");
            Assert.AreEqual(er1.GetHashCode(), er6.GetHashCode(), "GetHashCode() method returns unexpected value.");
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Inform the changing of EcellObject in PathwayEditor to DataManager.
        /// </summary>
        /// <param name="proKey">key of process</param>
        /// <param name="varKey">key of variable</param>
        /// <param name="changeType">type of change</param>
        /// <param name="coefficient">coefficient of VariableReference</param>
        /// <param name="isAnchor">is anchored or not.</param>
        public void NotifyVariableReferenceChanged(string proKey, string varKey, RefChangeType changeType, int coefficient, bool isAnchor)
        {
            // Get EcellObject of identified process.
            EcellProcess process = (EcellProcess)m_window.GetEcellObject(m_canvas.ModelID, proKey, EcellObject.PROCESS);
            // End if obj is null.
            if (null == process)
                return;

            // Get EcellReference List.
            List<EcellReference> refList = process.ReferenceList;
            List<EcellReference> newList = new List<EcellReference>();
            EcellReference oldRef = null;
            EcellReference newRef = null;

            foreach (EcellReference er in refList)
            {
                if (CheckReference(er, varKey, changeType, coefficient))
                    oldRef = er.Clone();
                else
                    newList.Add(er.Clone());
            }

            if (oldRef != null && changeType != RefChangeType.Delete)
            {
                newRef = oldRef.Clone();
                switch(changeType)
                {
                    case RefChangeType.SingleDir:
                        newRef.Coefficient = coefficient;
                        newRef.Name = PathUtil.GetNewReferenceName(newList, coefficient);
                        newList.Add(newRef);
                        if(oldRef.Coefficient != 0 && coefficient != 0 && oldRef.Coefficient != coefficient)
                            newList.Add(oldRef);
                        break;
                    case RefChangeType.BiDir:
                        EcellReference copyRef = newRef.Clone();
                        newRef.Coefficient = -1;
                        newRef.Name = PathUtil.GetNewReferenceName(newList, -1);
                        copyRef.Coefficient = 1;
                        copyRef.Name = PathUtil.GetNewReferenceName(newList, 1);
                        newList.Add(newRef);
                        newList.Add(copyRef);
                        break;
                }
            }
            else if(newRef == null)
            {
                switch(changeType)
                {
                    case RefChangeType.SingleDir:
                        EcellReference addRef = new EcellReference();
                        addRef.Coefficient = coefficient;
                        addRef.Key = varKey;
                        addRef.Name = PathUtil.GetNewReferenceName(newList, coefficient);
                        addRef.IsAccessor = 1;
                        newList.Add(addRef);
                        break;
                    case RefChangeType.BiDir:
                        EcellReference addSRef = new EcellReference();
                        addSRef.Coefficient = -1;
                        addSRef.Key = varKey;
                        addSRef.Name = PathUtil.GetNewReferenceName(newList, -1);
                        addSRef.IsAccessor = 1;
                        newList.Add(addSRef);

                        EcellReference addPRef = new EcellReference();
                        addPRef.Coefficient = 1;
                        addPRef.Key = varKey;
                        addPRef.Name = PathUtil.GetNewReferenceName(newList, 1);
                        addPRef.IsAccessor = 1;
                        newList.Add(addPRef);
                        break;
                }
            }
            // Check MassCalc
            if (process.Classname == EcellProcess.MASSCALCULATIONPROCESS)
            {
                foreach (EcellReference er in newList)
                {
                    er.Coefficient = 0;
                }
            }
            process.ReferenceList = newList;
            try
            {
                NotifyDataChanged(proKey, process, true, isAnchor);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                throw new PathwayException(MessageResources.ErrCreateEdge);
            }
        }
Ejemplo n.º 28
0
 public void TestToString()
 {
     string expectedString = "(\"S1\", \"Variable:/:S1\", 1, 0)";
     string resultString = "";
     EcellReference er = new EcellReference(expectedString);
     resultString = er.ToString();
     Assert.AreEqual(expectedString, resultString, "ToString() method returned unexpected result.");
 }
Ejemplo n.º 29
0
        public void TestNormalizeVariableReference()
        {
            EcellReference er = new EcellReference("V1", ":.:V1", 1, 1);
            string systemPath = "/S0/S1";
            Util.NormalizeVariableReference(er, systemPath);
            Assert.AreEqual("/S0/S1:V1", er.Key, "NormalizeSystemPath method returned unexpected result.");

            er = new EcellReference("V1", ":..:V1", 1, 1);
            Util.NormalizeVariableReference(er, systemPath);
            Assert.AreEqual("/S0:V1", er.Key, "NormalizeSystemPath method returned unexpected result.");
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Get the list of reference from VariableReferenceList.
 /// </summary>
 /// <param name="varRef">VariableReferenceList.</param>
 /// <returns>the list of EcellReference.</returns>
 public static List<EcellReference> ConvertFromEcellValue(EcellValue varRef)
 {
     List<EcellReference> list = new List<EcellReference>();
     if (varRef == null || !varRef.IsList)
         return list;
     foreach (object value in (IEnumerable)varRef.Value)
     {
         EcellReference er = new EcellReference(((IEnumerable)value).GetEnumerator());
         list.Add(er);
     }
     return list;
 }