Exemplo n.º 1
0
    public void ItemsCanBeAddedToBag()
    {
        var bag        = new RandomBag <int>();
        var startCount = bag.Count;

        bag.Add(7);
        Assert.AreEqual(startCount + 1, bag.Count);

        bag.Add(4, 3);
        Assert.AreEqual(startCount + 4, bag.Count);
    }
Exemplo n.º 2
0
 private void RefillBag()
 {
     if (currentBucket.counts.Sum() > 0)
     {
         for (int index = 0, length = currentBucket.counts.Length; index < length; index++)
         {
             bag.Add(LAUNCHER_BUBBLE_TYPES[index], currentBucket.counts[index]);
         }
     }
     else
     {
         bag.Add(BubbleType.Blue);
     }
 }
Exemplo n.º 3
0
    /// <summary>
    /// 随机生成 n × n 网格中的所有连接。
    /// </summary>
    /// <param name="n">网格边长。</param>
    /// <returns>随机排序的连接。</returns>
    public static RandomBag <Connection> Generate(int n)
    {
        var result = new RandomBag <Connection>();
        var random = new Random();

        // 建立横向连接
        for (var i = 0; i < n; i++)
        {
            for (var j = 0; j < n - 1; j++)
            {
                if (random.Next(10) > 4)
                {
                    result.Add(new Connection(i * n + j, (i * n) + j + 1));
                }
                else
                {
                    result.Add(new Connection((i * n) + j + 1, i * n + j));
                }
            }
        }

        // 建立纵向连接
        for (var j = 0; j < n; j++)
        {
            for (var i = 0; i < n - 1; i++)
            {
                if (random.Next(10) > 4)
                {
                    result.Add(new Connection(i * n + j, ((i + 1) * n) + j));
                }
                else
                {
                    result.Add(new Connection(((i + 1) * n) + j, i * n + j));
                }
            }
        }

        return(result);
    }
Exemplo n.º 4
0
        public void ShouldAdd()
        {
            // Given
            var operations = 50;
            var bag        = new RandomBag <int>();

            // When
            for (var i = 0; i < operations; i++)
            {
                bag.Add(i);
            }

            // Then
            bag.Size.ShouldBe(operations);
        }
Exemplo n.º 5
0
        public void ShouldEnumerateThroughBag()
        {
            // Given
            var operationsCount = 50;
            var capacity        = 50;
            var bag             = new RandomBag <int>();
            var masterList      = Enumerable.Range(0, capacity).ToList();

            // When
            foreach (var item in masterList)
            {
                bag.Add(item);
            }

            // Then
            for (var i = 0; i < operationsCount; i++)
            {
                var actualList = bag.ToList();
                actualList.ShouldNotBe(masterList);
            }
        }