Beispiel #1
0
    public void TestSwapDiceForRandomOne()
    {
        Player.restoreValuesToDefault();
        Player.diceMultiplier = 1;
        // Initialize values
        int maxRoll   = 1000;
        int nDiceObjs = diceLimit;

        DiceCluster.diceObjArray   = new Dice[nDiceObjs];
        DiceCluster.diceGroupArray = new DiceGroup[maxRoll + 1];
        for (int i = 0; i < DiceCluster.diceGroupArray.Length; i++)
        {
            DiceCluster.diceGroupArray[i] = new DiceGroup();
        }

        // Fill with random numbers
        GameObject dummyDiceObject;
        int        rollResult = 100;

        for (int i = 0; i < 500; i++)
        {
            DiceCluster.diceGroupArray[rollResult].nRolls++;

            if (i < diceLimit)
            {
                dummyDiceObject = new GameObject();
                dummyDiceObject.AddComponent <Dice>();
                DiceCluster.addDiceToArrays(rollResult, i, dummyDiceObject);
                DiceCluster.diceObjArray[i].value = rollResult;
            }
        }

        dummyDiceObject = new GameObject();
        dummyDiceObject.AddComponent <Dice>();
        int randomIndex = Random.Range(0, diceLimit);

        DiceCluster.swapDiceForRandomOne(randomIndex, Player.attackRolls[0], dummyDiceObject);

        Assert.AreEqual(1, DiceCluster.diceGroupArray[Player.attackRolls[0]].diceIDs.Count);
        Assert.AreEqual(diceLimit - 1, DiceCluster.diceGroupArray[rollResult].diceIDs.Count);
    }
Beispiel #2
0
    public void TestAddDiceToArrays()
    {
        int maxRoll = 1000;

        // Initialize values
        int[] rolls     = new int[] { 2, 7, 15, 7, 20, 1000, 7, 2, 2 };
        int   nDiceObjs = Mathf.Min(rolls.Length, diceLimit);

        DiceCluster.diceObjArray   = new Dice[nDiceObjs];
        DiceCluster.diceGroupArray = new DiceGroup[maxRoll + 1];
        for (int i = 0; i < DiceCluster.diceGroupArray.Length; i++)
        {
            DiceCluster.diceGroupArray[i] = new DiceGroup();
        }

        DiceGroup[] expectedGroupArray = new DiceGroup[maxRoll + 1];
        for (int i = 0; i < expectedGroupArray.Length; i++)
        {
            expectedGroupArray[i] = new DiceGroup();
        }
        expectedGroupArray[2] = new DiceGroup(3, new List <int>()
        {
            0, 7, 8
        });
        expectedGroupArray[7] = new DiceGroup(3, new List <int>()
        {
            1, 3, 6
        });
        expectedGroupArray[15] = new DiceGroup(1, new List <int>()
        {
            2
        });
        expectedGroupArray[20] = new DiceGroup(1, new List <int>()
        {
            4
        });
        expectedGroupArray[1000] = new DiceGroup(1, new List <int>()
        {
            5
        });

        // Fill arrays
        for (int i = 0; i < rolls.Length; i++)
        {
            GameObject dummyDiceObject = new GameObject();
            dummyDiceObject.AddComponent <Dice>();
            DiceCluster.addDiceToArrays(rolls[i], i, dummyDiceObject);
            DiceCluster.diceGroupArray[rolls[i]].nRolls++;
            DiceCluster.diceObjArray[i].value = rolls[i];
        }

        // Assert same diceObjArrays
        for (int i = 0; i < rolls.Length; i++)
        {
            Assert.AreEqual(rolls[i], DiceCluster.diceObjArray[i].value);
        }

        // Assert same diceGroupArrays
        for (int i = 0; i < expectedGroupArray.Length; i++)
        {
            Assert.AreEqual(expectedGroupArray[i].nRolls, DiceCluster.diceGroupArray[i].nRolls);
            Assert.AreEqual(expectedGroupArray[i].diceIDs, DiceCluster.diceGroupArray[i].diceIDs);
        }
    }