コード例 #1
0
    /**
     *  Set the data file of the player
     */
    public void SendData(string playerName)
    {
        ModifyData();
        PlayerData player = new PlayerData(playerName, data["platform5"], data["platform6"], data["platform7"], data["platform10"], data["spikes"], data["Catcher"], data["evilBlock"], data["evilSaw"], PlayerPrefs.GetInt("RandomMode"));

        DataFileManager.AddNewPlayer(player);
    }
コード例 #2
0
    /**
     *	Unit test of the FindData function
     */
    void TestFindData()
    {
        print("TestFindData...");
        Dictionary <string, float> data;
        PlayerData newPlayer;

        CreateFile();

        //Empty file
        data = DataFileManager.FindData("Test", path);
        Assert.AreEqual(null, data, string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Data should not exist"));

        //Add a player
        newPlayer = new PlayerData("Test", 1, 2, 4, 4, 0, 0, 1, 0, 0);
        DataFileManager.AddNewPlayer(newPlayer, path);
        data = DataFileManager.FindData("Test", path);
        Assert.AreEqual(0.25f, data["platform7"], string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 0.25!"));

        //Add an other player
        newPlayer = new PlayerData("Test", 2, 1, 12, 3, 0, 1, 0, 0, 0);
        DataFileManager.AddNewPlayer(newPlayer, path);
        newPlayer = new PlayerData("Test2", 1, 2, 3, 4, 0, 0, 0, 1, 0);
        DataFileManager.AddNewPlayer(newPlayer, path);
        data = DataFileManager.FindData("Test", path);
        Assert.AreEqual(0.0625f, data["platform7"], string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 0.0625!"));

        DeleteFile();
    }
コード例 #3
0
    /**
     *	Unit test of the ListOfPlayers function
     */
    void TestListOfPlayers()
    {
        print("TestListOfPlayers...");
        List <string> playerList;
        PlayerData    newPlayer;

        CreateFile();

        //Empty list
        playerList = DataFileManager.ListOfPlayers(path);
        Assert.AreEqual(0, playerList.Count, string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 0!"));

        //Add a player
        newPlayer = new PlayerData("Test", 1, 2, 3, 4, 0, 0, 1, 0, 0);
        DataFileManager.AddNewPlayer(newPlayer, path);
        playerList = DataFileManager.ListOfPlayers(path);
        Assert.AreEqual(1, playerList.Count, string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 1!"));

        //Add an other player
        newPlayer = new PlayerData("Test2", 1, 2, 3, 4, 0, 0, 1, 0, 0);
        DataFileManager.AddNewPlayer(newPlayer, path);
        playerList = DataFileManager.ListOfPlayers(path);
        Assert.AreEqual(2, playerList.Count, string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 2!"));

        //Add an other game for the first player
        newPlayer = new PlayerData("Test", 1, 2, 3, 4, 0, 0, 1, 0, 0);
        DataFileManager.AddNewPlayer(newPlayer, path);
        playerList = DataFileManager.ListOfPlayers(path);
        Assert.AreEqual(3, playerList.Count, string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 3!"));

        DeleteFile();
    }
コード例 #4
0
    /**
     *	Unit test of the ResetFile function
     */
    void TestResetFile()
    {
        print("TestResetFile...");
        string[]      data;
        List <string> trueData;

        CreateFile();

        //Empty file
        DataFileManager.ResetFile(path);
        data     = System.IO.File.ReadAllLines(path);
        trueData = FileWithoutBlank(data);
        Assert.AreEqual(1, trueData.Count, string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 1!"));

        //Add a player
        PlayerData newPlayer = new PlayerData("Test", 1, 2, 3, 4, 0, 0, 0, 1, 0);

        DataFileManager.AddNewPlayer(newPlayer, path);
        data     = System.IO.File.ReadAllLines(path);
        trueData = FileWithoutBlank(data);
        Assert.AreEqual(2, trueData.Count, string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 2!"));

        //Reset the file
        DataFileManager.ResetFile(path);
        data     = System.IO.File.ReadAllLines(path);
        trueData = FileWithoutBlank(data);
        Assert.AreEqual(1, trueData.Count, string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 1!"));

        //Check the first line of the file
        string firstline = "name;id;randomMode;platform5;platform6;platform7;platform10;spikes;catcher;evilBlock;evilSaw";

        Assert.AreEqual(firstline, data[0], string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Invalid firstline!"));

        DeleteFile();
    }
コード例 #5
0
    /**
     *	Unit test of the AddNewPlayer function
     */
    void TestAddNewPlayer()
    {
        print("TestAddNewPlayer...");
        int        id;
        PlayerData newPlayer;

        CreateFile();

        //Player not in the file
        id = DataFileManager.NextId("Test", path);
        Assert.AreEqual(1, id, string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 1!"));

        //Add a player
        newPlayer = new PlayerData("Test", 1, 2, 3, 4, 0, 0, 1, 0, 0);
        DataFileManager.AddNewPlayer(newPlayer, path);
        id = DataFileManager.NextId("Test", path);
        Assert.AreEqual(2, id, string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 2!"));
        id = DataFileManager.NextId("Test2", path);
        Assert.AreEqual(1, id, string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 1!"));

        //Add an other game for the player
        newPlayer = new PlayerData("Test", 1, 2, 3, 4, 0, 0, 0, 1, 0);
        DataFileManager.AddNewPlayer(newPlayer, path);
        id = DataFileManager.NextId("Test", path);
        Assert.AreEqual(3, id, string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 3!"));

        //Add an other player
        newPlayer = new PlayerData("Test2", 1, 2, 3, 4, 0, 0, 0, 1, 0);
        DataFileManager.AddNewPlayer(newPlayer, path);
        id = DataFileManager.NextId("Test", path);
        Assert.AreEqual(3, id, string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 3!"));
        id = DataFileManager.NextId("Test2", path);
        Assert.AreEqual(2, id, string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 2!"));

        DeleteFile();
    }