Skip to content

Commit

Permalink
Removed CalculateLuhnDigit() from Program class, amended tests to rem…
Browse files Browse the repository at this point in the history
…ove references to it(passing)
  • Loading branch information
MylesFTOP committed Mar 8, 2020
1 parent 91e4ae3 commit c1ba06b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 35 deletions.
31 changes: 0 additions & 31 deletions ValidationCore/LuhnCheck/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,8 @@ static void Main(string[] args)
// Luhn algorithm: starting from the right, take every other digit and double it, then add it all together

string input = Console.ReadLine();
CalculateLuhnDigit(input);

LuhnValidator luhnCandidate = new LuhnValidator();
LuhnValidator.CalculateLuhnDigit(input);
}

public static string CalculateLuhnDigit(string input)
{
int luhnDigit = 0;
int singleOperands = 0;
int doubleOperands = 0;

for (int i = 0; i < input.Length; i++)
{
int currentDigit = int.Parse(input.Substring(input.Length - i - 1, 1));

if (i % 2 == 0)
{ doubleOperands += currentDigit; }
else
{ singleOperands += currentDigit; }
}

luhnDigit = singleOperands + (2 * doubleOperands);
string luhnDigitString = luhnDigit.ToString();
luhnDigit = 0;

for (int i = 0; i < luhnDigitString.Length; i++)
{ luhnDigit += int.Parse(luhnDigitString.Substring(i, 1)); }

string output = input + luhnDigit;
Console.WriteLine(output);
return output;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ public class LuhnCalculationUnitTest
[Fact]
public void checkLuhnOutput()
{
string input = "12";
LuhnValidator luhnCandidate = new LuhnValidator();

string input = "12";
string actualValue = "125";
string expectedValue = LuhnValidator.CalculateLuhnDigit(input);
string actualValue = Program.CalculateLuhnDigit(input);
Assert.Equal(expectedValue, actualValue);
}

[Fact]
public void checkLuhnOutput2()
{
string input = "123456789";
LuhnValidator luhnCandidate = new LuhnValidator();

string input = "123456789";
string actualValue = "1234567897";
string expectedValue = LuhnValidator.CalculateLuhnDigit(input);
string actualValue = Program.CalculateLuhnDigit(input);
Assert.Equal(expectedValue, actualValue);
}
}
Expand Down

0 comments on commit c1ba06b

Please sign in to comment.