public void Test_Add_Two_Negative_Numbers()
        {
            Solution1 solution = new Solution1();
            int       Total    = solution.Add(-5, -5);

            Assert.AreEqual(-10, Total);
        }
Ejemplo n.º 2
0
        public void TestMethod7()
        {
            Solution1 s      = new Solution1();
            var       result = s.TilingRectangle(1, 1);

            Assert.AreEqual(result, 1);
        }
Ejemplo n.º 3
0
        private static int Solve1(string s)
        {
            var solution = new Solution1();
            var result   = solution.LengthOfLongestSubstring(s);

            return(result);
        }
        public override void Run()
        {
            var root = Create(0, 1, 2, 3, 4, 5, 6);

            BTreePrinter.Print(root);
            Console.WriteLine("Solution 1");
            var sol1   = new Solution1();
            var result = sol1.Convert(root);

            Display(result.Head);

            Console.WriteLine("Solution 2");
            root = Create(0, 1, 2, 3, 4, 5, 6);
            var sol2    = new Solution2();
            var result2 = sol2.Convert(root);

            Display(result2);

            Console.WriteLine("Solution 3");
            root = Create(0, 1, 2, 3, 4, 5, 6);
            var sol3    = new Solution3();
            var result3 = sol3.Convert(root);

            Display(result3);
        }
        public void Test_Add_Two_Sign_Numbers()
        {
            Solution1 solution = new Solution1();
            int       Total    = solution.Add(5, -5);

            Assert.AreEqual(0, Total);
        }
        public void Test_Add_Two_Different_Numbers()
        {
            Solution1 solution = new Solution1();
            int       Total    = solution.Add(5, 10);

            Assert.AreEqual(15, Total);
        }
Ejemplo n.º 7
0
        public void TestMethod9()
        {
            Solution1 s = new Solution1();

            for (int i = 1; i <= 13; i++)
            {
                var result = s.TilingRectangle(i, i);
                Assert.AreEqual(result, 1);
            }
        }
Ejemplo n.º 8
0
        private static void PrintResults1(Solution1 calcResults, bool isTest)
        {
            string testMessage = isTest ? "*** TEST ***  " : String.Empty;

            Console.WriteLine($@"
--------------------------------------");
            PrintMessageInColour($"[INFO] {testMessage}Results of Challenge 01:", ConsoleColor.Cyan, true);
            Console.WriteLine($@"[INFO] {testMessage}CountValid: {calcResults.CountValid}
--------------------------------------");
        }
Ejemplo n.º 9
0
        public void Problem1_WhenPassedInuptHasOnly1Element_ShouldReturnFalse()
        {
            var sut = new Solution1();

            int[] input = new int[] { 10 };

            var result = sut.Solve(input, 10);

            Assert.AreEqual(false, result);
        }
Ejemplo n.º 10
0
        public void Problem1_WhenPassedInuptDoesNotHaveSumK_ShouldReturnFalse()
        {
            var sut = new Solution1();

            int[] input = new int[] { 10, 20, 30, 40 };

            var result = sut.Solve(input, 100);

            Assert.AreEqual(false, result);
        }
Ejemplo n.º 11
0
        public void Problem1_WhenPassedInuptHasSumK_ShouldReturnTrue()
        {
            var sut = new Solution1();

            int[] input = new int[] { 10, 20, 30, 40 };

            var result = sut.Solve(input, 30);

            Assert.AreEqual(true, result);
        }
Ejemplo n.º 12
0
        public void Problem1_WhenPassedInuptHasOnly2Element_ShouldReturnTrueIfSumIsK()
        {
            var sut = new Solution1();

            int[] input = new int[] { 10, 20 };

            var result = sut.Solve(input, 30);

            Assert.AreEqual(true, result);
        }
Ejemplo n.º 13
0
        public void CreateBackground(string nums)
        {
            _sol = new Solution1();
            List <int> temp = new List <int>();

            foreach (string num in nums.Trim().Split(','))
            {
                temp.Add(int.Parse(num));
            }
            _sol._nums = temp.ToArray();
        }
Ejemplo n.º 14
0
        public static void PrintResults(Solution1 calcResults, bool isTest = false)
        {
            Solution2?results = calcResults as Solution2;

            if (results is null)
            {
                PrintResults1(calcResults, isTest);
            }
            else
            {
                PrintResults2(results, isTest);
            }
        }
Ejemplo n.º 15
0
        public static void PrintResults(Solution1 calcResults)
        {
            Solution2?results = calcResults as Solution2;

            if (results is null)
            {
                PrintResults1(calcResults);
            }
            else
            {
                PrintResults2(results);
            }
        }
Ejemplo n.º 16
0
        public WriteTest()
        {
            _memory        = new MemoryStream(4096);
            _buffer_memory = new BufferedStream(new MemoryStream(4096));
            _solution1     = new Solution1();
            _solution2     = new Solution2();
            MemoryMappedFile mmf = MemoryMappedFile.CreateNew("testmap", 4096);

            _mmvs   = mmf.CreateViewStream();
            _buffer = Encoding.UTF8.GetBytes(@"24242424224242424242423sfdv4242424224242424242423sfd_ + ER$#$#$#$242424242
sf + _ + _#$@#4$+_+_+_+_+ER$#$#$#$24242424242423sfdsf+_+_#$@#4$+_+_+_+_+ER$#$#$#$_+ER$#$#$#$24242424242423sfdsf+_+_#$@#4$+_+_+_+_+E
_ + ER$#$#$#$24242424242423sfdsf+_+_#$@#4$+_+_+_+_+E_+ER$#$#$#$24242424242423sfdsf+_+_#$@#4$+_+_+_+_+E_+ER$#$+E
24242424242423sfdsf + _ + _#$@#4$+_+_+_+_+ER$#$#$#$24242424242423sfdsf+_+_#$@#4$+_+_+_+_+ER$#$#$#$242424242424$#$#$#$42423sfdsf+_+_#$@#4$+_+_+_+_+ER$#$#$#$24242424242423sfdsf+_+_#$@#4$+_+_+_+_+ER$#$#$#$");
        }
Ejemplo n.º 17
0
        private static void PrintResults1(Solution1 calcResults)
        {
            Console.WriteLine($@"
--------------------------------------
[INFO] Results of Challenge 01:
--------------------------------------
[INFO] Number 1: {calcResults.Number1}
[INFO] Number 1: {calcResults.Number2}
[INFO] Sum     : {calcResults.Sum}
[INFO] Multiply: {calcResults.Multiplied}
--------------------------------------

");
        }
Ejemplo n.º 18
0
        public void SolutionOne_VerifyAllCartIds()
        {
            Solution1 sol1 = new Solution1();

            sol1.run();

            JsonInputObject  input  = sol1.input;
            JsonOutputObject result = sol1.output;

            foreach (Cart inputCart in input.carts)
            {
                Assert.IsTrue(result.carts.Exists(x => x.id == inputCart.id));
            }

            Assert.IsFalse(result.carts.Exists(x => x.id == 999));
        }
Ejemplo n.º 19
0
        public void SolutionOne_CompareResultsWithExpected()
        {
            Solution1 sol1 = new Solution1();

            sol1.run();

            JsonOutputObject actualJsonOutput   = sol1.output;
            JsonOutputObject expectedJsonOutput = sol1.LoadExpectedOutput();


            for (int i = 0; i < actualJsonOutput.carts.Count; i++)
            {
                Assert.AreEqual(actualJsonOutput.carts[i].id, expectedJsonOutput.carts[i].id);
                Assert.AreEqual(actualJsonOutput.carts[i].total, expectedJsonOutput.carts[i].total);
            }
        }
Ejemplo n.º 20
0
        static void Main(string[] args)
        {
            try
            {
                Solution1 sol1 = new Solution1();
                sol1.run();
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("Level 1 ERROR: {0}", ex.Message));
            }
            finally
            {
                Console.WriteLine("Level 1 solved successfully");
            }

            try
            {
                Solution2 sol2 = new Solution2();
                sol2.run();
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("Level 2 ERROR: {0}", ex.Message));
            }
            finally
            {
                Console.WriteLine("Level 2 solved successfully");
            }

            try
            {
                Solution3 sol3 = new Solution3();
                sol3.run();
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("Level 3 ERROR: {0}", ex.Message));
            }
            finally
            {
                Console.WriteLine("Level 3 solved successfully");
            }
        }
        static void Main(string[] args)
        {
            bool pass;

            do
            {
                Console.Write("Please choose a soloution you would like to run\n\nCheck the project readme file for details on each solution!" +
                              "\nSolution1 = 1\nSolution2 = 2\n\nSolution3/noInput!\n\nInput:");

                string input = Console.ReadLine();

                pass = true;


                if (input == "1")
                {
                    pass = true;
                    var solution1 = new Solution1(); //Instantiate My class for Solution1
                    solution1.RunSolution1();        //Calls a Method from the Solution1 class
                }
                else if (input == "2")
                {
                    pass = true;
                    var solution2 = new Solution2(); //Instantiate My class for Solution2
                    solution2.RunSolution2();        //Calls a Method from the Solution2 class
                }
                else if (input == "3")
                {
                    pass = true;
                    var solution3 = new Solution3(); //Instantiate My class for Solution3
                    solution3.RunSolution3();        //Calls a Method from the Solution3 class
                }
                else
                {
                    Console.WriteLine("Invalid Input");
                    pass = false;
                    Console.ReadLine();
                }

                Console.Clear();
            } while (pass == false);
        }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            FormattedOutput.PrintOpening();

            var input = new FormattedInput(HardCodedConfig.InputFilePath);

            FormattedOutput.PrintInputs(input);

            var results1 = new Solution1();

            results1.Calc(input.ParsedInput);
            FormattedOutput.PrintResults(results1);

            if (HardCodedConfig.Challenge2)
            {
                var results2 = new Solution2();
                results2.Calc(input.ParsedInput);
                FormattedOutput.PrintResults(results2);
            }
        }
        public void GetFirstCommonAncestorTest()
        {
            Solution <int> solution1 = new Solution1 <int>();
            Solution <int> solution2 = new Solution2 <int>();
            var            tree      = CreateTree();


            var p = tree.Root;              // Node 50
            var q = tree.Root.Left;         // Node 20
            var expectedResult = tree.Root; // Node 50

            RunTest(solution1, tree.Root, p, q, expectedResult);
            RunTest(solution2, tree.Root, p, q, expectedResult);

            p = tree.Root.Left;         // Node 20
            q = tree.Root.Right;        // Node 60
            expectedResult = tree.Root; // Node 50

            RunTest(solution1, tree.Root, p, q, expectedResult);
            RunTest(solution2, tree.Root, p, q, expectedResult);

            p = tree.Root.Left.Left.Left;         // Node 5
            q = tree.Root.Left.Left;              // Node 10
            expectedResult = tree.Root.Left.Left; // Node 10

            RunTest(solution1, tree.Root, p, q, expectedResult);
            RunTest(solution2, tree.Root, p, q, expectedResult);

            p = tree.Root.Left.Left.Left;    // Node 5
            q = tree.Root.Left.Right;        // Node 25
            expectedResult = tree.Root.Left; // Node 20

            RunTest(solution1, tree.Root, p, q, expectedResult);
            RunTest(solution2, tree.Root, p, q, expectedResult);

            p = tree.Root.Left.Left.Left;   // Node 5
            q = tree.Root.Right.Right.Left; // Node 65
            expectedResult = tree.Root;     // Node 50

            RunTest(solution1, tree.Root, p, q, expectedResult);
            RunTest(solution2, tree.Root, p, q, expectedResult);

            p = tree.Root.Right.Right;        // Node 70
            q = tree.Root.Right;              // Node 60
            expectedResult = tree.Root.Right; // Node 60

            RunTest(solution1, tree.Root, p, q, expectedResult);
            RunTest(solution2, tree.Root, p, q, expectedResult);

            p = new Tree <int> .Node(100); // a node that is not in the tree

            q = tree.Root.Left.Left;
            expectedResult = null;

            RunTest(solution1, tree.Root, p, q, expectedResult);
            RunTest(solution2, tree.Root, p, q, expectedResult);

            // Same node
            p = tree.Root.Right.Right;
            q = p;
            expectedResult = p;

            RunTest(solution1, tree.Root, p, q, expectedResult);
            RunTest(solution2, tree.Root, p, q, expectedResult);
        }
Ejemplo n.º 24
0
 static void Main(string[] args)
 {
     Console.WriteLine("Solution of day1:");
     Solution1.Day1();
 }
Ejemplo n.º 25
0
 public static void PrintResults(Solution1 calcResults, bool isTest = false)
 {
     if (calcResults is not Solution2 results)
     {
         PrintResults1(calcResults, isTest);
     }
Ejemplo n.º 26
0
 public void Setup()
 {
     solver = new Solution1();
 }
Ejemplo n.º 27
0
        static void Main(string[] args)
        {
            #region Q5
            string q51 = new Solution5().LongestPalindrome("babad");
            Console.WriteLine(q51);
            string q52 = new Solution5().LongestPalindrome("cbbd");
            Console.WriteLine(q52);
            string q53 = new Solution5().LongestPalindrome("ccd");
            Console.WriteLine(q53);
            string q54 = new Solution5().LongestPalindrome("aacdefcaa");
            Console.WriteLine(q54);
            string q55 = new Solution5().LongestPalindrome("a");
            Console.WriteLine(q55);
            string q56 = new Solution5().LongestPalindrome("aa");
            Console.WriteLine(q56);
            string q57 = new Solution5().LongestPalindrome("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            Console.WriteLine(q57);
            #endregion

            #region Q4
            var q41 = new Solution4().FindMedianSortedArrays(new[] { 1, 3 }, new[] { 2 });
            Console.WriteLine("OK");
            var q42 = new Solution4().FindMedianSortedArrays(new[] { 1, 3 }, new[] { 2, 4 });
            Console.WriteLine("OK");
            #endregion

            #region Q3
            var q30 = new Solution3().LengthOfLongestSubstring("abcabcbb");
            Console.WriteLine(q30);
            var q31 = new Solution3().LengthOfLongestSubstring("bbbbb");
            Console.WriteLine(q31);
            var q32 = new Solution3().LengthOfLongestSubstring("pwwkew");
            Console.WriteLine(q32);
            var q33 = new Solution3().LengthOfLongestSubstring("jlygy");
            Console.WriteLine(q33);
            #endregion

            #region Q2
            var x = new Solution2.ListNode(2)
            {
                next = new Solution2.ListNode(4)
                {
                    next = new Solution2.ListNode(3)
                }
            };

            var y = new Solution2.ListNode(5)
            {
                next = new Solution2.ListNode(6)
                {
                    next = new Solution2.ListNode(4)
                }
            };

            var x1 = new Solution2.ListNode(9);
            var y1 = new Solution2.ListNode(1)
            {
                next = new Solution2.ListNode(9)
                {
                    next = new Solution2.ListNode(9)
                }
            };

            var q2 = new Solution2().AddTwoNumbers(x1, y1);
            Console.Write("ok");
            #endregion

            #region Q1
            var q1 = new Solution1().TwoSum(new[] { 5, 75, 25 }, 100);
            Console.WriteLine(q1);
            #endregion
        }