Beispiel #1
0
        public IFlexibleWordCountModel GetFlexibleCountModel(ISingleWordCountModel withQuotes, ISingleWordCountModel withoutQuotes)
        {
            if (withQuotes == withoutQuotes)
            {
                throw new ArgumentException("Please supply two different count models.");
            }
            if (withQuotes == null || withoutQuotes == null)
            {
                throw new ArgumentException("Array of counts must not be null.");
            }
            int withQuotesLength    = withQuotes.GetLength();
            int withoutQuotesLength = withoutQuotes.GetLength();

            if (withQuotesLength < 1 || withoutQuotesLength < 1)
            {
                throw new ArgumentException("Number of counts must not be less than 1.");
            }
            if (withQuotesLength != withoutQuotesLength)
            {
                throw new ArgumentException("The arrays must have the same length.");
            }
            for (int i = 0; i < withQuotesLength; i++)
            {
                if (withQuotes.GetAt(i) < 0 || withoutQuotes.GetAt(i) < 0)
                {
                    throw new ArgumentException($"Counts must not be negative. Item {i} in one of the arrays was negative.");
                }
            }
            return(new FlexibleWordCountModel(withQuotes, withoutQuotes));
        }
Beispiel #2
0
        private WordCount TranslateCounts(ISingleWordCountModel model)
        {
            if (model.GetLength() != UniversalConstants.CountSize)
            {
                throw new ArgumentException($"Please pass a model with length {UniversalConstants.CountSize}.");
            }
            WordCount output = new WordCount()
            {
                One      = model.GetAt(0),
                Two      = model.GetAt(1),
                Three    = model.GetAt(2),
                Four     = model.GetAt(3),
                Five     = model.GetAt(4),
                Six      = model.GetAt(5),
                Seven    = model.GetAt(6),
                Eight    = model.GetAt(7),
                Nine     = model.GetAt(8),
                Ten      = model.GetAt(9),
                Eleven   = model.GetAt(10),
                Twelve   = model.GetAt(11),
                Thirteen = model.GetAt(12)
            };

            return(output);
        }
Beispiel #3
0
        public FlexibleWordCountModel(ISingleWordCountModel countsWithQuotes, ISingleWordCountModel countsWithoutQuotes)
        {
            if (countsWithQuotes == countsWithoutQuotes)
            {
                throw new ArgumentException("Please supply two different count models.");
            }
            if (countsWithQuotes == null || countsWithoutQuotes == null)
            {
                throw new ArgumentException("Array of counts must not be null.");
            }
            int withQuotesLength    = countsWithQuotes.GetLength();
            int withoutQuotesLength = countsWithoutQuotes.GetLength();

            if (withQuotesLength < 1 || withoutQuotesLength < 1)
            {
                throw new ArgumentException("The count collections must not have length zero.");
            }
            if (withQuotesLength != withoutQuotesLength)
            {
                throw new ArgumentException($"The count collections must have the same length.");
            }
            for (int i = 0; i < withQuotesLength; i++)
            {
                if (countsWithQuotes.GetAt(i) < 0 || countsWithoutQuotes.GetAt(i) < 0)
                {
                    throw new ArgumentException($"Counts must not be negative. Item {i} in one of the arrays was negative.");
                }
            }
            _length              = withQuotesLength;
            _countsWithQuotes    = countsWithQuotes.Copy();
            _countsWithoutQuotes = countsWithoutQuotes.Copy();
        }
Beispiel #4
0
 public GroupModel(string name, ISingleWordCountModel wordCountModel)
 {
     SetName(name);
     if (wordCountModel == null)
     {
         throw new ArgumentException("wordCountModel must not be null.");
     }
     for (int i = 0; i < wordCountModel.GetLength(); i++)
     {
         if (wordCountModel.GetAt(i) != 0)
         {
             throw new ArgumentException("wordCountModel must have counts all equal to zero upon initializing group.");
         }
     }
     _items    = new List <ITextOrGroupModel>();
     _counts   = wordCountModel.Copy();
     _length   = _counts.GetLength();
     _modified = true;
 }
        private void CompareTextModels(ITextModel model1, ITextModel model2)
        {
            Assert.AreEqual(model1.GetName(), model2.GetName());
            Assert.AreEqual(model1.GetAuthor(), model2.GetAuthor());
            Assert.AreEqual(model1.GetIncludeQuotes(), model2.GetIncludeQuotes());
            ISingleWordCountModel counts1        = model1.GetCounts();
            ISingleWordCountModel counts2        = model1.GetCounts();
            ISingleWordCountModel withQuotes1    = model1.GetCountsWithQuotes();
            ISingleWordCountModel withQuotes2    = model2.GetCountsWithQuotes();
            ISingleWordCountModel withoutQuotes1 = model1.GetCountsWithoutQuotes();
            ISingleWordCountModel withoutQuotes2 = model2.GetCountsWithoutQuotes();

            for (int i = 0; i < withQuotes1.GetLength(); i++)
            {
                Assert.AreEqual(counts1.GetAt(i), counts2.GetAt(i));
                Assert.AreEqual(withQuotes1.GetAt(i), withQuotes2.GetAt(i));
                Assert.AreEqual(withoutQuotes1.GetAt(i), withoutQuotes2.GetAt(i));
            }
            Assert.AreEqual(model1.GetLength(), model2.GetLength());
        }
        public void GetSingleCountsByLength()
        {
            ISingleWordCountModel output = _modelFactory.GetSingleCountModel(countSize);

            Assert.AreEqual(output.GetLength(), countSize);
        }