Created
October 26, 2016 03:37
-
-
Save toptensoftware/139e03cea3ee549f127b2026898dd298 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyContext : IContext | |
| { | |
| public MyContext(double r) | |
| { | |
| _r = r; | |
| } | |
| double _r; | |
| public double ResolveVariable(string name) | |
| { | |
| switch (name) | |
| { | |
| case "pi": return Math.PI; | |
| case "r": return _r; | |
| } | |
| throw new InvalidDataException($"Unknown variable: '{name}'"); | |
| } | |
| } | |
| [TestMethod] | |
| public void Variables() | |
| { | |
| var ctx = new MyContext(10); | |
| Assert.AreEqual(Parser.Parse("2 * pi * r").Eval(ctx), 2 * Math.PI * 10); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment