Exemplo n.º 1
0
 public void FreesMultipleBitsFromLong()
 {
     foreach (var test in new Test[] {
         new Test(0x0000000000000000UL, 64, 0xFFFFFFFFFFFFFFFFUL, 0, true),
         new Test(0x0000000000000000UL, 2, 0x0000000000000003UL, 0, true),
         new Test(0x0000000000000001UL, 63, 0xFFFFFFFFFFFFFFFFUL, 1, true),
         new Test(0x00000000000000FFUL, 8, 0x000000000000FFFFUL, 8, true),
         new Test(0x00000000000FF0FFUL, 8, 0x000000000FFFF0FFUL, 20, true),
     })
     {
         long expectedModified = test.value;
         long modified         = test.expectedModified;
         var  worked           = ConcurrentMask.TryFree(ref modified, test.offset, test.bits);
         Assert.AreEqual(expectedModified, modified);
         Assert.AreEqual(test.expectedWorked, ConcurrentMask.Succeeded(worked));
     }
 }
Exemplo n.º 2
0
    public void FreesMultipleBitsFromArray()
    {
        var storage = new NativeList <long>(3, Allocator.Persistent);

        storage.Length = 3;
        ConcurrentMask.TryAllocate(ref storage, out int _, 64);
        ConcurrentMask.TryAllocate(ref storage, out int _, 64);
        ConcurrentMask.TryAllocate(ref storage, out int _, 64);
        for (var i = 0; i < 3; ++i)
        {
            var worked = ConcurrentMask.TryFree(ref storage, i * 64 + 1, 63);
            Assert.AreEqual(true, ConcurrentMask.Succeeded(worked));
        }
        Assert.AreEqual(1L, storage[0]);
        Assert.AreEqual(1L, storage[1]);
        Assert.AreEqual(1L, storage[2]);
        storage.Dispose();
    }
Exemplo n.º 3
0
 public void FreesOneBitFromLong()
 {
     foreach (var test in new Test[] {
         new Test(0x0000000000000000UL, 0x0000000000000001UL, 0, true),
         new Test(0x0000000000000001UL, 0x0000000000000003UL, 1, true),
         new Test(0x00000000000000FFUL, 0x00000000000001FFUL, 8, true),
         new Test(0x0000000000000100UL, 0x0000000000000101UL, 0, true),
         new Test(0x7FFFFFFFFFFFFFFFUL, 0xFFFFFFFFFFFFFFFFUL, 63, true),
         new Test(0x8000000000000000UL, 0x8000000000000001UL, 0, true),
     })
     {
         long expectedModified = (long)test.value;
         long modified         = (long)test.expectedModified;
         var  worked           = ConcurrentMask.TryFree(ref modified, test.offset, 1);
         Assert.AreEqual(expectedModified, modified);
         Assert.AreEqual(test.expectedWorked, ConcurrentMask.Succeeded(worked));
     }
 }