Esempio n. 1
0
        public static void RunAnyTests(IEnumerable<string> testNames, LoadingData data)
        {
            var competitions = Dispatcher.Loader.GetCompetitions(data);

            Action testAction = () => ExecuteTests(testNames, data);
            testAction.BeginInvoke(null, null);
        }
Esempio n. 2
0
        public static void RunAllTests(LoadingData data)
        {
            var competitions = Dispatcher.Loader.GetCompetitions(data);
            var testsNames = competitions.Logic.Tests.Keys;

            Action testAction = () => ExecuteTests(testsNames, data);
            testAction.BeginInvoke(null, null);
        }
Esempio n. 3
0
        public static void RunOneTest(LoadingData data, string testName)
        {
            Debugger.Log(DebuggerMessageType.UnityTest, "Starting test " + testName);
            var test = Dispatcher.Loader.GetTest(data, testName);
            var asserter = new UnityAsserter(testName);

            Action testAction = () => ExecuteTest(testName, test, asserter, MakeServerInfo(data));
            testAction.BeginInvoke(null, null);
        }
Esempio n. 4
0
 static NetworkData MakeServerInfo(LoadingData data)
 {
     var networkInfo = new NetworkData
     {
         Port = UnityConstants.SoloNetworkPort,
         LoadingData = data,
         WaitWorld = WaitWorld
     };
     return networkInfo;
 }
    public void OnGUI()
    {
        background = new Texture2D(2, 2);
        Color preColor = GUI.color;
        if (Event.current.type == EventType.repaint)
        {
            GUI.color = new Color(preColor.r, preColor.g, preColor.b, 10);
            GUI.DrawTexture(new Rect(0.0f, 0.0f, Screen.width, Screen.height), background);
        }
        GUI.color = new Color(preColor.r, preColor.g, preColor.b, 10);
        Rect menuRect = new Rect(
            (Screen.width - kMenuWidth) * 0.5f,
            (Screen.height - kMenuHeight) * 0.5f,
            kMenuWidth,
            kMenuHeight
        );

        GUI.DrawTexture(menuRect, menuBackground);

        var tests = Dispatcher.loader.Levels[ASSEMBLY_NAME]["Test"]().Logic.Tests.Keys.OrderBy(x => x).ToArray();
        LoadingData data = new LoadingData();
        data.AssemblyName = ASSEMBLY_NAME;
        data.Level = "Test";

        GUILayout.BeginArea(menuRect);
        GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            MenuButton(button, "Tests", Color.black, () => { isPressedTests = !isPressedTests; });
            MenuButton(button, "Hardcoded: " + HardcodedTest, GetTestColor(HardcodedTest), () => Dispatcher.RunOneTest(data, HardcodedTest));

            GUI.color = preColor;
            GUILayout.EndVertical();

            GUILayout.BeginVertical(new GUILayoutOption[]{GUILayout.MinWidth(kMenuWidth / 2)});
            if (isPressedTests)
            {
                GUILayout.FlexibleSpace();
                MenuButton(button, "Run all tests", Color.black, () => Dispatcher.RunAllTests(data));
                GUILayout.FlexibleSpace();

                scrollViewVector = GUILayout.BeginScrollView(scrollViewVector, false, true);
                foreach (string test in tests)
                {

                    MenuButton(button, test, GetTestColor(test), () => Dispatcher.RunOneTest(data, test));
                }
                GUILayout.EndScrollView();
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();
        GUILayout.EndHorizontal();
        GUILayout.EndArea();
    }
Esempio n. 6
0
 static void ExecuteTests(IEnumerable<string> testNames, LoadingData data)
 {
     Debugger.Log(DebuggerMessageType.UnityTest, "staring tests");
     foreach (var testName in testNames)
     {
         if (Dispatcher.UnityShutdown)
         {
             Debugger.Log(DebuggerMessageType.UnityTest, "unity shutdown! stop testing");
             break;
         }
         var asserter = new UnityAsserter(testName);
         Debugger.Log(DebuggerMessageType.UnityTest, "Test is ready");
         var test = Dispatcher.Loader.GetTest(data, testName);
         ExecuteTest(testName, test, asserter, MakeServerInfo(data));
     }
 }
Esempio n. 7
0
        static void Main(string[] args)
        {
            int port = 14000;

            while (true)
            {
                try
                {
                    Console.Write("Attempting to connect ");
                    var client = new CvarcClient<object, MoveAndGripCommand>();

                    var loadingData = new LoadingData { AssemblyName = "Demo", Level = "Movement" };

                    var settings = new SettingsProposal
                    {
                        TimeLimit=3,
                        Controllers = new List<ControllerSettings> 
                        {
                            new ControllerSettings
                            {
                                 ControllerId=TwoPlayersId.Left, Name="This", Type= ControllerType.Client
                            }
                        }
                    };
                    
                    var state=KnownWorldStates.EmptyWithOneRobot(false);
                    var rules=new MoveAndGripRules();
                
                    client.Configurate(port, new ConfigurationProposal { LoadingData=loadingData, SettingsProposal=settings}, state);

                    client.Act(rules.Move(30));
                    client.Act(rules.Rotate(Angle.Pi));
                    client.Exit();
                    Console.WriteLine("Success");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                Thread.Sleep(1000);
            }
        }
Esempio n. 8
0
        readonly IWorldState worldState; // откуда?

        #endregion Fields

        #region Constructors

        public TutorialRunner(LoadingData loadingData, Configuration configuration = null, IWorldState worldState = null)
        {
            factory = new TutorialControllerFactory();

            var competitions = Dispatcher.Loader.GetCompetitions(loadingData);
            if (configuration == null)
            {
                this.configuration = new Configuration
                {
                    LoadingData = loadingData,
                    Settings = competitions.Logic.CreateDefaultSettings()
                };
            }
            else
                this.configuration = configuration;

            this.worldState = worldState ?? competitions.Logic.CreateWorldState(competitions.Logic.PredefinedWorldStates[0]);
            //this.worldState = worldState ?? competitions.Logic.CreateWorldState("0"); // lol

            Name = "Tutorial";
            CanStart = true;
            CanInterrupt = true;
        }
Esempio n. 9
0
 /// <summary>
 /// Gets the test with the specific name
 /// </summary>
 /// <param name="data"></param>
 /// <param name="testName"></param>
 /// <returns></returns>
 public ICvarcTest GetTest(LoadingData data, string testName)
 {
     var assemblyName = data.AssemblyName;
     var level = data.Level;
     Competitions competitions;
     try
     {
         competitions = GetCompetitions(assemblyName, level);
     }
     catch
     {
         throw new Exception(string.Format("The competition '{0}'.'{1}' were not found", assemblyName, level));
     }
     ICvarcTest test;
     try
     {
         test = competitions.Logic.Tests[testName];
     }
     catch
     {
         throw new Exception(string.Format("The test with name '{0}' was not found in competitions {1}.{2}", testName, assemblyName, level));
     }
     return test;
 }
Esempio n. 10
0
        public TournamentRunner(LoadingData loadingData, IWorldState worldState)
        {
            this.worldState = worldState;
            players = new List<TournamentPlayer>();

            var competitions = Dispatcher.Loader.GetCompetitions(loadingData);
            var settings = competitions.Logic.CreateDefaultSettings();
            configuration = new Configuration
            {
                LoadingData = loadingData,
                Settings = settings
            };

            //я игнорирую конфиги. надо хотя бы имя сохранять в метод "add player"

            controllerIds = competitions.Logic.Actors.Keys.ToArray();

            foreach (var controller in controllerIds
                .Select(x => new ControllerSettings
                {
                    ControllerId = x,
                    Type = ControllerType.Client,
                    Name = settings.Name
                }))
                settings.Controllers.Add(controller);

            requiredCountOfPlayers = controllerIds.Length;

            Debugger.Log(DebuggerMessageType.Unity, "t.runner created. count: " + requiredCountOfPlayers);
            if (requiredCountOfPlayers == 0)
                throw new Exception("requiered count of players cant be 0");

            Name = loadingData.AssemblyName + loadingData.Level;//"Tournament";
            CanInterrupt = false;
            CanStart = false;
        }
Esempio n. 11
0
        public void Show(Texture button, LoadingData data, float shift)
        {
            GUILayout.Space(2);
            GUILayout.BeginHorizontal();
                GUILayout.Label("", GUILayout.Width(shift));
            MenuButton(button,
                       " ‣ " + Name,
                       Color.white,
                       () => IsOpen = !IsOpen);
            GUILayout.EndHorizontal();

            if (IsOpen)
            {

                foreach (var test in Files)
                {
                    if (test is Folder)
                        ((Folder)test).Show(button, data, shift + 10);
                    else
                    {
                        GUILayout.BeginHorizontal();
                            GUILayout.Label("", GUILayout.Width(shift + 10));
                            MenuButton(button, ((string)test).Split('_').Last(), GetTestColor((string)test), () => {
                                TestDispatcher.RunOneTest(data, (string)test);
                                PlayerPrefs.SetInt((string)test, (GetTestColor((string)test) == Color.green) ? 1 : 0);
                            });
                        GUILayout.EndHorizontal();
                    }
                }
            }
        }
Esempio n. 12
0
    void TestsWindow(int windowID)
    {
        background = new Texture2D(2, 2);
        Color preColor = GUI.color;
        if (Event.current.type == EventType.repaint)
        {
            GUI.color = new Color(preColor.r, preColor.g, preColor.b, 10);
            //GUI.DrawTexture(new Rect(0.0f, 0.0f, Screen.width, Screen.height), background);
        }
        GUI.color = new Color(preColor.r, preColor.g, preColor.b, 10);
        Rect menuRect = new Rect(
            10,
            25,
            kMenuWidth - 20,
            kMenuHeight - 35
        );

        GUI.DrawTexture(menuRect, menuBackground);

        var tests = Dispatcher.Loader.Levels[ASSEMBLY_NAME][Level]().Logic.Tests.Keys.OrderBy(x => x).ToArray();
        LoadingData data = new LoadingData();
        data.AssemblyName = ASSEMBLY_NAME;
        data.Level = Level;

        if (!folderIsLoad)
        {
            folder = new Folder(ASSEMBLY_NAME);

            foreach (var test in tests)
            {
                var names = test.Split('_');
                Folder last = folder;
                for (int i = 0; i < names.Length - 1; i++)
                {
                    var f = last.Contains(names[i]);
                    if (f == null)
                    {
                        var newFolder = new Folder(names[i]);
                        last.Files.Add(newFolder);
                        last = newFolder;
                    }
                    else
                        last = (Folder)f;
                }
                if (PlayerPrefs.HasKey(test))
                {
                    TestDispatcher.LastTestExecution[test] = PlayerPrefs.GetInt(test) != 1;
                }
                last.Files.Add(test);
            }
            folderIsLoad = true;
        }

        GUILayout.BeginArea(menuRect);
        GUILayout.BeginHorizontal();
        GUILayout.BeginVertical();
        MenuButton(button, "Tests", Color.white, () => { isPressedTests = !isPressedTests; });
        GUILayout.Space(10);
        //MenuButton(button, "Hardcoded: " + HardcodedTest, GetTestColor(HardcodedTest), () => TestDispatcher.RunOneTest(data, HardcodedTest));
        //GUILayout.Space(10);
        MenuButton(button, "TUTORIAL", Color.white, () => Dispatcher.AddRunner(new TutorialRunner(data)));
        GUILayout.Space(10);
        logFile = TextField(logFile);
        GUILayout.Space(10);
        MenuButton(button, "Log play", Color.white, () => Dispatcher.AddRunner(new LogRunner(logFile)));

        GUI.color = preColor;
        GUILayout.EndVertical();

        GUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.MinWidth(kMenuWidth / 2) });
        if (isPressedTests)
        {
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            MenuButton(button, "Run all tests", Color.white, () => TestDispatcher.RunAllTests(data));
            GUILayout.Space(20);
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.Space(10);
            scrollViewVector = GUILayout.BeginScrollView(scrollViewVector, false, true);

            folder.Show(button, data, 0);
            GUILayout.EndScrollView();
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndVertical();
        GUILayout.EndHorizontal();
        GUILayout.EndArea();
    }
 public ConfigurationProposal()
 {
     LoadingData = new LoadingData();
     SettingsProposal = new SettingsProposal();
 }
Esempio n. 14
0
 public static void RunOneTest(LoadingData data, string testName)
 {
     Debugger.Log( DebuggerMessageType.Unity, "Starting test "+testName);
     var competitionsInstance = loader.GetCompetitions(data);
     var test = loader.GetTest(data, testName);
     var asserter = new UnityAsserter(testName);
     Dispatcher.WaitingNetworkServer.LoadingData = data;
     Action action = () =>
     {
         ExecuteTest(testName, test, asserter);
     };
     Dispatcher.RunThread(action, "test thread");
 }
Esempio n. 15
0
    public static void RunAllTests(LoadingData data)
    {
        var competitions = loader.GetCompetitions(data);
        var testsNames = competitions.Logic.Tests.Keys.ToArray();

        Action runOneTest = () =>
            {
                Debugger.Log(DebuggerMessageType.Unity, "staring tests");
                foreach(var testName in testsNames)
                {
                    var asserter = new UnityAsserter(testName);
                    Debugger.Log(DebuggerMessageType.Unity,"Test is ready");
                    Dispatcher.WaitingNetworkServer.LoadingData = data;
                    var test = loader.GetTest(data, testName);
                    ExecuteTest(testName, test, asserter);
                }
            };

        RunThread(runOneTest, "test runner");
        //ты умеешь запускать тесты, см. IntroductionScript
        //и ты знаешь, когда очередной тест закончился, тогда вызывается метод Exited
        //должен появится флаг тестового режима, и в этом режиме Exited должен запускать следующий тест. Если кончились, возвращение на Intro.
    }
Esempio n. 16
0
    MyWindow MakeTests()
    {
        var window = new MyWindow(ButtonSprite, "Tests", new Rect(0, 0, kMenuWidth, kMenuHeight));
        var scroll = new MyScrollBar(ButtonSprite);

        var scrollView = new MyList(ButtonSprite, new Rect(78, 0, 200, 241));
        scrollView.SetAnchor(new Vector2(0.5f, 0), new Vector2(1, 1));
        scrollView.Element.GetComponent<RectTransform>().offsetMin = new Vector2(0, 0);
        scrollView.Element.GetComponent<RectTransform>().offsetMax = new Vector2(-20, 0);

        folder = stateMenu.StateFolder[stateMenu.CurrentAssembly][stateMenu.CurrentLevel];
        var data = new LoadingData
        {
            AssemblyName = stateMenu.CurrentAssembly,
            Level = stateMenu.CurrentLevel
        };

        foreach (var e in folder.GetChildrenTests())
        {
            if (e.State != 0 && TestDispatcher.LastTestExecution.ContainsKey(e.NameTest))
                TestDispatcher.LastTestExecution[e.NameTest] = e.State == 1;
            else if (e.State != 0 && !TestDispatcher.LastTestExecution.ContainsKey(e.NameTest))
                TestDispatcher.LastTestExecution.Add(e.NameTest, e.State == 1);
        }

        var buttonTest = TestButton(folder, ButtonSprite, data, backgroundStateTest);

        folderIsLoad = true;
        var scrollR = scrollView.Element.GetComponent<ScrollRect>();
        scrollR.scrollSensitivity = 10;
        scrollR.verticalScrollbar = scroll.Element.GetComponent<Scrollbar>();
        scrollView.Element.name = "ScrollView";
        window.AddElement(scrollView);
        buttonTest.Element.name = "HeadButton";
        scrollView.MainElement.AddElement(buttonTest);
        scrollView.MainElement.Element.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;

        window.AddElement(scroll);

        return window;
    }
Esempio n. 17
0
    public static MyPanel TestButton(object test, Sprite sprite, LoadingData data, Sprite backgroundTest)
    {
        var headPanel = new MyPanel(sprite, new Rect(0, 0, 0, 0));
        Destroy(headPanel.Element.GetComponent<Image>());
        headPanel.SetAnchor(new Vector2(0, 0), new Vector2(1, 1));
        headPanel.Element.AddComponent<VerticalLayoutGroup>();
        var headPanelContentSizeFilter = headPanel.Element.AddComponent<ContentSizeFitter>();
        headPanelContentSizeFilter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
        if ((test as Folder) != null)
        {
            var mainPanel = new MyPanel(sprite, new Rect(0, 0, 0, 0));
            Destroy(mainPanel.Element.GetComponent<Image>());
            mainPanel.Element.SetActive(((Folder)test).IsOpen);
            mainPanel.SetAnchor(new Vector2(0, 0), new Vector2(1, 1));
            mainPanel.Element.AddComponent<LayoutElement>();
            mainPanel.Element.AddComponent<VerticalLayoutGroup>().padding.left = 20;

            var buttonArea = new MyPanel(sprite, new Rect(0, 0, 0, 0));
            UIElement.SetSize(buttonArea.Element.GetComponent<RectTransform>(), new Vector2(60, 32));
            buttonArea.SetAnchor(new Vector2(0, 0), new Vector2(1, 1));
            buttonArea.Element.AddComponent<HorizontalLayoutGroup>();

            var button = new MyButton(
                () =>
                {
                    mainPanel.Element.SetActive(!mainPanel.Element.activeSelf);
                    ((Folder)test).IsOpen = !((Folder)test).IsOpen;
                    Debug.Log(((Folder)test).Name + " : " + mainPanel.Element.activeSelf);
                }
                , sprite, new Rect(0, 0, 0, 0), "  <color=#00000060>►</color> " + ((Folder)test).Name);
            button.Element.AddComponent<LayoutElement>();

            var buttonRunTestIn = new MyButton(
                () =>
                {
                    TestDispatcher.RunAnyTests(((Folder)test).GetChildrenTests().Select(e => e.NameTest), data);
                    foreach(var e in ((Folder)test).GetChildrenTests().Select(e => e.NameTest))
                        ((Test) test).State = TestDispatcher.LastTestExecution[e] ? 1 : -1;
                }
                , sprite, new Rect(0, 0, 0, 0), "  <color=#00ff0060>►</color> ");
            buttonRunTestIn.Element.AddComponent<LayoutElement>();

            buttonArea.AddElement(button);
            buttonArea.AddElement(buttonRunTestIn);

            button.Element.GetComponentInChildren<Text>().alignment = TextAnchor.MiddleLeft;
            UIElement.SetSize(button.Element.GetComponent<RectTransform>(), new Vector2(60, 32));
            button.SetAnchor(new Vector2(0, 0), new Vector2(1, 1));
            var layoutElement = button.Element.AddComponent<LayoutElement>();

            layoutElement.minHeight = 30;
            headPanel.AddElement(buttonArea);
            foreach (var e in ((Folder)test).GetChildren())
                mainPanel.AddElement(TestButton(e, sprite, data, backgroundTest));
            headPanel.AddElement(mainPanel);
        }
        else
        {
            var testName = ((Test)test).NameTest;
            var button = new MyButton(
                () => {
                    TestDispatcher.RunOneTest(data, testName);
                    if (TestDispatcher.LastTestExecution.ContainsKey(testName))
                        if (TestDispatcher.LastTestExecution[testName])
                            ((Test)test).State = 1;
                        else
                            ((Test)test).State = -1;
                    else
                        ((Test)test).State = 0;
                    ((Test)test).State = TestDispatcher.LastTestExecution[testName] ? 1 : -1;
                }, sprite, new Rect(0, 0, 0, 0), testName.Split('_').Last());
            button.SetAnchor(new Vector2(0, 0), new Vector2(1, 1));
            button.Element.AddComponent<LayoutElement>();
            var testStateImage = new MyPanel(backgroundTest, new Rect(0, 0, 0, 0));
            testStateImage.SetAnchor(new Vector2(0, 0), new Vector2(1, 1));
            button.AddElement(testStateImage);
            testStateImage.Element.transform.SetAsFirstSibling();
            //testStateImage.Element.GetComponent<Image>().color = new Color32(0, 0, 0, 100);
            testStateImage.Element.GetComponent<Image>().color = GetTestColor(testName);
            button.Element.GetComponent<Button>().onClick.AddListener(() => testStateImage.Element.GetComponent<Image>().color = GetTestColor(testName));
            headPanel.AddElement(button);
            UIElement.SetSize(button.Element.GetComponent<RectTransform>(), new Vector2(60, 32));
            button.SetAnchor(new Vector2(0, 0), new Vector2(1, 1));
            var layoutElement = button.Element.AddComponent<LayoutElement>();
            layoutElement.minHeight = 30;
        }
        return headPanel;
    }
Esempio n. 18
0
		/// <summary>
		/// Creates the world for non-networking case: BotDemo or Tutorial modes. Automatically obtains all the parameters from CommandLineData
		/// </summary>
		/// <param name="cmdLineData"></param>
		/// <returns></returns>
		public IWorld CreateSimpleMode(CommandLineData cmdLineData)
		{
			var proposal = SettingsProposal.FromCommandLineData(cmdLineData);
			ControllerFactory factory = CreateControllerFactory(cmdLineData.Unnamed[2], proposal);
			var loadingData = new LoadingData { AssemblyName = cmdLineData.Unnamed[0], Level = cmdLineData.Unnamed[1] };
			return CreateSimpleMode(loadingData, proposal, factory);
		}
Esempio n. 19
0
		/// <summary>
		/// Creates the world for non-networking case: BotDemo or Tutorial modes.
		/// </summary>
		/// <param name="loadingData"></param>
		/// <param name="proposal"></param>
		/// <param name="factory"></param>
		/// <returns></returns>
		public IWorld CreateSimpleMode(LoadingData loadingData, SettingsProposal proposal, ControllerFactory factory)
		{
			var configuration = new Configuration();
			configuration.LoadingData = loadingData;
			var competitions = GetCompetitions(configuration.LoadingData);
			configuration.Settings = competitions.Logic.CreateDefaultSettings();


			proposal.Push(configuration.Settings, true);
			var stateName = configuration.Settings.WorldState;
			if (stateName == null)
			{
				if (competitions.Logic.PredefinedWorldStates.Count == 0)
					throw new Exception("The count of predefined stated in the " + competitions.Logic.GetType() + " is zero");
				stateName = competitions.Logic.PredefinedWorldStates[0];
			}
			var state = competitions.Logic.CreateWorldState(stateName);
			return CreateWorld(configuration, factory, state);

		}
Esempio n. 20
0
		public Competitions GetCompetitions(LoadingData data)
		{
			return GetCompetitions(data.AssemblyName, data.Level);
		}