예제 #1
0
        public void ParseStringAndObjectTest()
        {
            ParseTree tree = _parser.Parse(INST_3);

            Assert.IsNotNull(tree);

            Tuple t = (Tuple)tree.Eval(null);

            Assert.IsNotNull(t);

            _fields2.Add("dog");
            _fields2.Add(new DADTestA(1, "Cat"));

            _tuple2 = new Tuple(_fields2);

            Assert.AreEqual(_tuple2.GetNumberOfFields(), t.GetNumberOfFields());

            Assert.AreEqual(_tuple2, t);
        }
예제 #2
0
파일: Tuple.cs 프로젝트: vsnunes/dad1819
        /// <summary>
        /// Given two tuples check if they are equals.
        /// Be aware that Equals support all WildCards operations. So <"dog", "*"> is equal to <"dog", "brown">.
        /// </summary>
        /// <param name="obj">An object of type Tuple to compare</param>
        /// <returns>True if the two objects are the same (or wild-identical). False otherwise. </returns>
        public override bool Equals(object obj)
        {
            //If other than Tuple object is given return false immediately
            if (obj.GetType() == this.GetType())
            {
                Tuple tuple = obj as Tuple;
                // 1 -> Starts by comparing the number of fields of two tuples
                int numberOfFields = this.GetNumberOfFields();
                if (tuple.GetNumberOfFields() == numberOfFields)
                {
                    List <Object> otherObjects = tuple.GetAllFields();
                    for (int i = 0; i < numberOfFields; i++)
                    {
                        // 2 -> Compare the types of the fields.
                        //When tuple fields are string instead of calling equals method call the wildcomparator
                        //to check for wildcards in strings
                        if (tuple.GetFieldByNumber(i).GetType() == typeof(string))
                        {
                            if (this.GetFieldByNumber(i) == null)
                            {
                                return(false);
                            }

                            if (this.GetFieldByNumber(i).GetType() != typeof(string))
                            {
                                //Wildcard support of class name using objects
                                if (WildComparator(tuple.GetFieldByNumber(i) as string, this.GetFieldByNumber(i)) == false)
                                {
                                    return(false);
                                }
                            }
                            else if (WildComparator(tuple.GetFieldByNumber(i) as string, this.GetFieldByNumber(i) as string) == false)
                            {
                                return(false);
                            }
                        }
                        // 3 -> Cross comparation
                        // Wild card can be on this object or on obj argument
                        else if (this.GetFieldByNumber(i).GetType() == typeof(string))
                        {
                            if (tuple.GetFieldByNumber(i) == null)
                            {
                                return(false);
                            }

                            if (tuple.GetFieldByNumber(i).GetType() != typeof(string))
                            {
                                //Wildcard support of class name using objects
                                if (WildComparator(this.GetFieldByNumber(i) as string, tuple.GetFieldByNumber(i)) == false)
                                {
                                    return(false);
                                }
                            }
                            else if (WildComparator(this.GetFieldByNumber(i) as string, tuple.GetFieldByNumber(i) as string) == false)
                            {
                                return(false);
                            }
                        }

                        else if (!(this.GetFieldByNumber(i).Equals(tuple.GetFieldByNumber(i))))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            }
            return(false);
        }