Example #1
0
            public void ReverseTest_Neg123ReturnNeg321()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = -321;

                // act
                var actual = LCSolution.Reverse(-123);

                // assert
                Assert.AreEqual(expected, actual);
            }
Example #2
0
            public void ReverseTest_0Return0()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = 0;

                // act
                var actual = LCSolution.Reverse(0);

                // assert
                Assert.AreEqual(expected, actual);
            }
Example #3
0
            public void SortStringTest_leetcodeReturncdelotee()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = "cdelotee";

                // act
                string input  = "leetcode";
                var    actual = LCSolution.SortString(input);

                // assert
                Assert.AreEqual(expected, actual);
            }
Example #4
0
            public void SortStringTest_aaaabbbbccccReturnabccbaabccba()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = "abccbaabccba";

                // act
                string input  = "aaaabbbbcccc";
                var    actual = LCSolution.SortString(input);

                // assert
                Assert.AreEqual(expected, actual);
            }
Example #5
0
            public void SortStringTest_ratReturnart()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = "art";

                // act
                string input  = "rat";
                var    actual = LCSolution.SortString(input);

                // assert
                Assert.AreEqual(expected, actual);
            }
            public void GetMaxClockTimeTest_8051Return1850()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = "18:50";

                // act
                int inNum  = 8051;
                var actual = LCSolution.GetMaxClockTime(inNum);

                // assert
                Assert.AreEqual(expected, actual);
            }
            public void GetMaxClockTimeTest_1234Return2341()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = "23:41";

                // act
                int inNum  = 1234;
                var actual = LCSolution.GetMaxClockTime(inNum);

                // assert
                Assert.AreEqual(expected, actual);
            }
            public void IsMonotonicTest_223ReturnTrue()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = true;

                // act
                int[] inArray = new int[] { 2, 2, 3 };
                var   actual  = LCSolution.IsMonotonic(inArray);

                // assert
                Assert.AreEqual(expected, actual);
            }
            public void IsMonotonicTest_132ReturnFalse()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = false;

                // act
                int[] inArray = new int[] { 1, 3, 2 };
                var   actual  = LCSolution.IsMonotonic(inArray);

                // assert
                Assert.AreEqual(expected, actual);
            }
Example #10
0
            public void SortStringTest_spoReturnops()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = "ops";

                // act
                string input  = "spo";
                var    actual = LCSolution.SortString(input);

                // assert
                Assert.AreEqual(expected, actual);
            }
            public void CalcDifferentIntegerCountTest_100Return1()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = 1;

                // act
                int inNum  = 100;
                var actual = LCSolution.CalcDifferentIntegerCount(inNum);

                // assert
                Assert.AreEqual(expected, actual);
            }
Example #12
0
            public void SortedSquares_732311Return49949121()
            {
                // arrange
                var LCSolution = new LCProgram();

                int[] outArray = new int[] { 4, 9, 9, 49, 121 };
                var   expected = true;

                // act
                int[] inArray     = new int[] { -7, -3, 2, 3, 11 };
                int[] actualArray = LCSolution.SortedSquares(inArray);
                var   actual      = System.Linq.Enumerable.SequenceEqual(outArray, actualArray);

                // assert
                Assert.AreEqual(expected, actual);
            }
            public void RecursionStringTest_223Return6s()
            {
                // arrange
                List <string> expectedList = new List <string> {
                    "223", "232", "223", "232", "322", "322"
                };
                var expected = String.Join(", ", expectedList.ToArray());

                // act
                string        inStr      = "223";
                List <string> actualList = LCProgram.RecursionString("", inStr, inStr.Length);
                var           actual     = String.Join(", ", actualList.ToArray());

                // assert
                Assert.AreEqual(expected, actual);
            }
            public void HasCycleTest_1posNeg1ReturnFalse()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = false;

                // act
                LCProgram.ListNode_141 node_0 = new LCProgram.ListNode_141(1);

                node_0.next = null;

                var actual = LCSolution.HasCycle(node_0);

                // assert
                Assert.AreEqual(expected, actual);
            }
Example #15
0
            public void SortedSquares_410310Return01916100()
            {
                // arrange
                var LCSolution = new LCProgram();

                int[] outArray = new int[] { 0, 1, 9, 16, 100 };
                var   expected = true;

                // act
                int[] inArray     = new int[] { -4, -1, 0, 3, 10 };
                int[] actualArray = LCSolution.SortedSquares(inArray);
                var   actual      = System.Linq.Enumerable.SequenceEqual(outArray, actualArray);

                // assert
                Assert.AreEqual(expected, actual);
            }
            public void MincostTicketsTest_Return11()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = 11;

                // act
                int[] days = new int[6] {
                    1, 4, 6, 7, 8, 20
                };
                int[] costs = new int[3] {
                    2, 7, 15
                };
                var actual = LCSolution.MincostTickets(days, costs);

                // assert
                Assert.AreEqual(expected, actual);
            }
            public void HasCycleTest_12pos0ReturnTrue()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = true;

                // act
                LCProgram.ListNode_141 node_0 = new LCProgram.ListNode_141(1);
                LCProgram.ListNode_141 node_1 = new LCProgram.ListNode_141(2);

                node_0.next = node_1;
                node_1.next = node_0;

                var actual = LCSolution.HasCycle(node_0);

                // assert
                Assert.AreEqual(expected, actual);
            }
            public void MincostTicketsTest_Return6()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = 6;

                // act
                int[] days = new int[12] {
                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 31
                };
                int[] costs = new int[3] {
                    7, 2, 15
                };
                var actual = LCSolution.MincostTickets(days, costs);

                // assert
                Assert.AreEqual(expected, actual);
            }
            public void HasCycleTest_320neg4pos1ReturnTrue()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = true;

                // act
                LCProgram.ListNode_141 node_0 = new LCProgram.ListNode_141(3);
                LCProgram.ListNode_141 node_1 = new LCProgram.ListNode_141(2);
                LCProgram.ListNode_141 node_2 = new LCProgram.ListNode_141(0);
                LCProgram.ListNode_141 node_3 = new LCProgram.ListNode_141(-4);

                node_0.next = node_1;
                node_1.next = node_2;
                node_2.next = node_3;
                node_3.next = node_1;

                var actual = LCSolution.HasCycle(node_0);

                // assert
                Assert.AreEqual(expected, actual);
            }
Example #20
0
            public void DeleteNodeTest_4519Del1Return459True()
            {
                // arrange
                var LCSolution = new LCProgram();
                var expected   = true;

                // act
                LCProgram.ListNode_TIQ_DelNode node_0 = new LCProgram.ListNode_TIQ_DelNode(4);
                LCProgram.ListNode_TIQ_DelNode node_1 = new LCProgram.ListNode_TIQ_DelNode(5);
                LCProgram.ListNode_TIQ_DelNode node_2 = new LCProgram.ListNode_TIQ_DelNode(1);
                LCProgram.ListNode_TIQ_DelNode node_3 = new LCProgram.ListNode_TIQ_DelNode(9);

                node_0.next = node_1;
                node_1.next = node_2;
                node_2.next = node_3;
                node_3.next = null;

                LCSolution.DeleteNode(node_2);

                string strAfter = string.Empty;
                var    curNode  = node_0;

                while (curNode.next != null)
                {
                    strAfter += curNode.val.ToString();
                    curNode   = curNode.next;
                }
                strAfter += curNode.val.ToString();         // Last node

                bool actual = false;

                if (strAfter.CompareTo("459") == 0)
                {
                    actual = true;
                }

                // assert
                Assert.AreEqual(expected, actual);
            }
Example #21
0
 public void attachProgram(LCProgram prog)
 {
     program = prog;
 }