示例#1
0
        public void RaiseMoreThanThreeParameters()
        {
            RangeFunction function = new RangeFunction();

            try
            {
                function.Apply(null, new object[] { 1, 2, 3, 4 }, null);
                Assert.Fail("Exception expected");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(TypeError));
                Assert.AreEqual("range expected at most 3 arguments, got 4", ex.Message);
            }
        }
示例#2
0
        public void CreateRangeWithThreeParameters()
        {
            RangeFunction function = new RangeFunction();

            var result = function.Apply(null, new object[] { 1, -2, -1 }, null);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(Range));

            var range = (Range)result;

            Assert.AreEqual(1, range.From);
            Assert.AreEqual(-2, range.To);
            Assert.AreEqual(-1, range.Step);
        }
示例#3
0
        public void RaiseWhenNoParameters()
        {
            RangeFunction function = new RangeFunction();

            try
            {
                function.Apply(null, new object[] { }, null);
                Assert.Fail("Exception expected");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(TypeError));
                Assert.AreEqual("range expected 1 arguments, got 0", ex.Message);
            }
        }
示例#4
0
        public void RaiseIfSomeParameterIsFloat()
        {
            RangeFunction function = new RangeFunction();

            try
            {
                function.Apply(null, new object[] { 1.0, 2, 3 }, null);
                Assert.Fail("Exception expected");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(TypeError));
                Assert.AreEqual("'float' object cannot be interpreted as an integer", ex.Message);
            }
        }
示例#5
0
        //Function that converts a string to a number and verifies if its within range, unifies various functions
        //Requiere the mmin, max value of the value and also the function to check if its in range
        public static T NumberValidation <T>(T min, T max, RangeFunction <T> range, string message)
        {
            T    value = default(T);
            bool flag  = false;

            do
            {
                value = NumberConversion <T>(message);
                if (range(value, min, max))
                {
                    flag = true;
                }
            } while (flag == false);

            return(value);
        }