Equals() public méthode

public Equals ( List, a, List, b ) : bool
a List,
b List,
Résultat bool
        public void EmptyLists()
        {
            var comparer = new ListComparer <DateTime>();
            var list1    = new List <DateTime>();
            var list2    = new List <DateTime>();

            Assert.IsTrue(comparer.Equals(list1, list2));
            Assert.AreEqual(comparer.GetHashCode(list2), comparer.GetHashCode(list1));
        }
        public override bool Equals(object obj)
        {
            DataControlRangeDataCollection other = obj as DataControlRangeDataCollection;

            if (other == null)
            {
                return(false);
            }

            return((dataSourceIdentifier == other.dataSourceIdentifier) &&
                   (controlId == other.controlId) &&
                   rangeComparer.Equals(rangeDataList, other.rangeDataList));
        }
        public void DateTimeDifferent()
        {
            var comparer = new ListComparer <DateTime>();
            var list1    = new List <DateTime> {
                new DateTime(2019)
            };
            var list2 = new List <DateTime> {
                new DateTime(2017)
            };

            Assert.IsFalse(comparer.Equals(list1, list2));
            Assert.AreNotEqual(comparer.GetHashCode(list2), comparer.GetHashCode(list1));
        }
        public void Equals_TwoDiferentList_ReturnFalse()
        {
            List <string> list1 = new List <string>();
            List <string> list2 = new List <string>();

            list1.Add("a");
            list2.Add("h");
            list1.Add("b");
            list2.Add("bw");
            list1.Add("c");
            list2.Add("c");
            ListComparer <string> listComparer = new ListComparer <string>(EqualityComparer <string> .Default);

            Assert.IsFalse(listComparer.Equals(list1, list2));
        }
        public void Equals_TwoSameList_ReturnTrue()
        {
            List <string> list1 = new List <string>();
            List <string> list2 = new List <string>();

            list1.Add("a");
            list2.Add("a");
            list1.Add("b");
            list2.Add("b");
            list1.Add("c");
            list2.Add("c");
            ListComparer <string> listComparer = new ListComparer <string>(EqualityComparer <string> .Default);

            Assert.IsTrue(listComparer.Equals(list1, list2));
        }
Exemple #6
0
 public bool Equals([AllowNull] Person x, [AllowNull] Person y)
 {
     if (ReferenceEquals(x, y))
     {
         return(true);
     }
     if (ReferenceEquals(null, y) || ReferenceEquals(null, x))
     {
         return(false);
     }
     return(true &&
            string.Equals(x.LastName, y.LastName) &&
            string.Equals(x.FirstName, y.FirstName) &&
            numbersComparer.Equals(x.Numbers, y.Numbers) &&
            personsComparer.Equals(x.Friends, y.Friends));
 }
        private List <bool> Solve(int[,] maze, List <List <int> > q)
        {
            var qRes           = new List <bool>(q.Count);
            var tempQ          = new List <List <int> >();
            var lastTempLength = tempQ.Count;
            var listComparer   = new ListComparer();

            for (int i = 0; i < q.Count; i++)
            {
                var tempRes = true;
                if (tempQ.Contains(q[i], listComparer))
                {
                    var tt = tempQ.First(x => listComparer.Equals(x, q[i]));
                    tempQ.Remove(tt);
                }
                else
                {
                    tempQ.Add(q[i]);
                }

                if (i > 0 && !qRes[i - 1] && tempQ.Count > lastTempLength)
                {
                    qRes.Add(false);
                    lastTempLength = tempQ.Count;

                    continue;
                }
                else
                {
                    for (int j = 0; j < tempQ.Count; j++)
                    {
                        if (tempQ[j][0] == 0)
                        {
                            var currentPair = tempQ[j];
                            var corners     = new List <List <int> >()
                            {
                                new List <int> {
                                    currentPair[0] + 1, currentPair[1] + 1
                                },
                                new List <int> {
                                    currentPair[0] + 1, currentPair[1] - 1
                                },
                                new List <int> {
                                    currentPair[0] + 1, currentPair[1]
                                },
                            };
                            if (corners.Any(x => tempQ.Contains(x, listComparer)))
                            {
                                lastTempLength = tempQ.Count;

                                tempRes = false;

                                break;
                            }
                        }
                        else if (tempQ[j][0] == 1)
                        {
                            var currentPair = tempQ[j];
                            var corners     = new List <List <int> >()
                            {
                                new List <int> {
                                    currentPair[0] - 1, currentPair[1] + 1
                                },
                                new List <int> {
                                    currentPair[0] - 1, currentPair[1] - 1
                                },
                                new List <int> {
                                    currentPair[0] - 1, currentPair[1]
                                },
                            };
                            if (corners.Any(x => tempQ.Contains(x, listComparer)))
                            {
                                lastTempLength = tempQ.Count;

                                tempRes = false;
                                break;
                            }
                        }
                    }

                    lastTempLength = tempQ.Count;

                    qRes.Add(tempRes);

                    for (int i1 = 0; i1 < 2; i1++)
                    {
                        for (int j1 = 0; j1 < maze.GetLength(1); j1++)
                        {
                            var tt = false;
                            foreach (var item in tempQ)
                            {
                                if (item[0] == i1 && item[1] == j1)
                                {
                                    Console.Write('X');
                                    tt = true;
                                    break;
                                }
                            }
                            if (!tt)
                            {
                                Console.Write('_');
                            }
                        }
                        Console.WriteLine();
                    }
                    Console.WriteLine();
                }
            }

            return(qRes);
        }