Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. class MyLibrary
  2. {
  3. public MyLibrary()
  4. {
  5. pi = Math.PI;
  6. }
  7.  
  8. public double pi { get; private set; }
  9. public double r { get; set; }
  10.  
  11. public double rectArea(double width, double height)
  12. {
  13. return width * height;
  14. }
  15.  
  16. public double rectPerimeter(double width, double height)
  17. {
  18. return (width + height) * 2;
  19. }
  20. }
  21.  
  22. [TestMethod]
  23. public void Reflection()
  24. {
  25. // Create a library of helper function
  26. var lib = new MyLibrary();
  27. lib.r = 10;
  28.  
  29. // Create a context that uses the library
  30. var ctx = new ReflectionContext(lib);
  31.  
  32. // Test
  33. Assert.AreEqual(Parser.Parse("rectArea(10,20)").Eval(ctx), 200);
  34. Assert.AreEqual(Parser.Parse("rectPerimeter(10,20)").Eval(ctx), 60);
  35. Assert.AreEqual(Parser.Parse("2 * pi * r").Eval(ctx), 2 * Math.PI * 10);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement