Beispiel #1
0
        public void should_return_lowest_above_value_for_first_and_intermidiate_elements()
        {
            SortedDictionary <double, double> collection = new SortedDictionary <double, double>
            {
                { 0.25, 1 },
                { 0.5, 3 },
                { 0.75, 4 },
                { 1, 9 },
                { 1.25, 10 },
                { 1.5, 16 },
                { 2, 18 },
                { 3, 21 },
                { 4, 34 },
                { 5, 18 },
                { 6, 21 },
                { 7, 34 },
                { 8, 18 },
                { 9, 21 },
                { 10, 34 }
            };

            double val1 = 0.26;
            double val2 = 0.37;
            double val3 = 2.12;
            double val4 = 9.25;

            double key1 = Tools.FindLowestAbove(collection, val1);
            double key2 = Tools.FindLowestAbove(collection, val2);
            double key3 = Tools.FindLowestAbove(collection, val3);
            double key4 = Tools.FindLowestAbove(collection, val4);

            Assert.IsTrue(key1.Equals(0.5) && key2.Equals(0.5) && key3.Equals(3) && key4.Equals(10));
        }
Beispiel #2
0
        public void should_throw_exception_if_no_value_in_dictionary_above_the_key()
        {
            SortedDictionary <double, double> collection = new SortedDictionary <double, double>
            {
                { 0.25, 1 },
                { 0.5, 3 },
                { 0.75, 4 },
                { 1, 9 },
                { 1.25, 10 },
                { 1.5, 16 },
                { 2, 18 },
                { 3, 21 },
                { 4, 34 },
                { 5, 18 },
                { 6, 21 },
                { 7, 34 },
                { 8, 18 },
                { 9, 21 },
                { 10, 34 }
            };

            double val1 = 10;
            double val2 = 10.01;

            int nbExceptions = 0;

            try
            {
                double key1 = Tools.FindLowestAbove(collection, val1);
            }
            catch (Exception e)
            {
                nbExceptions++;
            }

            try
            {
                double key2 = Tools.FindLowestAbove(collection, val2);
            }
            catch (Exception e)
            {
                nbExceptions++;
            }

            Assert.IsTrue(nbExceptions == 2);
        }