Esempio n. 1
0
        public void GetMajorityElement_Test()
        {
            int[] input = new int[] { 1, 15, 99, 84, 5, 15 };
            //array içerisinde en çok bulunan değer 15 oluduğu için 15 dönmeli,  bu tür turumlarda dictinary kullanabiliriz
            int value1 = ArrayAlgorithms.GetMajorityElement(input);

            Assert.True(value1 == 15);
        }
Esempio n. 2
0
        public void FindMax_EmptyArray_Success()
        {
            ArrayAlgorithms arrayAlg = new ArrayAlgorithms();

            int[] array    = { };
            int   response = arrayAlg.FindMax(array);

            Assert.AreEqual(-1, response);
        }
Esempio n. 3
0
        public void FindMaxCompareToAll_ManyElements_Success()
        {
            ArrayAlgorithms arrayAlg = new ArrayAlgorithms();

            int[] array    = { 2, 5, 6, 6 };
            int   response = arrayAlg.FindMaxCompareToAll(array);

            Assert.AreEqual(6, response);
        }
Esempio n. 4
0
        public void FindMaxCompareToAll_OneElement_Success()
        {
            ArrayAlgorithms arrayAlg = new ArrayAlgorithms();

            int[] array    = { 2 };
            int   response = arrayAlg.FindMaxCompareToAll(array);

            Assert.AreEqual(2, response);
        }
Esempio n. 5
0
        public void FindMaxCompareToAll_NullArray_Success()
        {
            ArrayAlgorithms arrayAlg = new ArrayAlgorithms();

            int[] array    = null;
            int   response = arrayAlg.FindMaxCompareToAll(array);

            Assert.AreEqual(-1, response);
        }
Esempio n. 6
0
        public void TwoIntegersSumToTarget_Test()
        {
            int[] input = new int[] { 1, 15, 99, 84 };

            //84 + 15 = 99 => return true
            bool value1 = ArrayAlgorithms.TwoIntegersSumToTarget(input, target: 99);

            Assert.True(value1);
        }
        public void ArrayAlgorithms_Replace0With5_Input_102_Output_ShouldBe_152_Test()
        {
            // Arrange
            var input = 102;

            // Act
            var output = ArrayAlgorithms.Replace0With5InIntegerValue(input);

            // Assert
            Assert.AreEqual(152, output);
        }
        public void ArrayAlgorithms_FindMissingElementUsingXOR_Should_Return_Missing_Element()
        {
            // Arrange
            var input = new int[] { 1, 4, 0, 3, 2, 7, 6 };

            // Act
            var output = ArrayAlgorithms.FindMissingNumberUsingXOR(input);

            // Assert

            Assert.AreEqual(5, output);
        }
        public void ArrayAlgorithms_FindNonRepeatedElementsUsingMap_No_Missing_Elements_Should_Return_Minus_1()
        {
            // Arrange
            var input = new int[] { 1, 7, 2, 6, 2, 7, 6, 1 };

            // Act
            var output = ArrayAlgorithms.FindNonRepeatedElementUsingMap(input);

            // Assert

            Assert.AreEqual(-1, output);
        }
Esempio n. 10
0
        public void RotateArrayRight_Test()
        {
            int[] input = new int[] { 1, 5, 3, 6, 7, 8, 9, 11, 12 };

            int[] value1 = ArrayAlgorithms.RotateArrayRight(input, pivot: 4);

            int[] expectedOutput = new int[] { 7, 8, 9, 11, 12, 1, 5, 3, 6 };

            bool isEqual = Enumerable.SequenceEqual(expectedOutput, value1);

            Assert.True(isEqual);
        }
        public void ArrayAlgorithms_PrintMatrixInSpiralForm_Test()
        {
            // Arrange
            var input = new int[, ]
            {
                { 1, 2, 3, 4, 5 },
                { 6, 7, 8, 9, 10 },
                { 11, 12, 13, 14, 15 }
            };

            // Act
            ArrayAlgorithms.PrintMatrixInSpiralForm(input);
        }
Esempio n. 12
0
        public void MinMaxArraySwap_Test()
        {
            int[] input = new int[] { 1, 15, 99, 84, 5, 15 };

            //en küçün değer olan 1 ile en büyük değer olan 99'un yerlerini değiştiriyoruz
            int[] value1 = ArrayAlgorithms.MinMaxArraySwap(input);

            int[] expectedOutput = new int[] { 99, 15, 1, 84, 5, 15 };

            bool isEqual = Enumerable.SequenceEqual(expectedOutput, value1);

            Assert.True(isEqual);
        }
        public void ArrayAlgorithms_FindCombinationSuchThatPHValueIsNeutralized_Test()
        {
            // Arrange
            var input = new PhValue[] { new PhValue()
                                        {
                                            Element = "CA", Value = -3
                                        }, new PhValue()
                                        {
                                            Element = "AR", Value = 3
                                        }, new PhValue()
                                        {
                                            Element = "MN", Value = 6
                                        }, new PhValue()
                                        {
                                            Element = "PD", Value = 8
                                        } };

            // Act
            ArrayAlgorithms.FindCombinationSuchThatPHValueIsNeutralized(input);
        }
Esempio n. 14
0
 public void Init()
 {
     arrayAlgo = new ArrayAlgorithms();
 }