Exemple #1
0
        public void UnitRdx_ElementsBetweenIndexes()
        {
            int n  = 30;
            var rd = new RankedDictionary <int, int> {
                Capacity = 4
            };

            for (int ii = 0; ii < n; ++ii)
            {
                rd.Add(ii, -ii);
            }

            for (int p1 = 0; p1 < n; ++p1)
            {
                for (int p2 = p1; p2 < n; ++p2)
                {
                    int actual = 0;
                    foreach (var pair in rd.ElementsBetweenIndexes(p1, p2))
                    {
                        actual += pair.Key;
                    }

                    int expected = (p2 - p1 + 1) * (p1 + p2) / 2;
                    Assert.AreEqual(expected, actual);
                }
            }
        }
Exemple #2
0
        public void CrashRdx_ElementsBetweenIndexes_Argument()
        {
            var rd = new RankedDictionary <int, int> {
                { 0, 0 }, { 1, -1 }, { 2, -2 }
            };

            foreach (var pair in rd.ElementsBetweenIndexes(2, 1))
            {
            }
        }
Exemple #3
0
        public void CrashRdx_ElementsBetweenIndexes_ArgumentOutOfRangeD()
        {
            var rd = new RankedDictionary <int, int> {
                { 0, 0 }, { 1, -1 }
            };

            foreach (var pair in rd.ElementsBetweenIndexes(0, 2))
            {
            }
        }