Example #1
0
        static void FilterFrom(double from)
        {
            sb.Append("Ok: ");
            var testProduct = new Product("asd", "asd", from);

            var products = byPrice.RangeFrom(testProduct, true).Take(10);

            sb.AppendLine(string.Join(", ", products));
        }
Example #2
0
        private static void FilterByMinPrice(decimal minValue)
        {
            var minProduct       = new Product("random", minValue, "dawda");
            var filteredProducts = productsByPrice.RangeFrom(minProduct, true)
                                   .OrderBy(p => p.Price)
                                   .ThenBy(p => p.Name)
                                   .ThenBy(p => p.Type)
                                   .Take(10);

            if (filteredProducts.Count() > 0)
            {
                Console.WriteLine("Ok: {0}", string.Join(", ", filteredProducts));
            }
            else
            {
                Console.WriteLine("Ok:");
            }
        }
Example #3
0
        public void ListEvents(DateTime date, int count)
        {
            OrderedBag <Event> .VieweventsToShow = byDate.RangeFrom(new Event(date, "", ""), true);
            int showed = 0;

            foreach (var eventToShow in eventsToShow)
            {
                if (showed == count)
                {
                    break;
                }
                Messages.PrintEvent(eventToShow);
                showed++;
            }
            if (showed == 0)
            {
                Messages.NoEventsFound();
            }
        }
        public void ListEvents(DateTime date, int count)
        {
            Event startingEvent = new Event(date, "", "");

            OrderedBag <Event> .View eventsToDisplay = eventsByDate.RangeFrom(startingEvent, true);
            int countOfDisplayedEvents = 0;

            foreach (var eventToDisplay in eventsToDisplay)
            {
                if (countOfDisplayedEvents == count)
                {
                    break;
                }

                Messages.PrintEvent(eventToDisplay);
                countOfDisplayedEvents++;
            }

            if (countOfDisplayedEvents == 0)
            {
                Messages.NoEventsFound();
            }
        }
        private static string FilterByPriceFrom(string command)
        {
            var commandTokens = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            var result = new StringBuilder();

            result.Append("Ok: ");

            double fromPrice = double.Parse(commandTokens[4]);

            var product = new Product("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", fromPrice, "");

            var elements = sortedByPriceProducts.RangeFrom(product, true).ToArray();

            if (elements.Length > 0)
            {
                if (elements.Length >= 10)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        result.AppendFormat("{0}, ", elements[i].ToString());
                    }
                }
                else
                {
                    for (int i = 0; i < elements.Length; i++)
                    {
                        result.AppendFormat("{0}, ", elements[i].ToString());
                    }
                }

                result.Length -= 2;
            }

            return(result.ToString());
        }
Example #6
0
        static void Main()
        {
            // Testing priority queue
            var testQue = new PriorityQueue <int>();

            testQue.Enque(1);
            testQue.Enque(5);
            testQue.Enque(-87);
            testQue.Enque(67);
            testQue.Enque(98);
            testQue.Enque(6765);
            testQue.Enque(12);
            testQue.Enque(1);
            testQue.Enque(-2);
            testQue.Enque(-5);
            testQue.Enque(1);
            testQue.Enque(1);
            testQue.Enque(231);
            testQue.Enque(11);

            int numberOfEntries = testQue.Count;

            for (int i = 0; i < numberOfEntries - 1; i++)
            {
                Console.WriteLine(testQue.Dequeue());
            }


            // Testing products task
            OrderedBag <Product> tryBag = new OrderedBag <Product>();

            tryBag.Add(new Product("Mlqko", 55.76M));
            tryBag.Add(new Product("Hlqb", 56M));
            tryBag.Add(new Product("Maslo", .6M));
            tryBag.Add(new Product("Kroasan", 5.76M));
            tryBag.Add(new Product("Biskviti", 5.76M));
            tryBag.Add(new Product("Zele", 355.76M));
            tryBag.Add(new Product("Fystyci", 765.76M));
            tryBag.Add(new Product("Shokolad", 1.76M));

            var fromRangeProduct = new Product("test", 5m);

            var currentView = tryBag.RangeFrom(fromRangeProduct, true);

            foreach (var product in currentView)
            {
                Console.WriteLine("{0} has price of -> {1}", product.Name, product.Price);
            }

            // Test counting words
            string testText = "the ther the ther thir them t a m";

            string[] words   = testText.Split(' ');
            Trie     checkIt = new Trie();

            for (int i = 0; i < words.Count(); i++)
            {
                checkIt.Insert(words[i]);
            }

            var result = checkIt.CountWords();

            foreach (var pair in result)
            {
                Console.WriteLine("The word === {0} === can be found === {1} === times in the text", pair.Key, pair.Value);
            }
        }
Example #7
0
        static void Main()
        {
            // Testing priority queue
            var testQue = new PriorityQueue<int>();
            testQue.Enque(1);
            testQue.Enque(5);
            testQue.Enque(-87);
            testQue.Enque(67);
            testQue.Enque(98);
            testQue.Enque(6765);
            testQue.Enque(12);
            testQue.Enque(1);
            testQue.Enque(-2);
            testQue.Enque(-5);
            testQue.Enque(1);
            testQue.Enque(1);
            testQue.Enque(231);
            testQue.Enque(11);

            int numberOfEntries = testQue.Count;
            for (int i = 0; i < numberOfEntries -1; i++)
            {
                Console.WriteLine(testQue.Dequeue());
            }

            // Testing products task
            OrderedBag<Product> tryBag = new OrderedBag<Product>();
            tryBag.Add(new Product("Mlqko", 55.76M));
            tryBag.Add(new Product("Hlqb", 56M));
            tryBag.Add(new Product("Maslo", .6M));
            tryBag.Add(new Product("Kroasan", 5.76M));
            tryBag.Add(new Product("Biskviti", 5.76M));
            tryBag.Add(new Product("Zele", 355.76M));
            tryBag.Add(new Product("Fystyci", 765.76M));
            tryBag.Add(new Product("Shokolad", 1.76M));

            var fromRangeProduct = new Product("test", 5m);

            var currentView = tryBag.RangeFrom(fromRangeProduct, true);

            foreach (var product in currentView)
            {
                Console.WriteLine("{0} has price of -> {1}", product.Name, product.Price);
            }

            // Test counting words
            string testText = "the ther the ther thir them t a m";
            string[] words = testText.Split(' ');
            Trie checkIt = new Trie();
            for (int i = 0; i < words.Count(); i++)
            {
                checkIt.Insert(words[i]);
            }

            var result = checkIt.CountWords();

            foreach (var pair in result)
            {
                Console.WriteLine("The word === {0} === can be found === {1} === times in the text", pair.Key, pair.Value);
            }
        }