public void T_GenerateParagraphs_Indentation() { GeneratorFacade facade = InitBaseFacade(); ParagraphParams defaultParams = new ParagraphParams { ParagraphIndent = 8, SentenceIndent = 4 }; string resultStr = facade.GenerateParagraphs(5, defaultParams); StringBuilder sb = new StringBuilder(); for (int i = 0; i < defaultParams.ParagraphIndent; i++) { sb.Append(" "); } string paragraphIndent = sb.ToString(); sb.Length = 0; for (int i = 0; i < defaultParams.SentenceIndent; i++) { sb.Append(" "); } string sentenceIndent = sb.ToString(); sb.Length = 0; string[] paragraphSplits = resultStr.Split(new string[] { paragraphIndent }, StringSplitOptions.RemoveEmptyEntries); //Verify we got 5 paragraphs Assert.AreEqual(5, paragraphSplits.Length); foreach (string paragraph in paragraphSplits) { string trimmedParagraph = paragraph.TrimEnd() ; string[] sentenceSplits = trimmedParagraph.Split(new string[] { sentenceIndent }, StringSplitOptions.RemoveEmptyEntries); //Check sentences are of appropriate sizes Assert.GreaterOrEqual(sentenceSplits.Length, defaultParams.MinSentences); Assert.LessOrEqual(sentenceSplits.Length, defaultParams.MaxSentences); //Check sentences actually end with a punctuation mark foreach (string sentence in sentenceSplits) { Assert.Contains(sentence[sentence.Length - 1], facade.Generator.SentenceEnd); } } }
/// <summary> /// Generate paragraphs using specified settings /// The number of sentences will be a randomly generated number /// between the minimum and maximum number of sentences /// </summary> /// <returns></returns> public string GenerateParagraphs(int numParagraphs, ParagraphParams inputParams) { if (numParagraphs < 1) { throw new Exceptions.InvalidArguments( "The number of paragraphs should be at least one"); } if (inputParams.MinSentences > inputParams.MaxSentences) { throw new Exceptions.InvalidArguments( "Mininum sentences should be less than or equal to max sentences"); } if (inputParams.MaxSentences < 2) { throw new Exceptions.InvalidArguments( "Maximum sentences should be at least 2"); } if (inputParams.MinSentences < 0 || inputParams.ParagraphIndent < 0 || inputParams.SentenceIndent < 0) { throw new Exceptions.InvalidArguments( "All arguments should be positive"); } StringBuilder sb = new StringBuilder(); for(int i = 0 ; i < inputParams.ParagraphIndent ; i++) { sb.Append(' ') ; } string paragraphIndent = sb.ToString() ; sb.Length = 0 ; for(int i = 0 ; i < inputParams.SentenceIndent ; i++) { sb.Append(' ') ; } string sentenceIndent = sb.ToString() ; StringBuilder completeParagraphs = new StringBuilder() ; for(int i = 0 ; i < numParagraphs ; i++) { sb.Length = 0 ; if(i > 0) { sb.AppendLine() ; } sb.Append(paragraphIndent) ; int numSentences = _rand.Next(inputParams.MinSentences, inputParams.MaxSentences + 1) ; for(int j = 0 ; j < numSentences ; j ++) { if(j > 0) { sb.Append(sentenceIndent) ; } string currSentence = Generator.GenerateSentence(Defs.DEFAULT_MIN_SENTENCE_LENGTH); sb.Append(currSentence) ; } completeParagraphs.Append(sb) ; } return completeParagraphs.ToString() ; }
/// <summary> /// Generate paragraphs using specified settings /// The number of sentences will be a randomly generated number /// between the minimum and maximum number of sentences /// </summary> /// <returns></returns> public string GenerateParagraphs(int numParagraphs, ParagraphParams inputParams) { if (numParagraphs < 1) { throw new Exceptions.InvalidArguments( "The number of paragraphs should be at least one"); } if (inputParams.MinSentences > inputParams.MaxSentences) { throw new Exceptions.InvalidArguments( "Mininum sentences should be less than or equal to max sentences"); } if (inputParams.MaxSentences < 2) { throw new Exceptions.InvalidArguments( "Maximum sentences should be at least 2"); } if (inputParams.MinSentences < 0 || inputParams.ParagraphIndent < 0 || inputParams.SentenceIndent < 0) { throw new Exceptions.InvalidArguments( "All arguments should be positive"); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < inputParams.ParagraphIndent; i++) { sb.Append(' '); } string paragraphIndent = sb.ToString(); sb.Length = 0; for (int i = 0; i < inputParams.SentenceIndent; i++) { sb.Append(' '); } string sentenceIndent = sb.ToString(); StringBuilder completeParagraphs = new StringBuilder(); for (int i = 0; i < numParagraphs; i++) { sb.Length = 0; if (i > 0) { sb.AppendLine(); } sb.Append(paragraphIndent); int numSentences = _rand.Next(inputParams.MinSentences, inputParams.MaxSentences + 1); for (int j = 0; j < numSentences; j++) { if (j > 0) { sb.Append(sentenceIndent); } string currSentence = Generator.GenerateSentence(Defs.DEFAULT_MIN_SENTENCE_LENGTH); sb.Append(currSentence); } completeParagraphs.Append(sb); } return(completeParagraphs.ToString()); }