Beispiel #1
0
 public void TestGetHashCode()
 {
     EcellValue value1 = new EcellValue(1);
     EcellValue value2 = value1.Clone();
     Assert.AreEqual(value1.GetHashCode(), value2.GetHashCode(), "Clone method returned unexpected result.");
 }
Beispiel #2
0
        public void TestClone()
        {
            EcellValue value = new EcellValue(1);
            EcellValue clonedValue = value.Clone();
            Assert.IsNotNull(clonedValue, "Constructor of type, EcellValue failed to create instance.");
            Assert.AreEqual(value, clonedValue, "Clone method returned unexpected result.");
            Assert.IsTrue(clonedValue.IsInt, "IsInt is not expected value.");
            Assert.IsFalse(clonedValue.IsDouble, "IsDouble is not expected value.");
            Assert.IsFalse(clonedValue.IsList, "IsList is not expected value.");
            Assert.IsFalse(clonedValue.IsString, "IsString is not expected value.");
            Assert.AreEqual(1, (int)clonedValue.Value, "Value is not expected value.");
            Assert.AreEqual(EcellValueType.Integer, clonedValue.Type, "Type is not expected value.");

            // double
            value = new EcellValue(0.01);
            clonedValue = value.Clone();
            Assert.IsNotNull(clonedValue, "Constructor of type, EcellValue failed to create instance.");
            Assert.AreEqual(value, clonedValue, "Clone method returned unexpected result.");
            Assert.IsFalse(clonedValue.IsInt, "IsInt is not expected value.");
            Assert.IsTrue(clonedValue.IsDouble, "IsDouble is not expected value.");
            Assert.IsFalse(clonedValue.IsList, "IsList is not expected value.");
            Assert.IsFalse(clonedValue.IsString, "IsString is not expected value.");
            Assert.AreEqual(0.01, (double)clonedValue.Value, "Value is not expected value.");
            Assert.AreEqual(EcellValueType.Double, clonedValue.Type, "Type is not expected value.");

            // string.
            value = new EcellValue("test");
            clonedValue = value.Clone();
            Assert.IsNotNull(clonedValue, "Constructor of type, EcellValue failed to create instance.");
            Assert.AreEqual((string)value, (string)clonedValue, "Clone method returned unexpected result.");
            Assert.IsFalse(clonedValue.IsInt, "IsInt is not expected value.");
            Assert.IsFalse(clonedValue.IsDouble, "IsDouble is not expected value.");
            Assert.IsFalse(clonedValue.IsList, "IsList is not expected value.");
            Assert.IsTrue(clonedValue.IsString, "IsString is not expected value.");
            Assert.AreEqual("test", (string)clonedValue.Value, "Value is not expected value.");
            Assert.AreEqual(EcellValueType.String, clonedValue.Type, "Type is not expected value.");

            // list
            string str = "((\"S1\", \"Variable:/:S1\", 1, 0), (\"S2\", \"Variable:/:S2\", 1, 1))";
            value = EcellValue.ConvertFromListString(str);
            clonedValue = value.Clone();
            Assert.IsNotNull(clonedValue, "Constructor of type, EcellValue failed to create instance.");
            Assert.AreEqual((string)value, (string)clonedValue, "Clone method returned unexpected result.");
            Assert.IsFalse(clonedValue.IsInt, "IsInt is not expected value.");
            Assert.IsFalse(clonedValue.IsDouble, "IsDouble is not expected value.");
            Assert.IsTrue(clonedValue.IsList, "IsList is not expected value.");
            Assert.IsFalse(clonedValue.IsString, "IsString is not expected value.");
            Assert.AreEqual(str, clonedValue.ToString(), "ToString method returned unexpected value.");
            Assert.AreEqual(EcellValueType.List, clonedValue.Type, "Type is not expected value.");

            object obj = ((ICloneable)value).Clone();
            Assert.IsNotNull(obj, "Constructor of type, EcellValue failed to create instance.");

            try
            {
                obj = null;
                value = new EcellValue(obj);
                EcellValue newValue = value.Clone();
                Assert.Fail("Failed to throw TypeError Exception.");
            }
            catch (EcellException)
            {
            }
        }
Beispiel #3
0
        public void TestEquals()
        {
            // Compare int.
            EcellValue value1 = new EcellValue(1);
            EcellValue value2 = value1.Clone();
            Assert.IsTrue(value1.Equals(value2), "Equals method returned unexpected result.");
            Assert.IsTrue(value1.Equals(1), "Equals method returned unexpected result.");
            Assert.IsFalse(value1.Equals(1.0), "Equals method returned unexpected result.");

            value2 = null;
            Assert.IsFalse(value1.Equals(value2), "Equals method returned unexpected result.");
            Assert.IsFalse(value1.Equals(new object()), "Equals method returned unexpected result.");

            // Compare double.
            value1 = new EcellValue(0.01);
            value2 = value1.Clone();
            Assert.IsTrue(value1.Equals(value2), "Equals method returned unexpected result.");
            Assert.IsTrue(value1.Equals(0.01), "Equals method returned unexpected result.");

            // Compare string.
            value1 = new EcellValue("test");
            value2 = value1.Clone();
            Assert.IsTrue(value1.Equals(value2), "Equals method returned unexpected result.");
            Assert.IsTrue(value1.Equals("test"), "Equals method returned unexpected result.");

            string str = "((\"S1\", \"Variable:/:S1\", 1, 0), (\"S2\", \"Variable:/:S2\", 1, 1))";
            value1 = EcellValue.ConvertFromListString(str);
            value2 = value1.Clone();
            Assert.AreEqual((List<object>)value1.Value, (List<object>)value2.Value, "Equals method returned unexpected result.");
            Assert.IsTrue(value1.Equals((List<object>)value2.Value), "Equals method returned unexpected result.");

            str = "((\"S1\", \"Variable:/:S1\", 1, 0), (\"S3\", \"Variable:/:S3\", 1, 1))";
            value2 = EcellValue.ConvertFromListString(str);
            Assert.AreNotEqual((List<object>)value1.Value, (List<object>)value2.Value, "Equals method returned unexpected result.");
            Assert.IsFalse(value1.Equals((List<object>)value2.Value), "Equals method returned unexpected result.");

            str = "((\"S1\", \"Variable:/:S1\", 1, 0))";
            value2 = EcellValue.ConvertFromListString(str);
            Assert.AreNotEqual((List<object>)value1.Value, (List<object>)value2.Value, "Equals method returned unexpected result.");
            Assert.IsFalse(value1.Equals((List<object>)value2.Value), "Equals method returned unexpected result.");
        }
Beispiel #4
0
        public void TestEquals()
        {
            // double
            bool expectedBoolean = false;
            bool resultBoolean = false;
            EcellData data1 = new EcellData("Value", new EcellValue(1), "Variable:/:Test:Value");
            EcellData data2 = new EcellData("Value1", new EcellValue(1), "Variable:/:Test:Value");
            EcellData data3 = new EcellData("Value", new EcellValue(2), "Variable:/:Test:Value");
            EcellData data4 = new EcellData("Value", new EcellValue(1), "Variable:/:Test:Test");
            EcellData data5 = new EcellData("Value", new EcellValue(1), "Variable:/:Test:Value");

            expectedBoolean = false;
            resultBoolean = data1.Equals(data2);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            expectedBoolean = false;
            resultBoolean = data1.Equals(data3);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            expectedBoolean = false;
            resultBoolean = data1.Equals(data4);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            expectedBoolean = true;
            resultBoolean = data1.Equals(data5);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            // double
            data1 = new EcellData("Value", new EcellValue(0.1), "Variable:/:Test:Value");
            data2 = new EcellData("Value1", new EcellValue(0.1), "Variable:/:Test:Value");
            data3 = new EcellData("Value", new EcellValue(0.2), "Variable:/:Test:Value");
            data4 = new EcellData("Value", new EcellValue(0.1), "Variable:/:Test:Test");
            data5 = new EcellData("Value", new EcellValue(0.1), "Variable:/:Test:Value");

            expectedBoolean = false;
            resultBoolean = data1.Equals(data2);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            expectedBoolean = false;
            resultBoolean = data1.Equals(data3);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            expectedBoolean = false;
            resultBoolean = data1.Equals(data4);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            expectedBoolean = true;
            resultBoolean = data1.Equals(data5);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            // string
            data1 = new EcellData("Value", new EcellValue("Test"), "Variable:/:Test:Value");
            data2 = new EcellData("Value1", new EcellValue("Test"), "Variable:/:Test:Value");
            data3 = new EcellData("Value", new EcellValue("Test2"), "Variable:/:Test:Value");
            data4 = new EcellData("Value", new EcellValue("Test"), "Variable:/:Test:Test");
            data5 = new EcellData("Value", new EcellValue("Test"), "Variable:/:Test:Value");

            expectedBoolean = false;
            resultBoolean = data1.Equals(data2);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            expectedBoolean = false;
            resultBoolean = data1.Equals(data3);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            expectedBoolean = false;
            resultBoolean = data1.Equals(data4);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            expectedBoolean = true;
            resultBoolean = data1.Equals(data5);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            // List
            List<object> list1 = new List<object>();
            list1.Add("Test1");
            EcellValue value1 = new EcellValue(list1);
            List<object> list2 = new List<object>();
            list2.Add("Test2");
            EcellValue value2 = new EcellValue(list2);

            data1 = new EcellData("Value", value1.Clone(), "Variable:/:Test:Value");
            data2 = new EcellData("Value1", value1.Clone(), "Variable:/:Test:Value");
            data3 = new EcellData("Value", value2.Clone(), "Variable:/:Test:Value");
            data4 = new EcellData("Value", value1.Clone(), "Variable:/:Test:Test");
            data5 = new EcellData("Value", value1.Clone(), "Variable:/:Test:Value");

            expectedBoolean = false;
            resultBoolean = data1.Equals(data2);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            expectedBoolean = false;
            resultBoolean = data1.Equals(data3);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            expectedBoolean = false;
            resultBoolean = data1.Equals(data4);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            expectedBoolean = true;
            resultBoolean = data1.Equals(data5);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            expectedBoolean = false;
            resultBoolean = data1.Equals(new object());
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            EcellData data6 = data1.Clone();
            //object obj = null;
            //data6.Value = new EcellValue(obj);
            //expectedBoolean = false;
            //resultBoolean = data1.Equals(data6);
            //Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");
            //resultBoolean = data6.Equals(data1);
            //Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            data6.Value = null;
            resultBoolean = data1.Equals(data6);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");
            resultBoolean = data6.Equals(data1);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            data6 = data1.Clone();
            data6.Gettable = false;
            expectedBoolean = false;
            resultBoolean = data1.Equals(data6);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            data6 = data1.Clone();
            data6.Loadable = false;
            expectedBoolean = false;
            resultBoolean = data1.Equals(data6);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            data6 = data1.Clone();
            data6.Logable = true;
            expectedBoolean = false;
            resultBoolean = data1.Equals(data6);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            data6 = data1.Clone();
            data6.Logged = true;
            expectedBoolean = false;
            resultBoolean = data1.Equals(data6);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            data6 = data1.Clone();
            data6.Saveable = false;
            expectedBoolean = false;
            resultBoolean = data1.Equals(data6);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");

            data6 = data1.Clone();
            data6.Settable = false;
            expectedBoolean = false;
            resultBoolean = data1.Equals(data6);
            Assert.AreEqual(expectedBoolean, resultBoolean, "Equals method returned unexpected result.");
        }