示例#1
0
 public void Should_Load_Examples()
 {
     Assert.Equal("{\"name\": \"test\"}", TestExample.ReadAllText(this.GetType(), "json"));
     Assert.Equal("<test>ExamplesLoaderTest<test>", TestExample.ReadAllText(this.GetType()));
     Assert.Equal("<test>Should_Load_Examples<test>", TestExample.LoadTestFixture(this.GetType()));
     Assert.Equal("<test>Should_Load_Examples<test>", TestExample.LoadTestFixture());
 }
示例#2
0
        public void TestPrintAvailableExamples()
        {
            ExampleRunner runner = new ExampleRunner();

            runner.LoadCodeExamples(this.GetType().Assembly,
                                    new System.Type[] { typeof(NoRunTestExample) });

            CaptureConsoleIOAndExecute(
                delegate()
            {
                runner.PrintAvailableExamples();
            },
                delegate(string output)
            {
                string[] outputs = output.Split(new char[] { '\r', '\n' },
                                                StringSplitOptions.RemoveEmptyEntries)
                                   .Select(c => c.Trim())
                                   .ToArray();

                TestExample testExample = new TestExample();

                string[] expectedOutputs = new string[] {
                    testExample.Name,
                    new string('=', testExample.Name.Length),
                    testExample.Description,
                    "Usage",
                    ExampleRunner.GetUsage(testExample).Trim(),
                };
                Assert.That(outputs, Is.EquivalentTo(expectedOutputs));
            }
                );
        }
示例#3
0
    public override Playable CreatePlayable(PlayableGraph graph, GameObject myGameObject)
    {
        //Get access to the Playable Behaviour script
        TestExample playableBehaviour = new TestExample();

        //Resolve the exposed reference on the Scene GameObject by returning the table used by the graph
        playableBehaviour.m_MySceneObject = m_MySceneObject.Resolve(graph.GetResolver());

        //Make the PlayableBehaviour velocity variable the same as the variable you set
        playableBehaviour.m_SceneObjectVelocity = m_SceneObjectVelocity;

        playableBehaviour.targetStr = targetStr;

        //Create a custom playable from this script using the Player Behaviour script
        return(ScriptPlayable <TestExample> .Create(graph, playableBehaviour));
    }
示例#4
0
        private static void Main(string[] args)
        {
            var list = new List <int> {
                1, 2, 3, 4, 5
            };

            Console.WriteLine($"來源序列為:{string.Join(", ", list)}");

            Console.WriteLine("請輸入要判斷的數字:");
            int value;

            int.TryParse(Console.ReadLine(), out value);

            Console.WriteLine($"來源序列是否包含指定的項目:");
            var testExample = new TestExample();

            Console.WriteLine(testExample.Contains(list, value));

            Console.ReadLine();
        }
示例#5
0
 public static void Test()
 {
     TestExample.A();
 }
示例#6
0
        public static void perform_kNN(string pathTraining, string pathTest)
        {
            Console.WriteLine("input parameter k: ");
            parameterK = UInt32.Parse(Console.ReadLine());
            System.Console.WriteLine("this is the parameter" + parameterK);

            var fileTraining = new FileInfo(pathTraining);
            var fileTest     = new FileInfo(pathTest);

            int[]    arrInts    = new int[parameterK];
            string[] arrStrings = new string[parameterK];

            using (var streamTraining = new StreamReader(fileTraining.OpenRead()))
            {
                string trainingLine = null;
                while ((trainingLine = streamTraining.ReadLine()) != null)
                {
                    //TODO: handling document spacing
                    string[]    trainingColumns = trainingLine.Split("   \t", StringSplitOptions.RemoveEmptyEntries);
                    TestExample example         = new TestExample();
                    for (int i = 0; i < trainingColumns.Length - 1; i++)
                    {
                        example.exampleList.Add(Double.Parse(trainingColumns[i]));
                    }
                    example.result = trainingColumns[trainingColumns.Length - 1];

                    _examples.Add(example);
                }
            }

            using (var streamTest = new StreamReader(fileTest.OpenRead()))
            {
                string testLine = null;
                while ((testLine = streamTest.ReadLine()) != null)
                {
                    string[]    testColumns = testLine.Split("   \t", StringSplitOptions.RemoveEmptyEntries);
                    TestExample test        = new TestExample();
                    for (int i = 0; i < testColumns.Length - 1; i++)
                    {
                        test.exampleList.Add(Double.Parse(testColumns[i]));
                    }
                    test.result = testColumns[testColumns.Length - 1];
                    _tests.Add(test);
                }
            }

            for (int i = 0; i < _tests.Count; i++)
            {
                for (int x = 0; x < _examples.Count; x++)
                {
                    _examples[x].difference =
                        CalculateEuclideanDistance(_examples[x].exampleList, _tests[i].exampleList);
                }

                _examples.Sort(new TestExampleComparer());
                for (int z = 0; z < parameterK; z++)
                {
                    arrStrings[z] = _examples[z].result;
                }

                string MostCommon = arrStrings.GroupBy(v => v)
                                    .OrderByDescending(g => g.Count())
                                    .First()
                                    .Key;
                Console.WriteLine(MostCommon);
                if (MostCommon.Equals(_tests[i].result.Trim()))
                {
                    Count++;
                    Console.WriteLine("correct");
                }
                else
                {
                    Console.WriteLine($"Incorrect! The correct result is: {_tests[i].result}");
                }
            }

            Console.WriteLine($"percentage correctness: {(Count / _tests.Count) * 100}%");

            while (true)
            {
                Console.WriteLine("type \"finish\" to finish or \"example\" to give another example");
                string userInput = Console.ReadLine();
                if ("finish".Equals(userInput))
                {
                    break;
                }
                else if ("example".Equals(userInput))
                {
                    Console.WriteLine("input new parameter k, integer");
                    var newParameterK = Int32.Parse(Console.ReadLine());

                    string[] newArrStrings = new string[newParameterK];
                    double[] coefficients  = new double[4];

                    for (int i = 0; i < coefficients.Length; i++)
                    {
                        Console.WriteLine($"input coefficient number: {i + 1} as a double example(2,5 or 0,3)");
                        coefficients[i] = Double.Parse(Console.ReadLine());
                    }

                    for (int x = 0; x < _examples.Count; x++)
                    {
                        _examples[x].difference =
                            CalculateEuclideanDistance(_examples[x].exampleList, coefficients);
                    }

                    _examples.Sort(new TestExampleComparer());
                    for (int z = 0; z < newParameterK; z++)
                    {
                        newArrStrings[z] = _examples[z].result;
                    }

                    string NewMostCommon = newArrStrings.GroupBy(v => v)
                                           .OrderByDescending(g => g.Count())
                                           .First()
                                           .Key;
                    Console.WriteLine(NewMostCommon);
                }
                else
                {
                    Console.WriteLine("wrong input, try again...");
                }
            }
        }