public void NativeMultiHashMap_ForEach_Throws_When_Modified_From_Job() { using (var container = new NativeMultiHashMap <int, int>(32, Allocator.TempJob)) { var iter = container.GetEnumerator(); var jobHandle = new ParallelWriteToMultiHashMapJob { Writer = container.AsParallelWriter() }.Schedule(1, 2); #if UNITY_2020_2_OR_NEWER Assert.Throws <ObjectDisposedException>(() => #else Assert.Throws <InvalidOperationException>(() => #endif { while (iter.MoveNext()) { } }); jobHandle.Complete(); } }
private void CheckData(int size) { var result = new Dictionary <TKey, List <TValue> >(); using (var nativeMultiHashMapEnumerator = _nativeMultiHashMap.GetEnumerator()) { while (nativeMultiHashMapEnumerator.MoveNext()) { var data = nativeMultiHashMapEnumerator.Current; if (result.ContainsKey(data.Key)) { Assert.IsTrue(result.TryGetValue(data.Key, out var values)); values.Add(data.Value); } else { result.Add(data.Key, new List <TValue> { data.Value }); } Assert.IsTrue(result.ContainsKey(data.Key)); } } Assert.AreEqual(size, Length(result)); Assert.AreEqual( result.Keys.Intersect(_checkingResults.Keys).Count(), result.Keys.Union(_checkingResults.Keys).Count() ); foreach (var values in result) { Assert.IsTrue(_checkingResults.TryGetValue(values.Key, out var compareValues)); Assert.AreEqual( values.Value.Intersect(compareValues).Count(), values.Value.Union(compareValues).Count() ); } }
public void NativeMultiHashMap_ForEach_Throws_Job_Iterator() { using (var container = new NativeMultiHashMap <int, int>(32, Allocator.TempJob)) { var jobHandle = new NativeMultiHashMap_ForEachIterator { Iter = container.GetEnumerator() }.Schedule(); Assert.Throws <InvalidOperationException>(() => { container.Add(1, 1); }); jobHandle.Complete(); } }