Пример #1
0
        public int Solution(int[] eastWest)
        {
            // write your code in C# 5.0 with .NET 4.5 (Mono)
            var passings = new Hashtable();

            for (int i = 0; i < eastWest.Length; i++)
            {
                for (int j = 0; j < eastWest.Length; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }

                    var carPair = new CarPair(eastWest,
                                              i,
                                              j);

                    var hashCode   = carPair.GetHashCode();
                    var isContains = passings.ContainsKey(hashCode);

                    if (carPair.IsValid &&
                        !isContains)
                    {
                        passings.Add(hashCode, carPair);
                    }
                }
            }

            var array = new CarPair[passings.Values.Count];

            passings.Values.CopyTo(array, 0);

            return(passings.Values.Count);
        }
Пример #2
0
        public void OneThreeReturnsFalseTest()
        {
            var passingCars = new CarPair(m_EastWest,
                                          1,
                                          3);

            Assert.False(passingCars.IsValid);
        }
Пример #3
0
        public void Setup()
        {
            m_EastWest = new[] { 0, 1, 0, 1, 1 };

            m_CarPair = new CarPair(m_EastWest,
                                    0,
                                    1);

            m_CarPairSwapped = new CarPair(m_EastWest,
                                           1,
                                           0);

            m_CarPairOther = new CarPair(m_EastWest,
                                         2,
                                         3);
        }
Пример #4
0
        public void SameCarIsValidReturnsFalseTest()
        {
            var passingCars = new CarPair(m_EastWest, 2, 2);

            Assert.False(passingCars.IsValid);
        }
Пример #5
0
        public void NonPassingCarsIsValidReturnsFalseTest()
        {
            var passingCars = new CarPair(m_EastWest, 0, 2);

            Assert.False(passingCars.IsValid);
        }