From a84d66195ed989224814a216d94bf269661b1f2e Mon Sep 17 00:00:00 2001 From: ikpil Date: Wed, 1 May 2024 12:54:57 +0900 Subject: [PATCH] added RcRentedArray test --- test/DotRecast.Core.Test/RcRentedArrayTest.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/DotRecast.Core.Test/RcRentedArrayTest.cs b/test/DotRecast.Core.Test/RcRentedArrayTest.cs index 07d1f1b..0974f0d 100644 --- a/test/DotRecast.Core.Test/RcRentedArrayTest.cs +++ b/test/DotRecast.Core.Test/RcRentedArrayTest.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using DotRecast.Core.Buffers; using NUnit.Framework; @@ -56,4 +57,50 @@ public class RcRentedArrayTest Assert.Throws(() => rentedArray[^1] = 0); } } + + [Test] + public void TestSame() + { + // not same + { + using var r1 = RcRentedArray.Rent(1024); + using var r2 = RcRentedArray.Rent(1024); + + Assert.That(r2.AsArray() != r1.AsArray(), Is.EqualTo(true)); + } + + // same + { + // error case + float[] r1Array; + using (var r1 = RcRentedArray.Rent(1024)) + { + r1Array = r1.AsArray(); + for (int i = 0; i < r1.Length; ++i) + { + r1[i] = 123; + } + } + + using var r2 = RcRentedArray.Rent(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(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); + } } \ No newline at end of file