Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
garora committed Aug 18, 2013
1 parent 3e87499 commit 8fa4310
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ public RecentlyUsedList(int listSize, IEnumerable<string> listItems)
public void Add(string listitem)
{
if (string.IsNullOrEmpty(listitem))
throw new ArgumentException(string.Format("List items should not be Empty or Null. But it was [{0}]", listitem));
throw new ArgumentException(string.Format("List items should not be Empty or Null. But it was [{0}]",
listitem));

AvoidDuplicateInsertion(listitem);

_listofuniquestrings.Insert(0, listitem);

TrimListToTheSizeDefined();

}
Expand All @@ -96,7 +100,10 @@ public int Count

get
{
return _listofuniquestrings != null ? _listofuniquestrings.Count : 0;
return _listofuniquestrings != null
? _listofuniquestrings.Count
: 0;

}
}

Expand Down Expand Up @@ -130,7 +137,9 @@ IEnumerator IEnumerable.GetEnumerator()
private void SetDefaultListSize()
{

_listSize = _listSize < 0 ? DefaultListSize : _listSize;
_listSize = _listSize < 0
? DefaultListSize
: _listSize;

}
private void CheckForValidIndex(int index)
Expand All @@ -141,19 +150,22 @@ private void CheckForValidIndex(int index)
if (index > _listofuniquestrings.Count - 1)
throw new ArgumentException(string.Format("supplied index [{0}] should not greater than [{1}].", index, _listofuniquestrings.Count - 1));
}

private void AvoidDuplicateInsertion(string listitem)
{
var indexOccurenceofItem = _listofuniquestrings.IndexOf(listitem);

if (indexOccurenceofItem > -1)
_listofuniquestrings.RemoveAt(indexOccurenceofItem);
}

private void TrimListToTheSizeDefined()
{
if (_listSize != -1)
while (_listofuniquestrings.Count > _listSize)
_listofuniquestrings.RemoveAt(0); //Remove from Top in LIFO
}

#endregion

}
Expand Down
22 changes: 19 additions & 3 deletions TDD-Katas-project/TDD-Katas-project/The WordWrap Kata/WordWrap.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;

namespace TDD_Katas_project.The_WordWrap_Kata
{
Expand All @@ -9,59 +10,74 @@ public static string Wrap(string word, int wordLength)
{
var actualCount = 0;
var wrappedword = string.Empty;

if (IsContainNewLine(word)) return word;

if (IsContainNullEmptyOrWhiteSpaces(word)) return string.Empty;

foreach (var wrd in word)
{
wrappedword = wrappedword + Convert.ToString(wrd);

if (IsWhiteSpaceOrNewLine(wrd)) continue;
if (IsContainNewLine(wrd.ToString())) continue;

if (IsContainNewLine(wrd.ToString(CultureInfo.InvariantCulture))) continue;

actualCount++;

if (actualCount == wordLength)
wrappedword += "\n";
}

wrappedword = GetWrappedwordWithoutBlankSpacesAtStartOfNewLine(wrappedword);

return wrappedword;
}
#endregion

#region MyRegion

private static string GetWrappedwordWithoutBlankSpacesAtStartOfNewLine(string wrappedword)
{
var newWrappedWord = wrappedword;
var spaceCounter = 0;

for (var outCounter = 0; outCounter < wrappedword.Length; outCounter++)
{
if (IsContainNewLine(wrappedword[outCounter].ToString()))
if (IsContainNewLine(wrappedword[outCounter].ToString(CultureInfo.InvariantCulture)))
for (var inCounter = outCounter + 1; inCounter < wrappedword.Length; inCounter++)
{
if (char.IsWhiteSpace(wrappedword[inCounter]))
spaceCounter++;
else
break;
}

if (spaceCounter <= 0) continue;
newWrappedWord = RemoveWhiteSpacesFromWrappedWord(wrappedword, outCounter, spaceCounter); //RemoveWhiteSpacesFromWrappedWord(wrappedword, outCounter + 1, spaceCounter);

newWrappedWord = RemoveWhiteSpacesFromWrappedWord(wrappedword, outCounter, spaceCounter); //RemoveWhiteSpacesFromWrappedWord(wrappedword, outCounter + 1, spaceCounter);

spaceCounter = 0;
}

return newWrappedWord;
}

private static string RemoveWhiteSpacesFromWrappedWord(string wrappedword, int outCounter, int spaceCounter)
{
return wrappedword.Remove(outCounter + 1, spaceCounter);
}

private static bool IsContainNewLine(string word)
{
return word == "\n";
}

private static bool IsContainNullEmptyOrWhiteSpaces(string word)
{
return (string.IsNullOrEmpty(word)) || (string.IsNullOrWhiteSpace(word));
}

private static bool IsWhiteSpaceOrNewLine(char wrd)
{
return char.IsWhiteSpace(wrd) && (wrd == '\n');
Expand Down

0 comments on commit 8fa4310

Please sign in to comment.