Пример #1
0
        public void TestContains()
        {
            Assert.IsTrue(_biDictionary.Contains(new KeyValuePair <int, double>(10, 5.0)));
            Assert.IsTrue(_biDictionary.Contains(new KeyValuePair <double, int>(5.0, 10)));

            Assert.IsTrue(_biDictionary.ContainsKey(10));
            Assert.IsTrue(_biDictionary.ContainsValue(5.0));

            Assert.IsTrue(_biDictionary.ContainsKey(5.0));
            Assert.IsTrue(_biDictionary.ContainsValue(10));
        }
Пример #2
0
        public void BiDictionaryTest_containsValue_simple()
        {
            var biDictionary = new BiDictionary <Vector2Int, Vector2Int>
            {
                { new Vector2Int(5, 5), new Vector2Int(4, 4) },
                { new Vector2Int(6, 6), new Vector2Int(3, 3) },
                { new Vector2Int(7, 7), new Vector2Int(2, 2) }
            };

            Assert.IsTrue(biDictionary.ContainsValue(new Vector2Int(3, 3)));
            Assert.IsFalse(biDictionary.ContainsValue(new Vector2Int(6, 6)));
        }
Пример #3
0
        public bool GetCellPos(NavNode node, out Vector3Int cellPos)
        {
            Assert.IsTrue(initiated);

            if (map.ContainsValue(node))
            {
                cellPos = map.ValueMap[node];
                return(true);
            }

            cellPos = -Vector3Int.one;
            return(false);
        }
Пример #4
0
        /// <summary> Reads <see cref="Packet"/> objects from the network and queues them in the <see cref="receivedPackets"/> queue. </summary>
        private void ReadWork()
        {
            try
            {
                while (true)
                {
                    ushort packetType   = BitConverter.ToUInt16(ReadBytes(2), 0);
                    int    packetLength = BitConverter.ToInt32(ReadBytes(4), 0);
                    byte[] packetData   = ReadBytes(packetLength);

                    if (!typeByte.ContainsValue(packetType))
                    {
                        //Theoretically it is not possible that we receive a packet
                        //which is not known, since all the packets need to pass a certification.
                        //But if the UDP connection sends something and the AddPacketTypeRequest get lost
                        //this case is going to happen.
                        //从理论上讲,我们不可能收到未知的数据包,因为所有数据包都需要通过认证。但是,如果UDP连接发送了一些消息,而AddPacketTypeRequest丢失了,则将发生这种情况。
                        HandleUnknownPacket();
                        continue;
                    }

                    Packet receivedPacket = packetConverter.GetPacket(typeByte[packetType], packetData);
                    receivedPackets.Enqueue(receivedPacket);
                    receivedPacket.Size = packetLength;

                    Logger.LogInComingPacket(packetData, receivedPacket);

                    packetAvailableEvent.Set();
                }
            }
            catch (Exception exception)
            {
                if (!threadCancellationTokenSource.IsCancellationRequested)
                {
                    Logger.Log("Reading packet from stream", exception, LogLevel.Exception);
                }
                else
                {
                    return;
                }
            }

            CloseHandler(CloseReason.ReadPacketThreadException);
        }
Пример #5
0
        public void BiDictionaryTest()
        {
            BiDictionary <int, string, double> test1 = new BiDictionary <int, string, double>()
            {
                { 1, "first", 1.0 },
                { 2, "second", 2.0 },
                { 3, "third", 3.0 }
            };

            test1.Add(4, "fourth", 4.0);

            Assert.AreEqual(test1.ByKey1[1], 1.0);
            Assert.AreEqual(test1.ByKey2["first"], 1.0);

            Assert.IsTrue(test1.ContainsKey(1));
            Assert.IsTrue(test1.ContainsKey("first"));
            Assert.IsTrue(test1.ContainsKey(2));
            Assert.IsTrue(test1.ContainsKey(3));
            Assert.IsTrue(test1.ContainsKey(4));

            Assert.IsTrue(test1.ContainsValue(4.0));
        }