Esempio n. 1
0
        public void WhenOneFullSet_AndTwoPartialSets_ThenTwoSets()
        {
            var books = new List <Book>()
            {
                new Book(1, "Book 1", priceOfOneBook),
                new Book(1, "Book 1", priceOfOneBook),
                new Book(2, "Book 2", priceOfOneBook),
                new Book(2, "Book 2", priceOfOneBook),
                new Book(3, "Book 3", priceOfOneBook),
                new Book(3, "Book 3", priceOfOneBook),
                new Book(4, "Book 4", priceOfOneBook),
                new Book(5, "Book 5", priceOfOneBook)
            };

            var splitterOptions = new SetSplitterOptions
            {
                MaximumSetSize = 100
            };

            var splitter = new SetSplitter(splitterOptions);

            var result = splitter.Split(books);

            Assert.AreEqual(2, result.Count);
        }
Esempio n. 2
0
        private Array GetUniqueTerms(Array values)
        {
            HashSet <ByteBlock> uniqueValues = new HashSet <ByteBlock>();

            // Get every unique word split from every value in the array
            SetSplitter s = new SetSplitter();

            for (int i = 0; i < values.Length; ++i)
            {
                ByteBlock value = (ByteBlock)values.GetValue(i);
                foreach (Range r in s.Split(value).Ranges)
                {
                    if (r.Length > 0)
                    {
                        uniqueValues.Add(new ByteBlock(value.Array, r.Index, r.Length));
                    }
                }
            }

            // Convert the result to an array
            ByteBlock[] result = new ByteBlock[uniqueValues.Count];
            int         j      = 0;

            foreach (ByteBlock value in uniqueValues)
            {
                result[j] = value;
                j++;
            }

            return(result);
        }
Esempio n. 3
0
        public void WhenThreeDifferentBooks_ThenOneSet()
        {
            var books = new List <Book>()
            {
                new Book(1, "Book 1", priceOfOneBook),
                new Book(2, "Book 2", priceOfOneBook),
                new Book(3, "Book 3", priceOfOneBook)
            };

            var splitterOptions = new SetSplitterOptions
            {
                MaximumSetSize = 100
            };

            var splitter = new SetSplitter(splitterOptions);
            var result   = splitter.Split(books);

            Assert.AreEqual(1, result.Count);
        }
Esempio n. 4
0
        public void WithBoundedSetSizeOf1_ThenThreeDifferentBooks_IsThreeDifferentSets(int setSize, int expectedSplitCount)
        {
            var books = new List <Book>()
            {
                new Book(1, "Book 1", priceOfOneBook),
                new Book(2, "Book 2", priceOfOneBook),
                new Book(3, "Book 3", priceOfOneBook),
                new Book(4, "Book 4", priceOfOneBook),
                new Book(5, "Book 5", priceOfOneBook)
            };

            var splitterOptions = new SetSplitterOptions
            {
                MaximumSetSize = setSize
            };

            var splitter = new SetSplitter(splitterOptions);
            var result   = splitter.Split(books);

            Assert.AreEqual(expectedSplitCount, result.Count);
        }