Beispiel #1
0
 public void Add(T value, int backingValue, string name)
 {
     if (!entriesFromRequests.IsKnownKey(backingValue))
     {
         entriesFromRequests.Add(value, backingValue, name);
     }
 }
        public void Add_SameKeys_Allowed()
        {
            var dict = new DoubleKeyDictionary<string, string, int>();
            dict.Add("1", "1", 2);
            dict.Add("1", "1", 4);

            Assert.IsTrue(dict.ContainsKey("1", "1"));
        }
Beispiel #3
0
        public void AddTestArgumentNullException()
        {
            DoubleKeyDictionary <int, string, string> map = CreateDictionary();

            map.Add(8, "p", null);

            map.Add(0, null, "P");
        }
        public void Add_SameKeys_Allowed()
        {
            var dict = new DoubleKeyDictionary <string, string, int>();

            dict.Add("1", "1", 2);
            dict.Add("1", "1", 4);

            Assert.IsTrue(dict.ContainsKey("1", "1"));
        }
        public void Add_IntKeys_Works()
        {
            var dict = new DoubleKeyDictionary<int, int, int>();
            dict.Add(1, 1, 2);
            dict.Add(2, 2, 4);

            Assert.IsTrue(dict.ContainsKey(1, 1));
            Assert.IsTrue(dict.ContainsKey(2, 2));
        }
        public void Add_StringAndIntKeys_Works()
        {
            var dict = new DoubleKeyDictionary<string, int, int>();
            dict.Add("1", 1, 2);
            dict.Add("2", 2, 4);

            Assert.IsTrue(dict.ContainsKey("1", 1));
            Assert.IsTrue(dict.ContainsKey("2", 2));
        }
        public void Add_StringAndIntKeys_Works()
        {
            var dict = new DoubleKeyDictionary <string, int, int>();

            dict.Add("1", 1, 2);
            dict.Add("2", 2, 4);

            Assert.IsTrue(dict.ContainsKey("1", 1));
            Assert.IsTrue(dict.ContainsKey("2", 2));
        }
        public void Add_IntKeys_Works()
        {
            var dict = new DoubleKeyDictionary <int, int, int>();

            dict.Add(1, 1, 2);
            dict.Add(2, 2, 4);

            Assert.IsTrue(dict.ContainsKey(1, 1));
            Assert.IsTrue(dict.ContainsKey(2, 2));
        }
        public void Equals_IntKeys_MultipleValues_NotEqual()
        {
            var dict1 = new DoubleKeyDictionary <int, int, int>();
            var dict2 = new DoubleKeyDictionary <int, int, int>();

            dict1.Add(1, 1, 2);
            dict1.Add(1, 2, 3);
            dict2.Add(1, 1, 2);

            Assert.IsFalse(dict1.Equals(dict2));
        }
        public void Equals_IntKeys_DifferentKeys_NotEqual()
        {
            var dict1 = new DoubleKeyDictionary <int, int, int>();
            var dict2 = new DoubleKeyDictionary <int, int, int>();

            dict1.Add(1, 1, 2);
            dict1.Add(2, 1, 3);
            dict2.Add(1, 1, 2);

            Assert.IsFalse(dict1.Equals(dict2));
        }
        public void Equals_IntKeys_DifferentKeys_NotEqual()
        {
            var dict1 = new DoubleKeyDictionary<int, int, int>();
            var dict2 = new DoubleKeyDictionary<int, int, int>();

            dict1.Add(1, 1, 2);
            dict1.Add(2, 1, 3);
            dict2.Add(1, 1, 2);

            Assert.IsFalse(dict1.Equals(dict2));
        }
        public void Equals_StringKeys_MultipleValues_NotEqual()
        {
            var dict1 = new DoubleKeyDictionary <string, string, int>();
            var dict2 = new DoubleKeyDictionary <string, string, int>();

            dict1.Add("1", "1", 2);
            dict1.Add("1", "2", 3);
            dict2.Add("1", "1", 2);

            Assert.IsFalse(dict1.Equals(dict2));
        }
Beispiel #13
0
        //
        //编写测试时,还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        private DoubleKeyDictionary <int, string, string> CreateDictionary()
        {
            DoubleKeyDictionary <int, string, string> map = new DoubleKeyDictionary <int, string, string>();

            map.Add(1, "a", "Z");
            map.Add(2, "b", "X");
            map.Add(3, "c", "S");
            map.Add(4, "d", "C");
            map.Add(5, "e", "R");

            return(map);
        }
        public void AddingItemTwiceThrows()
        {
            var key1  = 5;
            var key2  = "key2";
            var value = "asmdpsodfgkhöglhmdfgh d";

            var dictionary = new DoubleKeyDictionary <int, string, string>();

            dictionary.Add(key1, key2, value);

            Action addSecondTime = () => { dictionary.Add(key1, key2, value); };

            addSecondTime.Should().Throw <Exception>();
        }
        public void Add_SameKeys_UpdatesValue()
        {
            var dict = new DoubleKeyDictionary<string, string, int>();

            // add first value
            dict.Add("1", "1", 2);
            var val = dict["1", "1"];
            // assert value is 2
            Assert.AreEqual<int>(2, val);

            // update value
            dict.Add("1", "1", 4);
            val = dict["1", "1"];
            // assert value has been updated to 4
            Assert.AreEqual<int>(4, val);
        }
Beispiel #16
0
        /// <summary>
        /// 查找相交线段
        /// </summary>
        /// <param name="lineSegs"></param>
        /// <returns></returns>
        public Vector2[] FindIntersections(LineSegment2D[] lineSegs)
        {
            this.Clear();

            if (lineSegs == null || lineSegs.Length == 0)
            {
                return(null);
            }

            VertexSegment2D[] segs = new VertexSegment2D[lineSegs.Length];

            for (var i = 0; i < lineSegs.Length; i++)
            {
                var seg = new VertexSegment2D(lineSegs[i]);

                segs[i] = seg;

                _upLineSegment.Add(seg.Up, seg);
                _lowLineSegment.Add(seg.Low, seg);

                _sortedVertexes.Add(seg.Up);
                _sortedVertexes.Add(seg.Low);
            }

            while (_sortedVertexes.Count > 0)
            {
                var point = _sortedVertexes.Min;
                _sortedVertexes.Remove(point);
                HandleEventPoint(point);
            }

            return(_sortedVertexes.ToArray());
        }
        public void Add_SameKeys_UpdatesValue()
        {
            var dict = new DoubleKeyDictionary <string, string, int>();

            // add first value
            dict.Add("1", "1", 2);
            var val = dict["1", "1"];

            // assert value is 2
            Assert.AreEqual <int>(2, val);

            // update value
            dict.Add("1", "1", 4);
            val = dict["1", "1"];
            // assert value has been updated to 4
            Assert.AreEqual <int>(4, val);
        }
        internal void LoadCache()
        {
            if (cacheLoaded)
            {
                return;
            }

            ReadCacheFile(GetCachePath(), (index, name) => { entriesFromFile.Add(index, name); });

            ReadCacheFile(GetDeactivatedCachePath(), (index, name) =>
            {
                entriesFromDeactivatedFile.Add(index, name);
                entriesFromFile.Add(index, name);
            });

            cacheLoaded = true;
        }
Beispiel #19
0
        public void AddTest()
        {
            DoubleKeyDictionary <int, string, string> map = CreateDictionary();

            map.Add(9, "p", "O");
            map.ContainsKeyOne(9).IsTrue();
            map.ContainsKeyTwo("p").IsTrue();
        }
        public void RemoveLevel1ReturnsFalseIfNothingFound()
        {
            var key1  = 5;
            var key21 = "key1";
            var key22 = "key2";
            var key12 = 2;

            var dictionary = new DoubleKeyDictionary <int, string, string>();

            dictionary.Add(key1, key21, "value11");
            dictionary.Add(key1, key22, "value2");
            dictionary.Add(key12, key21, "value3");
            dictionary.Add(key12, key22, "value4");

            var result = dictionary.Remove(3);

            result.Should().BeFalse();
        }
        public void Equals_IntKeys_OneValue_AreEqual()
        {
            var dict1 = new DoubleKeyDictionary <int, int, int>();
            var dict2 = new DoubleKeyDictionary <int, int, int>();

            dict1.Add(1, 1, 2);
            dict2.Add(1, 1, 2);

            Assert.IsTrue(dict1.Equals(dict2));
        }
        public void Equals_IntKeys_OneValue_AreEqual()
        {
            var dict1 = new DoubleKeyDictionary<int, int, int>();
            var dict2 = new DoubleKeyDictionary<int, int, int>();

            dict1.Add(1, 1, 2);
            dict2.Add(1, 1, 2);

            Assert.IsTrue(dict1.Equals(dict2));
        }
        public void Equals_StringKeys_OneValue_AreEqual()
        {
            var dict1 = new DoubleKeyDictionary<string, string, int>();
            var dict2 = new DoubleKeyDictionary<string, string, int>();

            dict1.Add("1", "1", 2);
            dict2.Add("1", "1", 2);

            Assert.IsTrue(dict1.Equals(dict2));
        }
        public void Equals_StringKeys_OneValue_AreEqual()
        {
            var dict1 = new DoubleKeyDictionary <string, string, int>();
            var dict2 = new DoubleKeyDictionary <string, string, int>();

            dict1.Add("1", "1", 2);
            dict2.Add("1", "1", 2);

            Assert.IsTrue(dict1.Equals(dict2));
        }
        public void Equals_DifferentKeyTypes_SameValue_NotEqual()
        {
            var dict1 = new DoubleKeyDictionary <int, string, int>();
            var dict2 = new DoubleKeyDictionary <string, string, int>();

            dict1.Add(1, "1", 2);
            dict2.Add("1", "1", 2);

            Assert.IsFalse(dict1.Equals(dict2));
        }
        public void Equals_StringKeys_SameKeys_DifferentValue_NotEqual()
        {
            var dict1 = new DoubleKeyDictionary<string, string, int>();
            var dict2 = new DoubleKeyDictionary<string, string, int>();

            dict1.Add("1", "1", 3);
            dict2.Add("1", "1", 2);

            Assert.IsFalse(dict1.Equals(dict2));
        }
    public DoubleKeyDictionary <K1, K2, Value> Clone()
    {
        DoubleKeyDictionary <K1, K2, Value> clone = new DoubleKeyDictionary <K1, K2, Value>();

        foreach (K1 key in base.Keys)
        {
            clone.Add(key, this[key].Clone());
        }
        return(clone);
    }
        public void Enumerate_IntKeys_ToString_Returns_Key1Key2Value()
        {
            var dict = new DoubleKeyDictionary <string, string, int>();

            dict.Add("a", "b", 1);

            foreach (var item in dict)
            {
                Assert.AreEqual <string>("a - b - 1", item.ToString());
            }
        }
        public void Enumerate_IntKeys_ToString_Returns_Key1Key2Value()
        {
            var dict = new DoubleKeyDictionary<string, string, int>();
            dict.Add("a", "b", 1);

            foreach (var item in dict)
            {
                Assert.AreEqual<string>("a - b - 1", item.ToString());
            }
        
        }
        public void CanRemoveExactEntry()
        {
            var key1  = 5;
            var key21 = "key1";
            var key22 = "key2";
            var key12 = 2;

            var dictionary = new DoubleKeyDictionary <int, string, string>();

            dictionary.Add(key1, key21, "value11");
            dictionary.Add(key1, key22, "value2");
            dictionary.Add(key12, key21, "value3");
            dictionary.Add(key12, key22, "value4");

            var result = dictionary.Remove(key1, key21);

            result.Should().BeTrue();
            dictionary.Count.Should().Be(3);
            dictionary.Contains(key1, key21).Should().BeFalse();
            dictionary.GetAll().FirstOrDefault(x => x == "value11").Should().BeNullOrEmpty();
        }
        private DoubleKeyDictionary <TKeyId, TKeyName, TValue> Initialize <TKeyId, TKeyName, TValue>(int count)
        {
            var doubleKeyDictionary = new DoubleKeyDictionary <TKeyId, TKeyName, TValue>();
            var typeId    = Nullable.GetUnderlyingType(typeof(TKeyId)) ?? typeof(TKeyId);
            var typeName  = Nullable.GetUnderlyingType(typeof(TKeyName)) ?? typeof(TKeyName);
            var typeValue = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue);

            for (var i = 0; i < count; i++)
            {
                doubleKeyDictionary.Add((TKeyId)Convert.ChangeType(i, typeId, CultureInfo.InvariantCulture), (TKeyName)Convert.ChangeType(i, typeName, CultureInfo.InvariantCulture), (TValue)Convert.ChangeType(i, typeValue, CultureInfo.InvariantCulture));
            }
            return(doubleKeyDictionary);
        }
        public void AddedItemsKeysAreFound()
        {
            var key1  = 5;
            var key2  = "key2";
            var value = "asmdpsodfgkhöglhmdfgh d";

            var dictionary = new DoubleKeyDictionary <int, string, string>();

            dictionary.Add(key1, key2, value);

            var result = dictionary.Contains(key1, key2);

            result.Should().BeTrue();
        }
 public void ResetDictionary()
 {
     dict = new DoubleKeyDictionary<int, int, int>();
     dict.Add(1, 1, 2);
     dict.Add(2, 1, 3);
     dict.Add(3, 1, 4);
     dict.Add(1, 2, 3);
     dict.Add(1, 3, 4);
     dict.Add(1, 4, 5);
 }
 public void ResetDictionary()
 {
     dict = new DoubleKeyDictionary <int, int, int>();
     dict.Add(1, 1, 2);
     dict.Add(2, 1, 3);
     dict.Add(3, 1, 4);
     dict.Add(1, 2, 3);
     dict.Add(1, 3, 4);
     dict.Add(1, 4, 5);
 }
        public void AddedItemIsFound()
        {
            var key1  = 5;
            var key2  = "key2";
            var value = "asmdpsodfgkhöglhmdfgh d";

            var dictionary = new DoubleKeyDictionary <int, string, string>();

            dictionary.Add(key1, key2, value);

            string resultValue = null;
            var    result      = dictionary.TryGetValue(key1, key2, out resultValue);

            result.Should().BeTrue();
            resultValue.Should().BeSameAs(value);
        }
 /// <summary>
 /// Registers the specified model unique identifier.
 /// </summary>
 /// <typeparam name="T">Geometry Buffer Type</typeparam>
 /// <param name="modelGuid">The model unique identifier.</param>
 /// <param name="geometry">The geometry.</param>
 /// <returns></returns>
 public IGeometryBufferModel Register <T>(Guid modelGuid, Geometry3D geometry) where T : class, IGeometryBufferModel, new()
 {
     if (geometry == null || modelGuid == Guid.Empty)
     {
         return(EmptyGeometryBufferModel.Empty);
     }
     lock (bufferDictionary)
     {
         IGeometryBufferModel container;
         if (bufferDictionary.TryGetValue(typeof(T), geometry.GUID, out var obj))
         {
             if (logger.IsEnabled(LogLevel.Trace))
             {
                 logger.LogTrace("Existing buffer found, GeomoetryGUID = {}", geometry.GUID);
             }
             container = obj as IGeometryBufferModel;
             obj.IncRef();
         }
         else
         {
             if (logger.IsEnabled(LogLevel.Trace))
             {
                 logger.LogTrace("Buffer not found, create new buffer. GeomoetryGUID = {}", geometry.GUID);
             }
             container = new T();
             var id = geometry.GUID;
             obj           = container as DisposeObject;
             obj.Disposed += (s, e) =>
             {
                 if (logger.IsEnabled(LogLevel.Trace))
                 {
                     logger.LogTrace("Disposing Geometry Buffer. GeomoetryGUID = {}", id);
                 }
                 lock (bufferDictionary)
                 {
                     bufferDictionary.Remove(typeof(T), id);
                 }
             };
             container.EffectsManager = manager;
             container.Geometry       = geometry;
             bufferDictionary.Add(typeof(T), geometry.GUID, obj);
         }
         return(container);
     }
 }
Beispiel #37
0
        internal IEnumerable <JiraNamedEntity> GetFieldsForAction(Issue issue, string actionId)
        {
            if (issue.Key == null)
            {
                issue = GetOneIssueFromProject(issue.Project);
            }

            if (!_cachedFieldsForAction.ContainsKey(issue.Project, actionId))
            {
                WithToken((token, service) =>
                {
                    _cachedFieldsForAction.Add(issue.Project, actionId, _jiraService.GetFieldsForAction(token, issue.Key.Value, actionId)
                                               .Select(f => new JiraNamedEntity(f)));
                });
            }

            return(_cachedFieldsForAction[issue.Project, actionId]);
        }
        public MaterialVariable Register(IMaterial material, IRenderTechnique technique)
        {
            if (material == null || technique.IsNull)
            {
                return(EmptyMaterialVariable.EmptyVariable);
            }
            var guid     = material.Guid;
            var techGuid = technique.GUID;

            lock (dictionary)
            {
                if (dictionary.TryGetValue(guid, techGuid, out MaterialVariable value))
                {
                    value.IncRef();
                    return(value);
                }
                else
                {
                    var v = material.CreateMaterialVariables(effectsManager, technique);
                    v.Initialize();
                    v.Disposed += (s, e) =>
                    {
                        lock (dictionary)
                        {
                            dictionary.Remove(guid, techGuid);
                        }
                    };
                    dictionary.Add(guid, techGuid, v);
                    if (IDMAX - (ushort)Count > 1000)
                    {
                        IDMAX = 0;
                        foreach (var m in dictionary)
                        {
                            m.Value.ID = ++IDMAX;
                        }
                    }
                    else
                    {
                        v.ID = ++IDMAX;
                    }
                    return(v);
                }
            }
        }
Beispiel #39
0
        public virtual bool Add(IEntity entity)
        {
            if (entity.LocalId == 0)
            {
                MainConsole.Instance.Warn("Entity with 0 localID!");
                return(false);
            }

            try
            {
                if (entity is ISceneEntity)
                {
                    lock (m_child_2_parent_entitiesLock)
                    {
                        foreach (ISceneChildEntity part in (entity as ISceneEntity).ChildrenEntities())
                        {
                            m_child_2_parent_entities.Remove(part.UUID);
                            m_child_2_parent_entities.Remove(part.LocalId);
                            m_child_2_parent_entities.Add(part.UUID, part.LocalId, entity.UUID);
                        }
                    }
                    lock (m_objectEntitiesLock)
                        m_objectEntities.Add(entity.UUID, entity.LocalId, entity as ISceneEntity);
                }
                else
                {
                    IScenePresence presence = (IScenePresence)entity;

                    lock (m_presenceEntitiesLock)
                    {
                        m_presenceEntitiesList.Add(presence);
                        m_presenceEntities.Add(presence.UUID, presence);
                    }
                }
            }
            catch (Exception e)
            {
                MainConsole.Instance.ErrorFormat("Add Entity failed: {0}", e.Message);
                return(false);
            }
            return(true);
        }
         /// <summary>
         /// Registers the specified model unique identifier.
         /// </summary>
         /// <typeparam name="T">Geometry Buffer Type</typeparam>
         /// <param name="modelGuid">The model unique identifier.</param>
         /// <param name="geometry">The geometry.</param>
         /// <returns></returns>
         public IGeometryBufferModel Register <T>(Guid modelGuid, Geometry3D geometry) where T : class, IGeometryBufferModel, new()
         {
             if (geometry == null || modelGuid == Guid.Empty)
             {
                 return(EmptyGeometryBufferModel.Empty);
             }
             lock (bufferDictionary)
             {
                 IGeometryBufferModel container;
                 if (bufferDictionary.TryGetValue(typeof(T), geometry.GUID, out ReferenceCountDisposeObject obj))
                 {
 #if DEBUGDETAIL
                     Debug.WriteLine("Existing buffer found, GeomoetryGUID = " + geometry.GUID);
 #endif
                     container = obj as IGeometryBufferModel;
                     obj.IncRef();
                 }
                 else
                 {
 #if DEBUGDETAIL
                     Debug.WriteLine("Buffer not found, create new buffer. GeomoetryGUID = " + geometry.GUID);
 #endif
                     container = new T();
                     var id = geometry.GUID;
                     obj           = container as ReferenceCountDisposeObject;
                     obj.Disposed += (s, e) =>
                     {
                         lock (bufferDictionary)
                         {
                             bufferDictionary.Remove(typeof(T), id);
                         }
                     };
                     container.EffectsManager = manager;
                     container.Geometry       = geometry;
                     bufferDictionary.Add(typeof(T), geometry.GUID, obj);
                 }
                 return(container);
             }
         }
        public void Equals_StringKeys_MultipleValues_NotEqual()
        {
            var dict1 = new DoubleKeyDictionary<string, string, int>();
            var dict2 = new DoubleKeyDictionary<string, string, int>();

            dict1.Add("1", "1", 2);
            dict1.Add("1", "2", 3);
            dict2.Add("1", "1", 2);

            Assert.IsFalse(dict1.Equals(dict2));
        }
        public void Equals_IntKeys_MultipleValues_NotEqual()
        {
            var dict1 = new DoubleKeyDictionary<int, int, int>();
            var dict2 = new DoubleKeyDictionary<int, int, int>();

            dict1.Add(1, 1, 2);
            dict1.Add(1, 2, 3);
            dict2.Add(1, 1, 2);

            Assert.IsFalse(dict1.Equals(dict2));
        }