Guest User

Untitled

a guest
Jun 29th, 2018
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. public static decimal Round(decimal userNumber)
  2. {
  3. return Math.Round(userNumber);
  4. }
  5.  
  6. public static decimal Round(decimal userNumber, int decimals)
  7. {
  8. return Math.Round(userNumber, decimals);
  9. }
  10.  
  11. [Test]
  12. public void Stackoverflow_Issue()
  13. {
  14. var interpreter = new Interpreter();
  15.  
  16. Func<decimal, decimal> roundFunction1 = (userNumber) => Round(userNumber);
  17. Func<decimal, int, decimal> roundFunction2 = (userNumber, decimals) => Round(userNumber, decimals);
  18.  
  19. interpreter.SetFunction("ROUND", roundFunction1);
  20. interpreter.SetFunction("ROUND", roundFunction2);
  21.  
  22. var x = 666.66M;
  23. interpreter.SetVariable("x", x);
  24.  
  25. Assert.AreEqual(Round(x, 3), interpreter.Eval("ROUND(x, 3)"));
  26. Assert.AreEqual(Round(x, 1), interpreter.Eval("ROUND(x, 1)"));
  27. }
Advertisement
Add Comment
Please, Sign In to add comment