示例#1
0
 public void WhenInsertingPastCapacity_ListExpands()
 {
     using (var growableBuffer = new GrowableBuffer <int>(Allocator.TempJob))
     {
         var capacity = growableBuffer.Capacity;
         while (capacity == growableBuffer.Capacity)
         {
             growableBuffer.Add(0);
         }
     }
 }
示例#2
0
        void QueueCommand <T>(T command)
            where T : unmanaged, IDSPCommand
        {
            if (!m_Commands.Valid)
            {
                throw new InvalidOperationException("Command buffer has not been initialized");
            }
            var queueCommand = m_Graph.AllocateCommand <T>();

            *queueCommand = command;
            m_Commands.Add((IntPtr)queueCommand);
        }
示例#3
0
 public void AddRange()
 {
     using (var growableBuffer = new GrowableBuffer <int>(Allocator.TempJob))
     {
         for (int i = 0; i < 9; ++i)
         {
             growableBuffer.Add(i);
         }
         using (var copiedList = new GrowableBuffer <int>(Allocator.Temp))
         {
             copiedList.AddRange(growableBuffer);
             CollectionAssert.AreEqual(growableBuffer.ToArray(), copiedList.ToArray());
         }
     }
 }
示例#4
0
 public void CopyFromArray()
 {
     using (var growableBuffer = new GrowableBuffer <int>(Allocator.TempJob))
     {
         for (int i = 0; i < 9; ++i)
         {
             growableBuffer.Add(i);
         }
         using (var copiedList = new GrowableBuffer <int>(Allocator.Temp, growableBuffer.ToArray()))
         {
             CollectionAssert.AreEqual(growableBuffer.ToArray(), copiedList.ToArray());
             Assert.AreEqual(growableBuffer.Count, copiedList.Capacity);
         }
     }
 }
示例#5
0
 public void CopyFromGrowableBuffer()
 {
     using (var growableBuffer = new GrowableBuffer <int>(Allocator.TempJob))
     {
         for (int i = 0; i < 9; ++i)
         {
             growableBuffer.Add(i);
         }
         using (var copiedList = new GrowableBuffer <int>(Allocator.Temp, growableBuffer))
         {
             // CollectionAssert is broken with GrowableBuffer<T> even though it only wants IEnumerable<T>...
             CollectionAssert.AreEqual(growableBuffer.ToArray(), copiedList.ToArray());
             Assert.AreEqual(growableBuffer.Count, copiedList.Capacity);
         }
     }
 }
示例#6
0
    public void Remove(int removalIndex)
    {
        using (var growableBuffer = new GrowableBuffer <int>(Allocator.TempJob))
        {
            var list = new List <int>();
            for (int i = 0; i < 9; ++i)
            {
                growableBuffer.Add(i);
                list.Add(i);
            }

            growableBuffer.RemoveAt(removalIndex);
            list.RemoveAt(removalIndex);
            CollectionAssert.AreEqual(list.ToArray(), growableBuffer.ToArray());
        }
    }
示例#7
0
    public void Insert(int insertionIndex)
    {
        using (var growableBuffer = new GrowableBuffer <int>(Allocator.TempJob))
        {
            var list = new List <int>();
            for (int i = 0; i < 9; ++i)
            {
                growableBuffer.Add(i);
                list.Add(i);
            }

            growableBuffer.Insert(insertionIndex, -1);
            list.Insert(insertionIndex, -1);
            CollectionAssert.AreEqual(list.ToArray(), growableBuffer.ToArray());
        }
    }
示例#8
0
    public void WhenInsertingPastCapacity_DescriptionIsStillValid()
    {
        using (var growableBuffer = new GrowableBuffer <int>(Allocator.TempJob))
        {
            var description = growableBuffer.Description;
            var capacity    = growableBuffer.Capacity;
            while (capacity == growableBuffer.Capacity)
            {
                growableBuffer.Add(0);
            }
            var rehydratedList = GrowableBuffer <int> .FromDescription(description);

            Assert.AreEqual(growableBuffer, rehydratedList);
            Assert.AreEqual(growableBuffer.Count, rehydratedList.Count);
            Assert.AreEqual(growableBuffer.Capacity, rehydratedList.Capacity);
            CollectionAssert.AreEqual(growableBuffer.ToArray(), rehydratedList.ToArray());
        }
    }