Exemplo n.º 1
0
    public void TestRnd()
    {
        System.Collections.Generic.List <int> intList = new System.Collections.Generic.List <int>()
        {
            1, 2, 3, 4, 5, 6, 7, 8, 9
        };

        int[] intArray = new int[9];
        int   loops    = 100;

        for (int i = 0; i < loops; i++)
        {
            int val = intList.Rnd();
            intArray[val - 1]++;
            Assert.AreEqual(true, intList.Contains(val));
        }

        // Weak ass std deviation test
        float sum1 = 0;

        foreach (int i in intArray)
        {
            sum1 += i;
        }
        float mean = sum1 / intArray.Length;

        Assert.AreEqual(((float)loops) / intList.Count, mean);
        float sum2 = 0;

        foreach (int i in intArray)
        {
            sum2 += Mathf.Pow(i - mean, 2);
        }
        float stdev = Mathf.Sqrt(sum2 / intList.Count);

        Assert.Less(stdev, mean);
        Assert.Greater(stdev, 0);
    }