コード例 #1
0
        public void AreContainerNotCorrectMoreChilds()
        {
            var clone = root.CloneWithChilds;

            clone.AddChild(FunctionContainer.CreateFunctionContainer_ConstArg(2));
            Assert.IsFalse(clone.IsCorrect());
        }
コード例 #2
0
        public void CreateProgramTest()
        {
            string source      = CompileServiceLanguageSourceCode.CPPCorrectSourceCode;
            int    timelimit   = 1;
            int    memorylimit = 1;

            Program program = FunctionContainer.CreateProgram(source, memorylimit, timelimit);

            Assert.AreEqual(program.Source, source);
            Assert.AreEqual(program.TimeLimit, timelimit);
            Assert.AreEqual(program.MemoryLimit, memorylimit);

            timelimit = -1;
            try
            {
                program = FunctionContainer.CreateProgram(source, memorylimit, timelimit);
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }

            timelimit   = 1;
            memorylimit = -1;
            try
            {
                program = FunctionContainer.CreateProgram(source, memorylimit, timelimit);
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: 9139876/PetProject
        static void TestHashSet()
        {
            ICrossedTree root = FunctionContainer.CreateFunctionContainer_TwoArgs("Сложение");

            ICrossedTree sin = FunctionContainer.CreateFunctionContainer_OneArg("Синус");

            ICrossedTree cos = FunctionContainer.CreateFunctionContainer_OneArg("Косинус");

            ICrossedTree arg1 = FunctionContainer.CreateFunctionContainer_SameArgs(1);

            ICrossedTree arg2 = FunctionContainer.CreateFunctionContainer_SameArgs(2);

            root.AddChild(sin);
            root.AddChild(cos);

            sin.AddChild(arg1);
            cos.AddChild(arg2);

            HashSet <ICrossedTree> crossedTrees = new HashSet <ICrossedTree>();

            crossedTrees.Add(root);
            crossedTrees.Add(root);
            crossedTrees.Add(root);
            crossedTrees.Add(root);

            Console.WriteLine(crossedTrees.Count);

            crossedTrees.Add(root.Clone);
            crossedTrees.Add(root.Clone);
            crossedTrees.Add(root.Clone);

            Console.WriteLine(crossedTrees.Count);
        }
コード例 #4
0
        public void CreateCompilationTesterTest()
        {
            Settings          settings = FunctionContainer.CreateDefaultSetting();
            CompilationTester tester;

            try
            {
                tester = FunctionContainer.CreateCompilationTester(settings);
                Assert.AreEqual(tester.Settings, settings);
            }
            catch (Exception)
            {
                Assert.AreEqual(false, true);
            }

            try
            {
                tester = FunctionContainer.CreateCompilationTester(null);
                Assert.AreEqual(false, true);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }
        }
コード例 #5
0
        public void CreateDefaultSettingTest()
        {
            Settings defaultSettings = FunctionContainer.CreateDefaultSetting();

            Assert.AreEqual(defaultSettings.TestingDirectory.Length > 0, true);
            Assert.AreNotEqual(defaultSettings.Compilers, null);
        }
コード例 #6
0
        public void AssignLanguageForProgramTest()
        {
            string  languageString = "CPP";
            string  result;
            Program program = new Program();

            result = FunctionContainer.AssignLanguageForProgram(languageString, ref program);
            Assert.AreEqual(result, String.Empty);
            Assert.AreEqual(program.Language, Language.VC8);

            languageString = "CS";
            result         = FunctionContainer.AssignLanguageForProgram(languageString, ref program);
            Assert.AreEqual(result, String.Empty);
            Assert.AreEqual(program.Language, Language.CSharp3);

            languageString = "Java";
            result         = FunctionContainer.AssignLanguageForProgram(languageString, ref program);
            Assert.AreEqual(result, String.Empty);
            Assert.AreEqual(program.Language, Language.Java6);

            languageString = "Delphi";
            result         = FunctionContainer.AssignLanguageForProgram(languageString, ref program);
            Assert.AreEqual(result, String.Empty);
            Assert.AreEqual(program.Language, Language.Delphi7);

            languageString = "cpp";
            result         = FunctionContainer.AssignLanguageForProgram(languageString, ref program);
            Assert.AreEqual(result, "Unsupported language");

            languageString = "unknown";
            result         = FunctionContainer.AssignLanguageForProgram(languageString, ref program);
            Assert.AreEqual(result, "Unsupported language");
        }
コード例 #7
0
        public void AreContainerNotCorrectLessChilds()
        {
            var clone = root.CloneWithChilds;

            clone.ChangeChild(clone.Childs.First(), FunctionContainer.CreateFunctionContainer_TwoArgs("Сложение"));
            Assert.IsFalse(clone.IsCorrect());
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: 9139876/PetProject
        static void Test2()
        {
            List <double> args   = new List <double>();
            List <double> etalon = new List <double>();

            foreach (var str in Resources.Example_Sin_Exp_.Split('\n'))
            {
                args.Add(double.Parse(str.Split(';')[0]));
                etalon.Add(double.Parse(str.Split(';')[1]));
            }

            var gen = new Generator(1, 2);

            while (true)
            {
                int counter = 50, error = 5, step = 0;

                FunctionContainer funcC = null;

                EvolutionaryAlgorithm.Errors errors = null;

                for (int i = 0; i < counter; i++)
                {
                    do
                    {
                        funcC = gen.GenerateFunctionContainer(null);
                    } while (!funcC.CorrectWorkByArguments(args.Select(a => new double[] { a }).ToList()));

                    var calculated = args.Select(a => funcC.Calc(new double[] { a })).ToList();

                    errors = new EvolutionaryAlgorithm.Errors(etalon, calculated);

                    step = i;

                    if (errors.DifferentialError <= error)
                    {
                        break;
                    }
                }

                Console.WriteLine($"\n\n\nstep = {step}");



                Console.WriteLine("Example_Sin_Exp_\n");
                Console.WriteLine(funcC.ToString() + "\n");

                Console.WriteLine($"DifferentialError = {errors.DifferentialError}");
                Console.WriteLine($"DifferentialExpError = {errors.DifferentialExpError}");
                Console.WriteLine($"ExpError = {errors.ExpError}");
                Console.WriteLine($"LogError = {errors.LogError}");
                Console.WriteLine($"SimpleError = {errors.SimpleError}");

                Console.ReadKey();
            }
        }
コード例 #9
0
        public void GenerateFileForCompilationTest()
        {
            Settings          settings = FunctionContainer.CreateDefaultSetting();
            CompilationTester compilationTester = new CompilationTester(settings);
            string            source, programPath;
            Language          language;

            //language tests
            source      = CompileServiceLanguageSourceCode.CSCorrectSourceCode;
            language    = Language.CSharp3;
            programPath = compilationTester.GenerateFileForCompilation(source, language);
            Assert.AreEqual(true, CompileServiceHelper.ValidatePath(programPath));

            source      = CompileServiceLanguageSourceCode.CPPCorrectSourceCode;
            language    = Language.VC8;
            programPath = compilationTester.GenerateFileForCompilation(source, language);
            Assert.AreEqual(true, CompileServiceHelper.ValidatePath(programPath));

            source      = CompileServiceLanguageSourceCode.JavaCorrectSourceCode;
            language    = Language.Java6;
            programPath = compilationTester.GenerateFileForCompilation(source, language);
            Assert.AreEqual(true, CompileServiceHelper.ValidatePath(programPath));

            source      = CompileServiceLanguageSourceCode.DelphiCorrectSourceCode;
            language    = Language.Delphi7;
            programPath = compilationTester.GenerateFileForCompilation(source, language);
            Assert.AreEqual(true, CompileServiceHelper.ValidatePath(programPath));

            //incorrect source
            source   = "";
            language = Language.CSharp3;
            try
            {
                programPath = compilationTester.GenerateFileForCompilation(source, language);
                Assert.AreEqual(false, true);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }

            //incorrect compiler
            settings.Compilers = new List <Compiler>();
            compilationTester  = new CompilationTester(settings);
            source             = "";
            language           = Language.CSharp3;
            try
            {
                programPath = compilationTester.GenerateFileForCompilation(source, language);
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }
        }
コード例 #10
0
ファイル: RunnerTest.cs プロジェクト: nbl852003/iudico
        public void ExecuteIncorrectParametersTest()
        {
            CompilationTester tester = new CompilationTester(FunctionContainer.CreateDefaultSetting());
            string            programPath;
            string            exeString;
            Program           program = FunctionContainer.CreateProgram("", 10000, 100000);
            Result            result;

            try
            {
                //-----------CS-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.CSCorrectSourceCode,
                                                                Language.CSharp3);
                exeString          = Path.ChangeExtension(programPath, "exe");
                program.InputTest  = "2";
                program.OutputTest = "23";
                program.Language   = Language.CSharp3;
                result             = Runner.Execute(exeString, program);
                Assert.AreNotEqual(result.ProgramStatus, Status.Accepted);

                //-----------CPP-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.CPPCorrectSourceCode,
                                                                Language.VC8);
                exeString          = Path.ChangeExtension(programPath, "exe");
                program.InputTest  = "2";
                program.OutputTest = "23";
                program.Language   = Language.VC8;
                result             = Runner.Execute(exeString, program);
                Assert.AreNotEqual(result.ProgramStatus, Status.Accepted);

                //-----------Java-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.JavaCorrectSourceCode,
                                                                Language.Java6);
                exeString          = Path.ChangeExtension(programPath, "exe");
                program.InputTest  = "2";
                program.OutputTest = "23";
                program.Language   = Language.Java6;
                result             = Runner.Execute(exeString, program);
                Assert.AreNotEqual(result.ProgramStatus, Status.Accepted);

                //-----------Delphi-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.DelphiCorrectSourceCode,
                                                                Language.Delphi7);
                exeString          = Path.ChangeExtension(programPath, "exe");
                program.InputTest  = "";
                program.OutputTest = " world!";
                program.Language   = Language.Delphi7;
                result             = Runner.Execute(exeString, program);
                Assert.AreNotEqual(result.ProgramStatus, Status.Accepted);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, false);
            }
        }
コード例 #11
0
        public void NotCorrectFunc()
        {
            var fc = FunctionContainer.CreateFunctionContainer_OneArg("Арксинус");

            fc.AddChild(FunctionContainer.CreateFunctionContainer_SameArgs(3));

            Assert.IsFalse(fc.CorrectWorkByArguments(new System.Collections.Generic.List <double[]>()
            {
                args
            }));
        }
コード例 #12
0
        private void buttonResolve_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            TreeListNode parentNode = treeListReferencedFiles.FocusedNode;

            while (parentNode.ParentNode != null && (parentNode.Tag == null || parentNode.Tag.GetType() != typeof(FunctionContainer)))
            {
                parentNode = parentNode.ParentNode;
            }
            FunctionContainer funcContainer = FunctionContainerDisplayedInEditors;

            syntaxEditorCurrent.SuspendPainting();

            for (int i = syntaxEditorCurrent.Document.Lines.Count - 1; i >= 0; i--)
            {
                if (syntaxEditorCurrent.Document.Lines[i].BackColor == Color.LightGray)
                {
                    syntaxEditorCurrent.Document.Lines.RemoveAt(i);
                }
            }
            funcContainer.MyFunction.Body = funcContainer.TheirFunction.Body = syntaxEditorCurrent.Text;

            if (FunctionsAreDifferent(funcContainer.MyFunction, funcContainer.TheirFunction))
            {
                // Don't delete node, just remove the 'code differences' text
                parentNode.SetValue(1, "");
                syntaxEditorCurrent.Visible  = false;
                syntaxEditorExternal.Visible = false;
                ucHeading1.Text = string.Format("{0}: no code differences", funcContainer.MyFunction.Name);
            }
            else
            {
                TreeListNode topLevelNode = parentNode.ParentNode;
                int          nodeIndex    = topLevelNode.Nodes.IndexOf(parentNode);

                // Remove the node
                if (topLevelNode.Nodes.Count > nodeIndex)
                {
                    treeListReferencedFiles.FocusedNode = topLevelNode.Nodes[nodeIndex];
                }
                else if (topLevelNode.Nodes.Count > 1)
                {
                    treeListReferencedFiles.FocusedNode = topLevelNode.Nodes[nodeIndex - 1];
                }
                else                 // This was the only node in the tree
                {
                    treeListReferencedFiles.FocusedNode = topLevelNode;
                }
                topLevelNode.Nodes.Remove(parentNode);
            }
            syntaxEditorCurrent.ResumePainting();
            Cursor = Cursors.Default;
        }
コード例 #13
0
        public void DelphiIncorrectCodeCompileTest()
        {
            CompilationTester tester = new CompilationTester(FunctionContainer.CreateDefaultSetting());
            string            programPath;
            CompileResult     result;

            try
            {
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.DelphiIncorrectSourceCode,
                                                                Language.Delphi7);
                result = Compiler.Delphi7Compiler.Compile(programPath);
                CompileServiceHelper.ValidateIncorrectCompilationResult(result);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, false);
            }
        }
コード例 #14
0
        public void AssignLanguageForProgramTest()
        {
            string  languageString = "CPP";
            string  result;
            Program program = new Program();

            result = FunctionContainer.AssignLanguageForProgram(languageString, ref program);

            Assert.AreEqual(result, String.Empty);

            languageString = "cpp";
            result         = FunctionContainer.AssignLanguageForProgram(languageString, ref program);
            Assert.AreEqual(result, "Unsupported language");

            languageString = "unknown";
            result         = FunctionContainer.AssignLanguageForProgram(languageString, ref program);
            Assert.AreEqual(result, "Unsupported language");
        }
コード例 #15
0
        public void Successfully_RegisterAllFunctions()
        {
            var registry = new FunctionRegistry();
            var cont     = new FunctionContainer(2);

            registry.RegisterType(cont);
            Assert.IsTrue(registry.Contains("a", FunctionScope.Basic));
            Assert.IsTrue(registry.Contains("b", FunctionScope.Global));
            Assert.IsFalse(registry.Contains("c", FunctionScope.Global));

            var conf = new RollerConfig()
            {
                FunctionRegistry = registry, GetRandomBytes = GetRNG(Roll9())
            };

            EvaluateRoll("1d20.a()", conf, 1, "1d20.a() => 9 => 10");
            EvaluateRoll("1d20.b()", conf, 1, "1d20.b() => 9 => 11");
            EvaluateRoll("b()", conf, 0, "b() => 2 => 2");
        }
コード例 #16
0
ファイル: LoaderBase.cs プロジェクト: loopzer/core
        public void LoadFunctions(Assembly assembly)
        {
            foreach (var item in assembly.DefinedTypes.SelectMany(x => x.GetMethods()).Where(x => x.IsStatic))
            {
                var con = new FunctionContainer(item);

                this.log.Info("CSLoader loading function: " + item.Name);

                if (!this.functions.ContainsKey(item.Name))
                {
                    this.functions.Add(item.Name, con);
                }
                else
                {
                    this.functions[item.Name] = con;
                }
            }

            GC.Collect();
        }
コード例 #17
0
        public FunctionContainerTest()
        {
            //2 + 2*2

            root = FunctionContainer.CreateFunctionContainer_TwoArgs("Сложение");

            var arg1 = FunctionContainer.CreateFunctionContainer_ConstArg(2);

            var op1 = FunctionContainer.CreateFunctionContainer_TwoArgs("Умножение");

            var arg2 = FunctionContainer.CreateFunctionContainer_ConstArg(2);
            var arg3 = FunctionContainer.CreateFunctionContainer_ConstArg(2);

            root.AddChild(arg1);
            root.AddChild(op1);

            op1.AddChild(arg2);
            op1.AddChild(arg3);

            args = new double[] { 1, 2, 3 };
        }
コード例 #18
0
        public void GeneralCompileTest()
        {
            CompilationTester tester = new CompilationTester(FunctionContainer.CreateDefaultSetting());
            string            programPath;
            CompileResult     result;

            try
            {
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.CSCorrectSourceCode,
                                                                Language.CSharp3);
                result = Compiler.DotNet3Compiler.Compile(programPath);
                CompileServiceHelper.ValidateCorrectCompilationResult(result);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, false);
            }

            // bad input parameters
            try
            {
                result = Compiler.DotNet3Compiler.Compile(null);
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }

            try
            {
                result = Compiler.DotNet3Compiler.Compile("");
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }
        }
コード例 #19
0
        void InitContainers()
        {
            var controllers_factoryset =
                new FactorySet <ITrackController>(
                    SheetMusicEditor.CreateFactory()
                    );

            var controllers_viewerset =
                new ViewerSet <ITrackController>(
                    SheetMusicEditorView.Viewer.Instance
                    );

            var tracks_factoryset =
                new FactorySet <ITrack>(
                    MusicTrackFactory.Instance
                    );

            var tracks_viewerset =
                new ViewerSet <ITrack>();

            containerfactoryset.Factories.Add(
                TrackControllerContainer.CreateFactory(
                    tracks_factoryset,
                    tracks_viewerset,
                    controllers_factoryset,
                    controllers_viewerset
                    )
                );

            containerfactoryset.Factories.Add(
                PolylineContainer.CreateFactory(
                    new FactorySet <PolylineData>(
                        PolylineData.FactoryInstance
                        ),
                    new ViewerSet <PolylineData>(
                        )
                    )
                );

            containerfactoryset.Factories.Add(
                FunctionContainer.CreateFactory(
                    new FunctionCodeTools(
                        SquareFunction.FactoryClass.Instance,
                        PolylineFunction.FactoryClass.Instance,
                        PolynomialFunction.FactoryClass.Instance,
                        PulseWidthModulatedFunction.FactoryClass.Instance,

                        LocalPerspectiveFunction.FactoryClass.Instance,
                        GlobalPerspectiveFunction.FactoryClass.Instance
                        ),
                    new FactorySet <FunctionSource>(
                        FunctionSource.FactoryInstance
                        ),
                    new ViewerSet <FunctionSource>(
                        )
                    )
                );

            containerfactoryset.Factories.Add(
                ScreenContainer.CreateFactory(
                    new FactorySet <IScreen>(
                        TrackControllerScreen.FactoryInstance
                        ),
                    new ViewerSet <IScreen>(
                        TrackControllerScreenView.Viewer.Instance
                        )
                    )
                );
        }
コード例 #20
0
        private void treeListReferencedFiles_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
            TreeListNode parentNode = e.Node;

            while (parentNode.ParentNode != null && (parentNode.Tag == null || parentNode.Tag.GetType() != typeof(FunctionContainer)))
            {
                parentNode = parentNode.ParentNode;
            }
            if (parentNode.Tag != null && parentNode.Tag.GetType() == typeof(FunctionContainer))
            {
                var funcContainer = (FunctionContainer)parentNode.Tag;

                if (funcContainer == FunctionContainerDisplayedInEditors)
                {
                    // We are already displaying this function. Don't redisplay as we'll cause a flicker and loose the current line
                    return;
                }
                ClearApplyButtons();
                ClearDeleteButtons();
                FunctionContainerDisplayedInEditors = funcContainer;

                if (funcContainer.MyFunction != null && funcContainer.TheirFunction != null)
                {
                    if (funcContainer.MyFunction.Body == funcContainer.TheirFunction.Body)
                    {
                        syntaxEditorCurrent.Visible  = false;
                        syntaxEditorExternal.Visible = false;
                        ucHeading1.Text       = string.Format("{0}: no code differences", funcContainer.MyFunction.Name);
                        buttonResolve.Visible = false;
                    }
                    else
                    {
                        ucHeading1.Text = string.Format("{0}: code", funcContainer.MyFunction.Name);
                        string bodyExternal = funcContainer.TheirFunction.Body;
                        string bodyCurrent  = funcContainer.MyFunction.Body;

                        BusyPopulatingEditors = true;
                        syntaxEditorCurrent.SuspendPainting();
                        syntaxEditorExternal.SuspendPainting();
                        Slyce.IntelliMerge.UI.Utility.Perform2WayDiffInTwoEditors(syntaxEditorExternal, syntaxEditorCurrent, ref bodyExternal, ref bodyCurrent);
                        BusyPopulatingEditors = false;
                        buttonResolve.Visible = true;

                        if (syntaxEditorCurrent.Document.Lines.Count > 0)
                        {
                            syntaxEditorCurrent.SelectedView.FirstVisibleDisplayLineIndex = 0;
                        }
                        if (syntaxEditorExternal.Document.Lines.Count > 0)
                        {
                            syntaxEditorExternal.SelectedView.FirstVisibleDisplayLineIndex = 0;
                        }
                        syntaxEditorCurrent.ResumePainting();
                        syntaxEditorExternal.ResumePainting();
                        AddApplyButtons();
                        AddDeleteButtons();
                        SetLineNumbers();
                        syntaxEditorCurrent.Visible  = true;
                        syntaxEditorExternal.Visible = true;
                    }
                }
                else if (funcContainer.MyFunction == null && funcContainer.TheirFunction != null)
                {
                    syntaxEditorExternal.Text    = funcContainer.TheirFunction.Body;
                    syntaxEditorCurrent.Visible  = false;
                    syntaxEditorExternal.Visible = true;
                    ucHeading1.Text       = string.Format("{0}: no code differences", funcContainer.TheirFunction.Name);
                    buttonResolve.Visible = false;
                }
                else if (funcContainer.MyFunction != null && funcContainer.TheirFunction == null)
                {
                    syntaxEditorCurrent.Text     = funcContainer.MyFunction.Body;
                    syntaxEditorCurrent.Visible  = true;
                    syntaxEditorExternal.Visible = false;
                    ucHeading1.Text       = string.Format("{0}: no code differences", funcContainer.MyFunction.Name);
                    buttonResolve.Visible = false;
                }
                else
                {
                    syntaxEditorCurrent.Visible  = false;
                    syntaxEditorExternal.Visible = false;
                    ucHeading1.Text       = "No function selected";
                    buttonResolve.Visible = false;
                }
            }
        }
コード例 #21
0
ファイル: Program.cs プロジェクト: 9139876/PetProject
        static void Test3()
        {
            var root1 = FunctionContainer.CreateFunctionContainer_TwoArgs("Сложение");

            var sin = FunctionContainer.CreateFunctionContainer_OneArg("Синус");

            var cos = FunctionContainer.CreateFunctionContainer_OneArg("Косинус");

            var arg1 = FunctionContainer.CreateFunctionContainer_SameArgs(1);

            var arg2 = FunctionContainer.CreateFunctionContainer_SameArgs(2);

            root1.AddChild(sin);
            root1.AddChild(cos);

            sin.AddChild(arg1);
            cos.AddChild(arg2);

            var root2 = FunctionContainer.CreateFunctionContainer_TwoArgs("Умножение");

            var exp = FunctionContainer.CreateFunctionContainer_OneArg("Экспонента");

            var minus = FunctionContainer.CreateFunctionContainer_TwoArgs("Вычитание");

            var log = FunctionContainer.CreateFunctionContainer_OneArg("Натуральный_логарифм");

            var sqr = FunctionContainer.CreateFunctionContainer_OneArg("Корень_квадратный");

            var arg3 = FunctionContainer.CreateFunctionContainer_SameArgs(3);

            var arg4 = FunctionContainer.CreateFunctionContainer_SameArgs(4);

            var arg5 = FunctionContainer.CreateFunctionContainer_SameArgs(5);

            root2.AddChild(exp);
            root2.AddChild(minus);

            minus.AddChild(log);
            minus.AddChild(sqr);

            exp.AddChild(arg3);
            log.AddChild(arg4);
            sqr.AddChild(arg5);

            root1.Rating = 50;
            root2.Rating = 50;

            //Console.WriteLine(root1);

            //for (int i = 0; i < root1.SublevelsCount; i++)
            //{
            //    Console.WriteLine($"\n{i}");

            //    foreach (var ch in root1.GetChilds(i))
            //        Console.WriteLine(ch);
            //}


            //Console.WriteLine(root1);
            //Console.WriteLine(root2);

            //Console.WriteLine("\n***************\n");

            //for (int i = 0; i < 25; i++)
            //{
            //    Console.WriteLine($"\n******* {i+1} *******\n");

            //    var cross = EvolutionaryAlgorithm.Crossing.CrossRouletteTrees(new Common.ICrossedTree[] { root1, root2 });

            //    Console.WriteLine(cross);

            //}


            Console.WriteLine(root1);
            Console.WriteLine(root2);

            Console.WriteLine("\n***************\n");

            for (int i = 0; i < 25; i++)
            {
                Console.WriteLine($"\n******* {i + 1} *******\n");

                var cross = EvolutionaryAlgorithm.Crossing.CrossOverTrees(root1, root2);

                Console.WriteLine(cross);
            }
        }
コード例 #22
0
ファイル: CompilerTest.cs プロジェクト: nbl852003/iudico
        public void CompileTest()
        {
            CompilationTester tester = new CompilationTester(FunctionContainer.CreateDefaultSetting());
            string            programPath;
            CompileResult     result;

            #region CorrectLangugeSource

            try
            {
                //-----------CS-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.CSCorrectSourceCode,
                                                                Language.CSharp3);
                result = Compiler.DotNet3Compiler.Compile(programPath);
                CompileServiceHelper.ValidateCorrectCompilationResult(result);

                //-----------CPP-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.CPPCorrectSourceCode,
                                                                Language.VC8);
                result = Compiler.VC8Compiler.Compile(programPath);
                CompileServiceHelper.ValidateCorrectCompilationResult(result);

                //-----------Java-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.JavaCorrectSourceCode,
                                                                Language.Java6);
                result = Compiler.Java6Compiler.Compile(programPath);
                CompileServiceHelper.ValidateCorrectCompilationResult(result);

                //-----------Delphi-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.DelphiCorrectSourceCode,
                                                                Language.Delphi7);
                result = Compiler.Delphi7Compiler.Compile(programPath);
                CompileServiceHelper.ValidateCorrectCompilationResult(result);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, false);
            }

            #endregion

            #region IncorrectLangugeSource

            try
            {
                //-----------CS-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.CSIncorrectSourceCode,
                                                                Language.CSharp3);
                result = Compiler.DotNet3Compiler.Compile(programPath);
                CompileServiceHelper.ValidateIncorrectCompilationResult(result);

                //-----------CPP-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.CPPIncorrectSourceCode,
                                                                Language.VC8);
                result = Compiler.VC8Compiler.Compile(programPath);
                CompileServiceHelper.ValidateIncorrectCompilationResult(result);

                //-----------Java-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.JavaIncorrectSourceCode,
                                                                Language.Java6);
                result = Compiler.Java6Compiler.Compile(programPath);
                CompileServiceHelper.ValidateIncorrectCompilationResult(result);

                //-----------Delphi-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.DelphiIncorrectSourceCode,
                                                                Language.Delphi7);
                result = Compiler.Delphi7Compiler.Compile(programPath);
                CompileServiceHelper.ValidateIncorrectCompilationResult(result);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, false);
            }

            #endregion

            // bad input parameters
            try
            {
                result = Compiler.DotNet3Compiler.Compile(null);
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }

            try
            {
                result = Compiler.DotNet3Compiler.Compile("");
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }
        }