本文整理汇总了C#中Evaluator.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# Evaluator.Evaluate方法的具体用法?C# Evaluator.Evaluate怎么用?C# Evaluator.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Evaluator
的用法示例。
在下文中一共展示了Evaluator.Evaluate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDoubleArithmetic
public void TestDoubleArithmetic()
{
Evaluator e = new Evaluator();
Assert.AreEqual(5.0, e.Evaluate("2.5 * 2").As<double>());
Assert.AreEqual(5.0, e.Evaluate("2.5 * 2").As<double>());
Assert.AreEqual(5, e.Evaluate("2.6 * 2").As<int>());
Assert.AreEqual(5.2, e.Evaluate("2.6 * 2").As<double>());
}
示例2: TestEvaluation
public void TestEvaluation()
{
var evaluator = new Evaluator();
object actual = evaluator.Evaluate("1 + 2 * 3");
Assert.IsTrue(actual is int);
Assert.AreEqual(7, (int)actual);
actual = evaluator.Evaluate("3 + 5 * (-2 ** 7 - 8/2)");
Assert.IsTrue(actual is int);
Assert.AreEqual(-657, (int)actual);
}
示例3: Setup
private static IEnvironment Setup(string program)
{
var evaluator = new Evaluator();
var reader = new Reader();
foreach (string lispThing in NihilEntryPoint.GetBasicLispThings())
{
evaluator.Evaluate(reader.Read(lispThing, evaluator.Environment));
}
evaluator.Evaluate(reader.Read(program, evaluator.Environment));
return evaluator.Environment;
}
示例4: FloodFill
public void FloodFill()
{
Bitmap map = new Bitmap(new string[]
{
"111111111111111111",
"100000000000001001",
"100000000000001001",
"100001111111001001",
"100001010001001001",
"100001000101001001",
"100001111111000001",
"111011000000001111",
"100000001000010001",
"100000001000010001",
"111111111111111111"
});
Debug.WriteLine(map.ToString());
Evaluator<LocationNode> eval = new Evaluator<LocationNode>();
FloodFillStrategy strategy = new FloodFillStrategy(map, new VectorInt(2, 2));
eval.Evaluate(strategy);
Debug.WriteLine(strategy.Result.ToString());
List<LocationNode> path = strategy.GetShortestPath(new VectorInt(9, 9));
Assert.IsNotNull(path);
Debug.WriteLine(StringHelper.Join(path, delegate(LocationNode node) { return node.Location.ToString(); }, ", "));
Debug.WriteLine(map.ToString());
// Expected value
Assert.AreEqual(new VectorInt(9, 9), path[path.Count - 1].Location);
}
示例5: OnFirstRun
/// <summary>Called when [first run].</summary>
///
/// <exception cref="InvalidDataException">Thrown when an Invalid Data error condition occurs.</exception>
protected override void OnFirstRun()
{
if (varName != null)
return;
var declaration = Condition.TrimEnd().TrimEnd(';');
var parts = declaration.Split('=');
if (parts.Length != 2)
throw new InvalidDataException(
"Invalid var declaration, should be '@var varName = {MemberExpression} [, {VarDeclaration}]' was: " + declaration);
varName = parts[0].Trim();
memberExpr = parts[1].Trim();
this.Condition = memberExpr;
const string methodName = "resolveVarType";
var exprParams = GetExprParams();
var evaluator = new Evaluator(ReturnType, Condition, methodName, exprParams);
var result = evaluator.Evaluate(methodName, GetParamValues(ScopeArgs).ToArray());
ScopeArgs[varName] = result;
if (result != null)
this.ReturnType = result.GetType();
base.OnFirstRun();
}
示例6: TestMethod5
public void TestMethod5()
{
var evaluator = new Evaluator();
var reader = new Reader();
var program = "((lambda () #t))";
var sexp = reader.Read(program, evaluator.Environment);
var rexp = evaluator.Evaluate(sexp);
}
示例7: GenerateStaticMoveMap
/// <summary>
/// Generate a static move map, ie. all positions for which a player could move to in the course of a puzzle
/// </summary>
/// <param name="Map"></param>
/// <returns></returns>
public static Bitmap GenerateStaticMoveMap(SokobanMap Map)
{
Bitmap boundry = GenerateBoundryMap(Map);
// Flood fill from player position to remove any unreachable positions
FloodFillStrategy floodFill = new FloodFillStrategy(boundry, Map.Player);
Evaluator<LocationNode> eval = new Evaluator<LocationNode>();
eval.Evaluate(floodFill);
return floodFill.Result;
}
示例8: EvaluatorEvaluate
public void EvaluatorEvaluate()
{
Parser parser = new Parser();
Evaluator evaluator = new Evaluator();
string expr = "3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3";
object result = evaluator.Evaluate(parser.Parse(expr));
Assert.IsNotNull(result);
Assert.IsInstanceOfType(result, typeof(double));
Assert.IsTrue((double)result > 3);
Assert.IsTrue((double)result < 3.01);
}
示例9: GenerateMoveMap
/// <summary>
/// Generate the move map for a current position
/// </summary>
/// <param name="boundryMap"></param>
/// <param name="crateMap">May be null, assumes boundryMap is constraintmap</param>
/// <param name="playerPosition"></param>
/// <returns></returns>
public static Bitmap GenerateMoveMap(Bitmap boundryMap, Bitmap crateMap, VectorInt playerPosition)
{
Bitmap constraints = boundryMap;
if (crateMap != null) constraints = boundryMap.BitwiseOR(crateMap);
// Flood fill from player position to remove any unreachable positions
FloodFillStrategy floodFill = new FloodFillStrategy(constraints, playerPosition);
Evaluator<LocationNode> eval = new Evaluator<LocationNode>();
eval.Evaluate(floodFill);
return floodFill.Result;
}
示例10: EvaluatorInvalidFail
public void EvaluatorInvalidFail()
{
Evaluator evaluator = new Evaluator();
ExpressionQueue expression = new ExpressionQueue("4 + 5 +");
expression.Enqueue(new Operand(4));
expression.Enqueue(new Operand(5));
expression.Enqueue(new RaspyOperator('+', Associativity.Left, 2, 2));
expression.Enqueue(new RaspyOperator('+', Associativity.Left, 2, 2));
evaluator.Evaluate(expression);
}
示例11: Test
public void Test()
{
var evaluator = new Evaluator<Person>(
Rule<Person>.When(p => p.Age > 20).And(p => p.Name != "Tomas").ClassifyAs("OldTomas"),
Rule<Person>.When(p => p.Age < 20).And(p => p.Name == "Ignac").ClassifyAs("IgnacClass")
);
var person = new Person() { Age = 10, Name = "Ignac" };
var c = evaluator.Evaluate(person);
Assert.AreEqual("IgnacClass", c.Name);
}
示例12: CanEvaluatePlayer
public void CanEvaluatePlayer()
{
var data = new Hashtable();
data["Name"] = "Blah";
data["Team"] = "Bears";
data["WeeklyScores"] = new double[] { 0.1, 0.0, 0.0 };
var scorer = new ThumbsUpScorer();
var parser = new PlayerParser();
var evaluator = new Evaluator(parser, scorer);
var evaluation = evaluator.Evaluate(data);
Assert.AreEqual("You should acquire Blah.", evaluation);
}
示例13: FindPlayerPath
/// <summary>
/// Find the shortest path from the player position to a destination position
/// </summary>
/// <param name="Map">Map</param>
/// <param name="Destination">Destination goal position</param>
/// <returns>NULL if no path is found</returns>
public static List<VectorInt> FindPlayerPath(SokobanMap Map, VectorInt Destination)
{
Bitmap boundry = MapAnalysis.GenerateBoundryMap(Map);
boundry = boundry.BitwiseOR(MapAnalysis.GenerateCrateMap(Map));
// Find all positble moves for the player
FloodFillStrategy floodFill = new FloodFillStrategy(boundry, Map.Player);
Evaluator<LocationNode> eval = new Evaluator<LocationNode>();
eval.Evaluate(floodFill);
List<LocationNode> result = floodFill.GetShortestPath(Destination);
if (result == null) return null;
// Path found, convert to VectoInt
return result.ConvertAll<VectorInt>(delegate(LocationNode item) { return item.Location; });
}
示例14: CreateType
public Type CreateType(string code, IEnumerable<Assembly> references, bool emitDebugInfo)
{
code = CodeParser.RandomNamespaceGenerate(code);
var evaluator = new Evaluator(
new CompilerContext(
new CompilerSettings
{
GenerateDebugInfo = emitDebugInfo,
Optimize = emitDebugInfo,
LoadDefaultReferences = !Host.IsWebApp()
},
_printer));
if (references == null)
{
references = AppDomain.CurrentDomain.GetAssemblies()
.Where(
x => x.GetName()
.Name != "mscorlib");
}
references.ToList().ForEach(evaluator.ReferenceAssembly);
evaluator.Compile(code);
var assemblies = this.GetDynamicAssemblies();
Type result = null;
if (assemblies.Any())
{
result = assemblies.LastOrDefault().GetTypes().FirstOrDefault();
}
else
{
var evaluate = string.Format(
"typeof({0}.{1});",
Regex.Match(code, Constants.Regex.Namespace).Value.Trim(),
Regex.Match(code, Constants.Regex.ClassName).Value.Trim());
result = (Type)evaluator.Evaluate(evaluate);
}
return result;
}
示例15: TestReverseStrategyCoreSimple
public void TestReverseStrategyCoreSimple()
{
CodeTimer timer = new CodeTimer("");
timer.Start();
try
{
SokobanMap map = new SokobanMap();
map.SetFromStrings(new string[]
{
"~##~#####",
"##.##.O.#",
"#.##.XO.#",
"~##.X...#",
"##.XP.###",
"#.X..##~~",
"#OO.##.##",
"#...#~##~",
"#####~#~~"
});
PuzzleMap pMap = new PuzzleMap((Puzzle)null);
pMap.Map = map;
SolverController controller = new SolverController(pMap);
controller.Init();
controller.State = SolverController.States.Running; // Manually set state, as we are not using the controller; but the strategy uses the controller to check if it should exit
ReverseStrategy rev = new ReverseStrategy(controller);
Evaluator<SolverNode> eval = new Evaluator<SolverNode>();
EvalStatus result = eval.Evaluate(rev);
Assert.AreEqual(EvalStatus.CompleteSolution, result, "Should find a solution");
}
finally
{
timer.Stop();
System.Console.WriteLine("Total Time: " + timer.Duration(1));
}
}