The Tests All Run


The tests all run, and the code is much better. It s time for a break. Let s see what we ve accomplished. We had these two methods :

 public void InsertParagraphTag() { 
if ( lines.Count == 0 ) {
lines.Add( "<P></P>" );
selectionStart = 3;
return;
}
lines.InsertRange(LineContainingCursor()+1, NewParagraph());
selectionStart = NewSelectionStart(LineContainingCursor() + 2, "<P>");
}

public void InsertSectionTags() {
if ( lines.Count == 0 ) {
lines.Add( "<sect1><title></title>" );
lines.Add( "</sect1>");
selectionStart = 14;
return;
}
lines.InsertRange(LineContainingCursor()+1, NewSection());
selectionStart = NewSelectionStart(LineContainingCursor() + 1,
"<sect1><title>");
}

And now we have these:

 public void InsertParagraphTag() { 
int cursorLine = LineContainingCursor();
lines.InsertRange(cursorLine+1, NewParagraph());
selectionStart = NewSelectionStart(cursorLine + 1, "<P>");
}

public void InsertSectionTags() {
int cursorLine = LineContainingCursor();
lines.InsertRange(cursorLine+1, NewSection());
selectionStart = NewSelectionStart(cursorLine + 1, "<sect1><title>");
}

Much better. Of course, we can see that these two methods are almost exactly the same, so there s duplication to remove. We ll catch that next time.




Extreme Programming Adventures in C#
Javaв„ў EE 5 Tutorial, The (3rd Edition)
ISBN: 735619492
EAN: 2147483647
Year: 2006
Pages: 291

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net