示例#1
0
        public void ShouldNotCompile(string code)
        {
            var compiler          = new AiCompiler();
            var compilationResult = compiler.Compile(code);

            Assert.False(compilationResult.IsOk);
            Assert.NotEmpty(compilationResult.Errors);
            Assert.All(compilationResult.Errors, error =>
                       Assert.Equal(ErrorLevel.Error, error.Severity));
        }
示例#2
0
        public void ShouldNotRun(string code, Type runtimeError)
        {
            var compiler          = new AiCompiler();
            var compilationResult = compiler.Compile(code);

            Assert.True(compilationResult.IsOk, "Compilation failed");

            var ai    = compilationResult.Ai;
            var state = new TrackState
            {
                Car = new Car(4, 11),
            };

            var aiResult = ai.Run(state);

            Assert.False(aiResult.IsOk);
            Assert.Equal(runtimeError, aiResult.RuntimeException.GetType());
        }
示例#3
0
        public void ShouldCompileAndRun(string code, int speed)
        {
            var compiler          = new AiCompiler();
            var compilationResult = compiler.Compile(code);

            Assert.True(compilationResult.IsOk, $"Compilation failed");

            var ai    = compilationResult.Ai;
            var state = new TrackState
            {
                Car = new Car(4, 11),
            };

            var aiResult = ai.Run(state);

            Assert.Equal(speed, aiResult.Speed);
            Assert.InRange(aiResult.ExecutionTime, TimeSpan.FromMilliseconds(0), TimeSpan.FromMilliseconds(100));
        }