Firstborn/Library/PackageCache/com.unity.collections@1.4.0/Unity.Collections.Tests/UnsafeAtomicCounterTests.cs
Schaken-Mods b486678290 Library -Artifacts
Library -Artifacts
2023-03-28 12:24:16 -05:00

45 lines
1.3 KiB
C#

using NUnit.Framework;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Collections.Tests;
internal class UnsafeCounterTests
{
[Test]
public unsafe void UnsafeAtomicCounter32_AddSub()
{
int value = 0;
var counter = new UnsafeAtomicCounter32(&value);
Assert.AreEqual(0, counter.Add(123));
Assert.AreEqual(123, counter.Add(0));
Assert.AreEqual(123, counter.Sub(0));
Assert.AreEqual(123, counter.AddSat(1, 123));
Assert.AreEqual(123, counter.SubSat(1, 123));
counter.AddSat(0xffff, 256);
Assert.AreEqual(256, counter.Add(0));
counter.SubSat(0xffff, -256);
Assert.AreEqual(-256, counter.Add(0));
}
[Test]
public unsafe void UnsafeAtomicCounter64_AddSub()
{
long value = 0;
var counter = new UnsafeAtomicCounter64(&value);
Assert.AreEqual(0, counter.Add(123));
Assert.AreEqual(123, counter.Add(0));
Assert.AreEqual(123, counter.Sub(0));
Assert.AreEqual(123, counter.AddSat(1, 123));
Assert.AreEqual(123, counter.SubSat(1, 123));
counter.AddSat(0xffff, 256);
Assert.AreEqual(256, counter.Add(0));
counter.SubSat(0xffff, -256);
Assert.AreEqual(-256, counter.Add(0));
}
}