public void MethodTestGravaDados()
        {
            string path = Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory()));

            path = path.Replace("\\UnitTestProjeto\\bin", "");
            string strNameFile       = path + "\\ArquivoDados.txt";
            string strNameFileIndice = path + "\\ArquivoIndice.txt";

            List <ITweet> listaTweets = new List <ITweet>();
            Tweets        tweets      = new Tweets();

            listaTweets.AddRange(tweets.BuscarTweets("", "", "", "", "#RockBand"));

            Principal p = new Principal();

            p.strNameFile       = strNameFile;
            p.strNameFileIndice = strNameFileIndice;
            p.GravarDados(listaTweets);
            BinarySearchAlgorithm bsa    = new BinarySearchAlgorithm();
            StrFileIndice         objeto = new StrFileIndice();

            if (bsa.BinarySearchById(1170023482421325824, strNameFileIndice, ref objeto))
            {
                Assert.AreEqual(1170023482421325824, objeto.Id);
            }
        }
Beispiel #2
0
        public void BinarySearch_Null_ExpectedResults()
        {
            Number[] arr = { new Number(), new Number(1), new Number(2), new Number(3) };

            Number x = new Number(1);

            Assert.Throws <ArgumentNullException>(() => BinarySearchAlgorithm <Number> .BinarySearch(arr, x, null));
        }
Beispiel #3
0
        public void FilterArrayByKey_Number_ExpectedResults()
        {
            Number[] arr = { new Number(1), new Number(3), new Number(-1), new Number() };

            Array.Sort(arr, new Number());

            Number x = new Number(1);

            Assert.AreEqual(2, BinarySearchAlgorithm <Number> .BinarySearch(arr, x, new Number()));
        }
        public void BinarySearch_InvalidItem()
        {
            var array        = new[] { 1, 6, 12, 25, 90, 155, 255, 789, 1230, 1987, 90890 };
            var binarySearch = new BinarySearchAlgorithm(array);
            var validItem    = 55;

            var result = binarySearch.Search(validItem);

            Assert.Null(result);
        }
        public void BinarySearchRecursive_InvalidItem()
        {
            var array        = new[] { 1, 6, 12, 25, 90, 155, 255, 789, 1230, 1987, 90890 };
            var binarySearch = new BinarySearchAlgorithm(array);
            var invalidItem  = 55;

            var result = binarySearch.RecursiveSearch(invalidItem, 0, array.Length);

            Assert.Null(result);
        }
Beispiel #6
0
        public void BinarySearch_Point_ExpectedResults()
        {
            Point[] arr = { new Point(1, 2), new Point(3, 4), new Point(-1, -2), new Point(), new Point(1, 2) };

            Array.Sort(arr, Comparer <Point> .Default.Compare);


            Point x = new Point(1, 2);

            Assert.AreEqual(2, BinarySearchAlgorithm <Point> .BinarySearch(arr, x));
        }
        public void MethodTestBinarySearch()
        {
            string path = Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory()));

            path = path.Replace("\\UnitTestProjeto\\bin", "");
            string strNameFileIndice     = path + "\\ArquivoIndice.txt";
            BinarySearchAlgorithm bsa    = new BinarySearchAlgorithm();
            StrFileIndice         objeto = new StrFileIndice();

            if (bsa.BinarySearchById(1170023482421325824, strNameFileIndice, ref objeto))
            {
                Assert.AreEqual(1170023482421325824, objeto.Id);
            }
        }
        public void MethodTestEnderecoIndice()
        {
            string path = Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory()));

            path = path.Replace("\\UnitTestProjeto\\bin", "");
            string strNameFile       = path + "\\ArquivoDados.txt";
            string strNameFileIndice = path + "\\ArquivoIndice.txt";

            BinarySearchAlgorithm bsa    = new BinarySearchAlgorithm();
            StrFileIndice         objeto = new StrFileIndice();

            if (bsa.BinarySearchById(1170023482421325824, strNameFileIndice, ref objeto))
            {
                FileStream fsDados = new FileStream(strNameFile, FileMode.Open);
                fsDados.Seek(objeto.Posicao, SeekOrigin.Begin);
                StrFile oReturn = bsa.GetFileValue <StrFile>(fsDados);
                Assert.AreEqual(1170023482421325824, oReturn.Id);

                fsDados.Close();
                fsDados.Dispose();
            }
        }
Beispiel #9
0
 public FastThreeSum(int[] arr) : base(arr)
 {
     bs = new BinarySearchAlgorithm(arr);
 }
Beispiel #10
0
 public void BinarySearch_String_ExpectedResults(string[] array, string digit, int expected)
 {
     Assert.AreEqual(expected, BinarySearchAlgorithm <string> .BinarySearch(array, digit));
 }
Beispiel #11
0
 public void BinarySearch_Int_ExpectedResults(int[] array, int digit, int expected)
 {
     Assert.AreEqual(expected, BinarySearchAlgorithm <int> .BinarySearch(array, digit));
 }
 public void SearchTests_WithEmptyArray_ThrowArgumentException()
 => Assert.Throws <ArgumentException>(() => BinarySearchAlgorithm.Search(new int[0], 1));
 public void SearchTests_WithUnSortingArray_ThrowArgumentException()
 => Assert.Throws <ArgumentException>(() => BinarySearchAlgorithm.Search(new int[] { 5, 3, 1, 2, 4 }, 2));
 public int SearchTests_WithStringArray_ReturnIndex(string[] sourceArray, string value)
 {
     return(BinarySearchAlgorithm.Search(sourceArray, value));
 }
 public void SearchTests_WithNullArray_ThrowArgumentNullException()
 => Assert.Throws <ArgumentNullException>(() => BinarySearchAlgorithm.Search(null, 1));
 public int SearchTests_WithDouble_ReturnIndex(double[] source, double value)
 {
     return(BinarySearchAlgorithm.Search(source, value));
 }
 public int SearchTests_WithInt_ReturnIndex(int[] source, int value)
 {
     return(BinarySearchAlgorithm.Search(source, value));
 }
Beispiel #18
0
 public void Setup()
 {
     int[] sortedArray = new int[] { 10, 22, 31, 43, 56, 68, 79, 81, 92, 100 };
     bs = new BinarySearchAlgorithm(sortedArray);
 }
Beispiel #19
0
 public void Setup()
 {
     _sut = new BinarySearchAlgorithm();
 }
Beispiel #20
0
        private static void RandomExercises()
        {
            int[] numValues = { 8, 1, 2, 2, 3 };
            ArrayExercises.SmallerNumbersThanCurrent(numValues);

            int[] FirstDuplicate = { 2, 1, 3, 5, 3, 2 };
            Console.WriteLine(string.Format("{0} is the first duplicate.", ArrayExercises.FindFirstDuplicate(FirstDuplicate)));

            BinaryTree <int> MyTree = new BinaryTree <int>();

            MyTree.Insert(6);
            MyTree.Insert(7);
            MyTree.Insert(8);
            MyTree.Insert(2);
            MyTree.Insert(7);
            MyTree.Insert(1);
            MyTree.Insert(3);
            MyTree.Insert(9);
            MyTree.Insert(1);
            MyTree.Insert(4);
            MyTree.Insert(5);

            MyTree.SumEvenGrandparent(MyTree.Find(6));

            long           binary_val = 100100111000000;
            BitManipulator x          = new BitManipulator();

            Console.WriteLine(x.GetDecimalValue(binary_val));

            int[] luis = ManyExercises.BeautifulArray(4);

            int[] arri = { 1, 1, 2, 3, 3, 4, 4, 8, 8 };

            int UniqueVal = ManyExercises.SingleNonDuplicate(arri);

            if (UniqueVal > -1)
            {
                Console.WriteLine(string.Format("Unique value is {0}.", UniqueVal));
            }
            else
            {
                Console.WriteLine("No unique value is found in given array.");
            }

            Console.WriteLine("\n");
            string a = "kqep";
            string b = "pekeq";

            CustomSortString.SortString(a, b);

            int[] Pancakes = { 3, 2, 4, 1 };
            ArrayExercises.PancakeSort(Pancakes);

            // [[11,25,66,1,69,7],[23,55,17,45,15,52],[75,31,36,44,58,8],[22,27,33,25,68,4],[84,28,14,11,5,50]]
            int[][] matrix = new int[5][] { new int[] { 11, 25, 66, 1, 69, 7 }, new int[] { 23, 55, 17, 45, 15, 52 }, new int[] { 75, 31, 36, 44, 58, 8 }, new int[] { 22, 27, 33, 25, 68, 4 }, new int[] { 84, 28, 14, 11, 5, 50 } };

            Console.WriteLine("Original Matrix:");
            PrintMatrix(matrix);
            JaggedArray.DiagonalSort(matrix);
            Console.WriteLine("\nDiagonally Sorted Matrix:");
            PrintMatrix(matrix);
            Console.ReadLine();

            int[] arr = { 8, 3, 2, 7, 9, 1, 4, 1 };

            Console.WriteLine("\n");
            Console.WriteLine("Before SelectionSort:");
            foreach (int i in arr)
            {
                Console.Write(i + ",");
            }
            Console.ReadLine();
            SelectionSortAlgorithm.SelectionSort(arr);

            Console.WriteLine("\n");
            Console.WriteLine("After SelectionSort:");
            foreach (int i in arr)
            {
                Console.Write(i + ",");
            }
            Console.WriteLine("\n");
            Console.ReadLine();

            Console.Write("Binary Search. Enter number to search for: ");
            int.TryParse(Console.ReadLine(), out int key);
            BinarySearchAlgorithm.BinarySearch(arr, key);
            arr = Sorting();

            int[] G = { 1, 2, 3, 3, 4, 5 };
            Console.WriteLine(OneDimensionalArray.FindDuplicate(G));
            Console.ReadLine();

            int[] arrX1 = { 3, 4, -7, 1, 3, 3, 1, -4 };
            OneDimensionalArray.FindSubarrayForGivenSum(arrX1, 7);

            var y1 = new int[] { 3, 1, 7, 5, 4, 9, 2 };

            InsertionSortAlgorithm.InsertionSortBitWise(y1);
            PrintResults(y1);

            //ArrayExercises.StoreElementsInArray();
            var x1 = new int[] { 1, 2, 3 };
            var x2 = new int[] { 1, 2, 3 };

            ArrayExercises.MergeToArraysSameSizeSorted(x1, x2);


            LeetCode lc         = new LeetCode();
            var      groupSizes = new int[] { 3, 3, 3, 3, 3, 1, 3 };
            var      List111    = OneDimensionalArray.GroupThePeople(groupSizes);

            int[][] indices = new int[3][] { new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 } };
            lc.OddCells(2, 3, indices);
        }