예제 #1
0
        private void TpiSocket_ResponseReceived(object sender, TpiResponse response)
        {
            switch (response.ResponseType)
            {
            case TpiResponseType.System:
                this.ProcessEvent(response);
                break;

            case TpiResponseType.Partition:
                // Find the partition and process it (ignore any partitions that are not defined in app settings)
                Partition p = PartitionList.FirstOrDefault(x => x.Id == response.PartitionId);
                if (p != null)
                {
                    p.ProcessEvent(response);
                }
                break;

            case TpiResponseType.Zone:
                // Find the zone and process it (ignore any zones that are not defined in app settings)
                Zone z = ZoneList.FirstOrDefault(x => x.Id == response.ZoneId);
                if (z != null)
                {
                    z.ProcessEvent(response);
                }
                break;
            }
        }
예제 #2
0
        public void Partition(ListNode head, int x, ListNode expected)
        {
            var sut    = new PartitionList();
            var actual = sut.Partition(head, x);

            Assert.AreEqual(JsonConvert.SerializeObject(expected), JsonConvert.SerializeObject(actual));
        }
예제 #3
0
        public void TestPartitionList()
        {
            var head = MyLinkList.BuildListNodeFromArray(new[] { 1, 4, 3, 2, 5, 2 });

            head = PartitionList.Do(head, 3);
            Assert.AreEqual(head.Next.Next.Val, 2);
            Assert.AreEqual(head.Next.Next.Next.Next.Val, 4);
        }
예제 #4
0
        public void Given_list_When_partition_2_Then_return()
        {
            var list = new ListNode(2)
            {
                next = new ListNode(1)
                {
                }
            };

            var result = PartitionList.Partition(list, 2);

            Assert.AreEqual(1, result.val);
        }
예제 #5
0
        public void Given_list_When_partition_3_Then_return()
        {
            var list = new ListNode(5)
            {
                next = new ListNode(2)
                {
                    next = new ListNode(3)
                    {
                        next = new ListNode(4)
                    },
                }
            };

            var result = PartitionList.Partition(list, 3);

            Assert.AreEqual(2, result.val);
        }
예제 #6
0
        public void TestPartitionList()
        {
            PartitionList.ListNode head  = new PartitionList.ListNode(1);
            PartitionList.ListNode node2 = new PartitionList.ListNode(4);
            PartitionList.ListNode node3 = new PartitionList.ListNode(3);
            PartitionList.ListNode node4 = new PartitionList.ListNode(2);
            PartitionList.ListNode node5 = new PartitionList.ListNode(5);
            PartitionList.ListNode node6 = new PartitionList.ListNode(6);
            head.Next  = node2;
            node2.Next = node3;
            node3.Next = node4;
            node4.Next = node5;
            node5.Next = node6;

            var f      = new PartitionList();
            var answer = f.Run(head, 3);

            while (answer != null)
            {
                Console.Write($" {answer.Val} ->");
                answer = answer.Next;
            }
        }