using NUnit.Framework; using Unity.Collections; using Unity.Jobs; namespace Unity.Jobs.Tests.ManagedJobs { public class JobTestsFixtureBasic { [SetUp] public void Setup() { #if UNITY_DOTSRUNTIME Unity.Runtime.TempMemoryScope.EnterScope(); #endif } [TearDown] public void Teardown() { #if UNITY_DOTSRUNTIME Unity.Runtime.TempMemoryScope.ExitScope(); #endif } } public class JobTestsFixture : JobTestsFixtureBasic { /* * this used to test both, and maybe it should again, but we have to make GetExecuteMethod() work with * multiple interfaces, hopefully in a non-global way */ public struct SumDataParallelForJob : /*IJob,*/ IJobParallelFor { [ReadOnly] public NativeArray input0; [ReadOnly] public NativeArray input1; public NativeArray output; /* public void Execute() { for (var i = 0; i < output.Length; ++i) output[i] = input0[i] + input1[i]; }*/ public void Execute(int i) { output[i] = input0[i] + input1[i]; } } public struct CopyAndDestroyNativeArrayParallelForJob : IJobParallelFor { [ReadOnlyAttribute][DeallocateOnJobCompletionAttribute] public NativeArray input; public NativeArray output; public void Execute(int i) { output[i] = input[i]; } } public SumDataParallelForJob data; public int[] expectedInput0; public NativeArray input0; public NativeArray input1; public NativeArray input2; public NativeArray output; public NativeArray output2; [SetUp] public void Init() { expectedInput0 = new int[10]; input0 = new NativeArray(10, Allocator.Persistent); input1 = new NativeArray(10, Allocator.Persistent); input2 = new NativeArray(10, Allocator.Persistent); output = new NativeArray(10, Allocator.Persistent); output2 = new NativeArray(10, Allocator.Persistent); for (var i = 0; i < output.Length; i++) { expectedInput0[i] = i; input0[i] = i; input1[i] = 10 * i; input2[i] = 100 * i; output[i] = 0; output2[i] = 0; } data.input0 = input0; data.input1 = input1; data.output = output; } public void ExpectOutputSumOfInput0And1() { for (var i = 0; i != output.Length; i++) Assert.AreEqual(input0[i] + input1[i], output[i]); } public void ExpectOutputSumOfInput0And1And2() { for (var i = 0; i != output.Length; i++) Assert.AreEqual(input0[i] + input1[i] + input2[i], output[i]); } [TearDown] public void Cleanup() { try { input0.Dispose(); } catch { } try { input1.Dispose(); } catch { } try { input2.Dispose(); } catch { } try { output.Dispose(); } catch { } try { output2.Dispose(); } catch { } } } }