added RcRentedArray test

This commit is contained in:
ikpil 2024-05-01 12:54:57 +09:00
parent 29fab9f5b2
commit a84d66195e
1 changed files with 47 additions and 0 deletions

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using DotRecast.Core.Buffers; using DotRecast.Core.Buffers;
using NUnit.Framework; using NUnit.Framework;
@ -56,4 +57,50 @@ public class RcRentedArrayTest
Assert.Throws<NullReferenceException>(() => rentedArray[^1] = 0); Assert.Throws<NullReferenceException>(() => rentedArray[^1] = 0);
} }
} }
[Test]
public void TestSame()
{
// not same
{
using var r1 = RcRentedArray.Rent<float>(1024);
using var r2 = RcRentedArray.Rent<float>(1024);
Assert.That(r2.AsArray() != r1.AsArray(), Is.EqualTo(true));
}
// same
{
// error case
float[] r1Array;
using (var r1 = RcRentedArray.Rent<float>(1024))
{
r1Array = r1.AsArray();
for (int i = 0; i < r1.Length; ++i)
{
r1[i] = 123;
}
}
using var r2 = RcRentedArray.Rent<float>(1024);
Assert.That(r2.AsArray() == r1Array, Is.EqualTo(true));
Assert.That(r2.AsArray().Sum(), Is.EqualTo(0));
}
}
[Test]
public void TestDispose()
{
var r1 = RcRentedArray.Rent<float>(1024);
for (int i = 0; i < r1.Length; ++i)
{
r1[i] = 123;
}
Assert.That(r1.IsDisposed, Is.EqualTo(false));
r1.Dispose();
Assert.That(r1.IsDisposed, Is.EqualTo(true));
Assert.That(r1.AsArray(), Is.Null);
}
} }