public void GetCountsWithQuotes() { model.SetIncludeQuotes(true); ISingleWordCountModel counts = model.GetCounts(); Assert.AreEqual(counts.GetAt(3), 4); }
public void TestCopy() { ISingleWordCountModel copy = singleWordCountModel.Copy(); Assert.AreEqual(copy.GetAt(0), singleWordCountModel.GetAt(0)); Assert.AreEqual(copy.GetAt(1), singleWordCountModel.GetAt(1)); Assert.AreEqual(copy.GetAt(2), singleWordCountModel.GetAt(2)); Assert.AreEqual(copy.GetAt(3), singleWordCountModel.GetAt(3)); Assert.AreEqual(copy.GetAt(4), singleWordCountModel.GetAt(4)); }
public void CountOneText() { groupOne.Add(textOne); ISingleWordCountModel counts = groupOne.GetCounts(); Assert.AreEqual(1, counts.GetAt(0)); Assert.AreEqual(2, counts.GetAt(1)); Assert.AreEqual(3, counts.GetAt(2)); Assert.AreEqual(4, counts.GetAt(3)); Assert.AreEqual(5, counts.GetAt(4)); }
public void CountTwoTexts() { groupOne.Add(textOne); groupOne.Add(textTwo); ISingleWordCountModel counts = groupOne.GetCounts(); Assert.AreEqual(4, counts.GetAt(0)); Assert.AreEqual(5, counts.GetAt(1)); Assert.AreEqual(6, counts.GetAt(2)); Assert.AreEqual(7, counts.GetAt(3)); Assert.AreEqual(8, counts.GetAt(4)); }
public void Initialize() { _modelFactory = new ModelFactory(); int[] countsWithQuotes = new int[] { 0, 3, 1, 4, 2, 5 }; int[] countsWithoutQuotes = new int[] { 6, 9, 7, 10, 8, 11 }; ISingleWordCountModel withQuotes = _modelFactory.GetSingleCountModel(countsWithQuotes); ISingleWordCountModel withoutQuotes = _modelFactory.GetSingleCountModel(countsWithoutQuotes); wordCountModel = _modelFactory.GetFlexibleCountModel(withQuotes, withoutQuotes); nullWordCountModel = null; model = new TextModel("model", wordCountModel); }
private IFlexibleWordCountModel GetCountsFromText(Text text) { WordCount withQuotes = _db.WordCounts.FirstOrDefault(x => x.Id == text.WithQuotesId); WordCount withoutQuotes = _db.WordCounts.FirstOrDefault(x => x.Id == text.WithoutQuotesId); if (withQuotes == null || withoutQuotes == null) { throw new ArgumentException("One of the Counts entities is missing."); } ISingleWordCountModel withQuotesModel = TranslateCounts(withQuotes); ISingleWordCountModel withoutQuotesModel = TranslateCounts(withoutQuotes); return(_modelFactory.GetFlexibleCountModel(withQuotesModel, withoutQuotesModel)); }
private void executeAnalysisButton_Click(object sender, EventArgs e) { //if (_analysisController.GetActiveItems().Count > 0) if (_activeItemNames.Count > 0) { try { dataTable.Rows.Clear(); //clear any previous analysis analysisLineChart.Series.Clear(); //List<ITextOrGroupViewModel> groupList = _analysisController.GetActiveItems(); //gets any texts/groups that have been added to the analysis group List <ITextOrGroupViewModel> groupList = GetActiveItems(); //gets any texts/groups that have been added to the analysis group foreach (ITextOrGroupViewModel groupEntry in groupList) { //table int rowId = dataTable.Rows.Add(); //new row created to make sure formatting in present DataGridViewRow row = dataTable.Rows[rowId]; //assigns the new row to be worked on ISingleWordCountModel model = groupEntry.GetCounts(); row.Cells[0].Value = groupEntry.GetName(); //name of group placed in the first cell of the datatable for (int i = 0; i < groupEntry.GetLength(); i++) { row.Cells[i + 1].Value = model.GetAt(i); //assigning all of the counts to cells } //graph analysisLineChart.Series.Add(groupEntry.GetName()); // add the name of the series analysisLineChart.Series[groupEntry.GetName()].ChartType = SeriesChartType.Line; // assign chart type for (int i = 1; i <= UniversalConstants.CountSize; i++) { analysisLineChart.Series[groupEntry.GetName()].Points.AddXY(i, model.GetAt(i - 1)); // assigning all of the xy points on the chart } analysisLineChart.Series[groupEntry.GetName()].ChartArea = "Analysis Chart"; //neccesary so that the chart has a location for the series analysisLineChart.Series[groupEntry.GetName()].BorderWidth = 3; analysisLineChart.Series[groupEntry.GetName()].BorderDashStyle = ChartDashStyle.Solid; } tabControl1.SelectTab(analysisTab); //move to analysis page this.WindowState = FormWindowState.Maximized; //maximize page size so that whole chart can be seen } catch { string errorMessage = "You need to add groups to be analyzed"; var form2 = new ErrorMessageDisplay(errorMessage); form2.Show(this); } } else { string errorMessage = "There are no groups or texts being analyzed. Please add a text or group before executing."; var form2 = new ErrorMessageDisplay(errorMessage); form2.Show(this); } }
public void CountOneGroupOneFile() { groupOne.Add(textOne); groupOne.Add(textTwo); groupTwo.Add(groupOne); groupTwo.Add(textThree); ISingleWordCountModel counts = groupTwo.GetCounts(); Assert.AreEqual(52, counts.GetAt(0)); Assert.AreEqual(53, counts.GetAt(1)); Assert.AreEqual(54, counts.GetAt(2)); Assert.AreEqual(55, counts.GetAt(3)); Assert.AreEqual(56, counts.GetAt(4)); }
public void DeleteFromChild() { groupOne.Add(textOne); groupOne.Add(textTwo); groupTwo.Add(groupOne); ISingleWordCountModel counts = groupTwo.GetCounts(); groupOne.Remove(textTwo); counts = groupTwo.GetCounts(); Assert.AreEqual(1, counts.GetAt(0)); Assert.AreEqual(2, counts.GetAt(1)); Assert.AreEqual(3, counts.GetAt(2)); Assert.AreEqual(4, counts.GetAt(3)); Assert.AreEqual(5, counts.GetAt(4)); }
public void Initialize() { _modelFactory = new ModelFactory(); int[] countsOne = new int[] { 1, 2, 3, 4, 5 }; singleCountIncludeQuotes = _modelFactory.GetSingleCountModel(countsOne); int[] countsTwo = new int[] { 1, 14, 3, 28, 5 }; singleCountExcludeQuotes = _modelFactory.GetSingleCountModel(countsTwo); singleCountNull = null; int[] countsLengthOne = new int[] { 55 }; singleCountLengthOne = _modelFactory.GetSingleCountModel(countsLengthOne); int[] countsLengthZeroA = new int[0]; singleCountLengthZeroA = new FakeSingleWordCountModel(countsLengthZeroA); int[] countsLengthZeroB = new int[0]; singleCountLengthZeroB = new FakeSingleWordCountModel(countsLengthZeroB); int[] countsWithNegative = new int[] { 1, -2, 3, 4, 5 }; singleCountNegativeCount = new FakeSingleWordCountModel(countsWithNegative); flexibleWordCountModel = _modelFactory.GetFlexibleCountModel(singleCountIncludeQuotes, singleCountExcludeQuotes); }
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 ISingleWordCountModel TranslateCounts(WordCount count) { ISingleWordCountModel output = _modelFactory.GetSingleCountModel(UniversalConstants.CountSize); output.SetAt(0, (int)count.One); output.SetAt(1, (int)count.Two); output.SetAt(2, (int)count.Three); output.SetAt(3, (int)count.Four); output.SetAt(4, (int)count.Five); output.SetAt(5, (int)count.Six); output.SetAt(6, (int)count.Seven); output.SetAt(7, (int)count.Eight); output.SetAt(8, (int)count.Nine); output.SetAt(9, (int)count.Ten); output.SetAt(10, (int)count.Eleven); output.SetAt(11, (int)count.Twelve); output.SetAt(12, (int)count.Thirteen); return(output); }
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 CountWordAcrossLinesFromFile() { using (streamReader = new StreamReader("..\\..\\SampleTextFiles\\WordSpanningMultipleLines.txt")) { var textModel = _modelFactory.GetTextModel("test", streamReader, countSize); counts = textModel.GetCounts(); Assert.AreEqual(getFreq(1, 14), counts.GetAt(0)); Assert.AreEqual(getFreq(2, 14), counts.GetAt(1)); Assert.AreEqual(getFreq(2, 14), counts.GetAt(2)); Assert.AreEqual(getFreq(2, 14), counts.GetAt(3)); Assert.AreEqual(getFreq(1, 14), counts.GetAt(4)); Assert.AreEqual(getFreq(1, 14), counts.GetAt(5)); Assert.AreEqual(getFreq(1, 14), counts.GetAt(6)); Assert.AreEqual(getFreq(3, 14), counts.GetAt(7)); Assert.AreEqual(getFreq(1, 14), counts.GetAt(8)); Assert.AreEqual(0, counts.GetAt(9)); Assert.AreEqual(0, counts.GetAt(10)); Assert.AreEqual(0, counts.GetAt(11)); Assert.AreEqual(0, counts.GetAt(12)); } }
public void CountMismatchedQuotationMarks() { using (streamReader = new StreamReader("..\\..\\SampleTextFiles\\MismatchedQuotationMarks.txt")) { var textModel = _modelFactory.GetTextModel("test", streamReader, countSize); counts = textModel.GetCounts(); Assert.AreEqual(0, counts.GetAt(0)); Assert.AreEqual(0, counts.GetAt(1)); Assert.AreEqual(getFreq(1, 7), counts.GetAt(2)); Assert.AreEqual(getFreq(2, 7), counts.GetAt(3)); Assert.AreEqual(getFreq(2, 7), counts.GetAt(4)); Assert.AreEqual(0, counts.GetAt(5)); Assert.AreEqual(0, counts.GetAt(6)); Assert.AreEqual(0, counts.GetAt(7)); Assert.AreEqual(getFreq(1, 7), counts.GetAt(8)); Assert.AreEqual(getFreq(1, 7), counts.GetAt(9)); Assert.AreEqual(0, counts.GetAt(10)); Assert.AreEqual(0, counts.GetAt(11)); Assert.AreEqual(0, counts.GetAt(12)); } }
public void CountWithLineIncorrectlyEndingWithHyphen() { using (streamReader = new StreamReader("..\\..\\SampleTextFiles\\TheSleeperExcerpt.txt")) { var textModel = _modelFactory.GetTextModel("test", streamReader, countSize); counts = textModel.GetCounts(); Assert.AreEqual(0, counts.GetAt(0)); Assert.AreEqual(0, counts.GetAt(1)); Assert.AreEqual(getFreq(6, 15), counts.GetAt(2)); Assert.AreEqual(getFreq(4, 15), counts.GetAt(3)); Assert.AreEqual(getFreq(4, 15), counts.GetAt(4)); Assert.AreEqual(getFreq(1, 15), counts.GetAt(5)); Assert.AreEqual(0, counts.GetAt(6)); Assert.AreEqual(0, counts.GetAt(7)); Assert.AreEqual(0, counts.GetAt(8)); Assert.AreEqual(0, counts.GetAt(9)); Assert.AreEqual(0, counts.GetAt(10)); Assert.AreEqual(0, counts.GetAt(11)); Assert.AreEqual(0, counts.GetAt(12)); } }
public void CountWithLineIncorrectlyEndingWithHyphenInsideQuotes() { string s = "The general shouted, \"No-\nWe will not give them an inch."; stringReader = new StringReader(s); var textModel = _modelFactory.GetTextModel("test", stringReader, 13); counts = textModel.GetCounts(); Assert.AreEqual(0, counts.GetAt(0)); Assert.AreEqual(getFreq(3, 11), counts.GetAt(1)); Assert.AreEqual(getFreq(2, 11), counts.GetAt(2)); Assert.AreEqual(getFreq(4, 11), counts.GetAt(3)); Assert.AreEqual(0, counts.GetAt(4)); Assert.AreEqual(0, counts.GetAt(5)); Assert.AreEqual(getFreq(2, 11), counts.GetAt(6)); Assert.AreEqual(0, counts.GetAt(7)); Assert.AreEqual(0, counts.GetAt(8)); Assert.AreEqual(0, counts.GetAt(9)); Assert.AreEqual(0, counts.GetAt(10)); Assert.AreEqual(0, counts.GetAt(11)); Assert.AreEqual(0, counts.GetAt(12)); }
public void CountWordAcrossLines() { string s = "Let us consider a word spanning multip-\nle lines. Will the program handle it correctly?"; stringReader = new StringReader(s); var textModel = _modelFactory.GetTextModel("test", stringReader, countSize); counts = textModel.GetCounts(); Assert.AreEqual(getFreq(1, 14), counts.GetAt(0)); Assert.AreEqual(getFreq(2, 14), counts.GetAt(1)); Assert.AreEqual(getFreq(2, 14), counts.GetAt(2)); Assert.AreEqual(getFreq(2, 14), counts.GetAt(3)); Assert.AreEqual(getFreq(1, 14), counts.GetAt(4)); Assert.AreEqual(getFreq(1, 14), counts.GetAt(5)); Assert.AreEqual(getFreq(1, 14), counts.GetAt(6)); Assert.AreEqual(getFreq(3, 14), counts.GetAt(7)); Assert.AreEqual(getFreq(1, 14), counts.GetAt(8)); Assert.AreEqual(0, counts.GetAt(9)); Assert.AreEqual(0, counts.GetAt(10)); Assert.AreEqual(0, counts.GetAt(11)); Assert.AreEqual(0, counts.GetAt(12)); }
public void CountWithEmDashes() { string s = "So fitfully—so fearfully— So fitfully—so fearfully—"; stringReader = new StringReader(s); var textModel = _modelFactory.GetTextModel("test", stringReader, countSize); counts = textModel.GetCounts(); Assert.AreEqual(0, counts.GetAt(0)); Assert.AreEqual(getFreq(4, 8), counts.GetAt(1)); Assert.AreEqual(0, counts.GetAt(2)); Assert.AreEqual(0, counts.GetAt(3)); Assert.AreEqual(0, counts.GetAt(4)); Assert.AreEqual(0, counts.GetAt(5)); Assert.AreEqual(0, counts.GetAt(6)); Assert.AreEqual(getFreq(2, 8), counts.GetAt(7)); Assert.AreEqual(getFreq(2, 8), counts.GetAt(8)); Assert.AreEqual(0, counts.GetAt(9)); Assert.AreEqual(0, counts.GetAt(10)); Assert.AreEqual(0, counts.GetAt(11)); Assert.AreEqual(0, counts.GetAt(12)); }
public void CountIncludingQuotes() { string s = "As Thomas Jefferson once said, \"Hey there buddy.\""; stringReader = new StringReader(s); var textModel = _modelFactory.GetTextModel("test", stringReader, countSize); counts = textModel.GetCounts(); Assert.AreEqual(0, counts.GetAt(0)); Assert.AreEqual(getFreq(1, 8), counts.GetAt(1)); Assert.AreEqual(getFreq(1, 8), counts.GetAt(2)); Assert.AreEqual(getFreq(2, 8), counts.GetAt(3)); Assert.AreEqual(getFreq(2, 8), counts.GetAt(4)); Assert.AreEqual(getFreq(1, 8), counts.GetAt(5)); Assert.AreEqual(0, counts.GetAt(6)); Assert.AreEqual(0, counts.GetAt(7)); Assert.AreEqual(getFreq(1, 8), counts.GetAt(8)); Assert.AreEqual(0, counts.GetAt(9)); Assert.AreEqual(0, counts.GetAt(10)); Assert.AreEqual(0, counts.GetAt(11)); Assert.AreEqual(0, counts.GetAt(12)); }
public void Initialize() { _modelFactory = new ModelFactory(); var countsOne = new int[] { 1, 2, 3, 4, 5 }; var countsTwo = new int[] { 7, 8, 9, 10, 11 }; var countsThree = new int[] { 100, 101, 102, 103, 104 }; var countsWrongLength = new int[] { 55 }; var groupCountsBadInitialization = new int[] { 7, 7, 7, 7, 7 }; var countsWithQuotesOne = _modelFactory.GetSingleCountModel(countsOne); var countsWithQuotesTwo = _modelFactory.GetSingleCountModel(countsTwo); var countsWithQuotesThree = _modelFactory.GetSingleCountModel(countsThree); var countsWithQuotesWrongLength = _modelFactory.GetSingleCountModel(countsWrongLength); var countsWithoutQuotesOne = _modelFactory.GetSingleCountModel((int[])countsOne.Clone()); var countsWithoutQuotesTwo = _modelFactory.GetSingleCountModel((int[])countsTwo.Clone()); var countsWithoutQuotesThree = _modelFactory.GetSingleCountModel((int[])countsThree.Clone()); var countsWithoutQuotesWrongLength = _modelFactory.GetSingleCountModel((int[])countsWrongLength.Clone()); badCountInitialization = _modelFactory.GetSingleCountModel(groupCountsBadInitialization); var flexibleCountsOne = _modelFactory.GetFlexibleCountModel(countsWithQuotesOne, countsWithoutQuotesOne); var flexibleCountsTwo = _modelFactory.GetFlexibleCountModel(countsWithQuotesTwo, countsWithoutQuotesTwo); var flexibleCountsThree = _modelFactory.GetFlexibleCountModel(countsWithQuotesThree, countsWithoutQuotesThree); var flexibleCountsWrongLength = _modelFactory.GetFlexibleCountModel(countsWithQuotesWrongLength, countsWithoutQuotesWrongLength); textOne = _modelFactory.GetTextModel("text one", flexibleCountsOne); textTwo = _modelFactory.GetTextModel("text two", flexibleCountsTwo); textThree = _modelFactory.GetTextModel("text three", flexibleCountsThree); textWrongLength = _modelFactory.GetTextModel("text wrong length", flexibleCountsWrongLength); groupOne = _modelFactory.GetGroupModel("group one", 5); groupTwo = _modelFactory.GetGroupModel("group two", 5); }
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)); }
public void Initialize() { _modelFactory = new ModelFactory(); counts = _modelFactory.GetSingleCountModel(countSize); }
public void GetSingleCountsByLength() { ISingleWordCountModel output = _modelFactory.GetSingleCountModel(countSize); Assert.AreEqual(output.GetLength(), countSize); }
public void Initialize() { _modelFactory = new ModelFactory(); singleWordCountModel = _modelFactory.GetSingleCountModel(new int[] { 3, 5, 4, 7, 6 }); }