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); } }
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); }
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); } }
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); } }
//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); }