Skip to content

Instantly share code, notes, and snippets.

@simpleprogrammer-shared
simpleprogrammer-shared / why-comments-are-stupid-1.cs
Created July 17, 2016 19:16
Why Comments Are Stupid, a Real Example
internal static void SplitDirectoryFile(string path, out string directory, out string file)
{
directory = null;
file = null;
// assumes a validated full path
if (path != null)
{
int length = path.Length;
int rootLength = GetRootLength(path);
@simpleprogrammer-shared
simpleprogrammer-shared / specification-based-test-design-11.cs
Created July 17, 2016 19:13
Specification-based Test Design Techniques for Enhancing Unit Tests (Part 1) 11
private const string GreaterThanZeroExpectionMessage = "The age should be greater than zero.";
private const string SmallerThan123ExpectionMessage = "The age should be smaller than 123.";
private const string ShouldBeIntegerExpectionMessage = "The age input should be an integer value between 0 - 122.";
[TestCase("-1", 0, ExpectedException = typeof(ArgumentException), ExpectedMessage = GreaterThanZeroExpectionMessage)]
[TestCase("0", 0, ExpectedException = typeof(ArgumentException), ExpectedMessage = GreaterThanZeroExpectionMessage)]
[TestCase("1", 0)]
[TestCase("4", 0)]
[TestCase("5", 0)]
[TestCase("6", 20)]
@simpleprogrammer-shared
simpleprogrammer-shared / specification-based-test-design-10.cs
Created July 17, 2016 19:12
Specification-based Test Design Techniques for Enhancing Unit Tests (Part 1) 10
private const string GreaterThanZeroExpectionMessage = "The age should be greater than zero.";
private const string SmallerThan123ExpectionMessage = "The age should be smaller than 123.";
private const string ShouldBeIntegerExpectionMessage = "The age input should be an integer value between 0 - 122.";
[TestCase("0", 0, ExpectedException = typeof(ArgumentException), ExpectedMessage = GreaterThanZeroExpectionMessage)]
[TestCase("5", 0)]
[TestCase("15", 20)]
[TestCase("25", 40)]
[TestCase("80", 5)]
[TestCase("1000", 0, ExpectedException = typeof(ArgumentException), ExpectedMessage = SmallerThan123ExpectionMessage)]
@simpleprogrammer-shared
simpleprogrammer-shared / specification-based-test-design-9.cs
Created July 17, 2016 19:11
Specification-based Test Design Techniques for Enhancing Unit Tests (Part 1) 9
else
{
throw new ArgumentException("The age should be smaller than 123.");
}
@simpleprogrammer-shared
simpleprogrammer-shared / specification-based-test-design-8.cs
Created July 17, 2016 19:10
Specification-based Test Design Techniques for Enhancing Unit Tests (Part 1) 8
if (age <= 0)
{
throw new ArgumentException("The age should be greater than zero.");
}
@simpleprogrammer-shared
simpleprogrammer-shared / specification-based-test-design-7.cs
Created July 17, 2016 19:09
Specification-based Test Design Techniques for Enhancing Unit Tests (Part 1) 7
if (!isInteger)
{
throw new ArgumentException("The age input should be an integer value between 0 - 122.");
}
@simpleprogrammer-shared
simpleprogrammer-shared / specification-based-test-design-6.cs
Created July 17, 2016 19:09
Specification-based Test Design Techniques for Enhancing Unit Tests (Part 1) 6
else if (age >= 65 && age <= 122)
{
subscriptionPrice = 5;
}
@simpleprogrammer-shared
simpleprogrammer-shared / specification-based-test-design-5.cs
Created July 17, 2016 19:08
Specification-based Test Design Techniques for Enhancing Unit Tests (Part 1) 5
еlse if (age > 18 && age < 65)
{
subscriptionPrice = 40;
}
@simpleprogrammer-shared
simpleprogrammer-shared / specification-based-test-design-4.cs
Created July 17, 2016 19:07
Specification-based Test Design Techniques for Enhancing Unit Tests (Part 1) 4
else if (age > 5 && age <= 18)
{
subscriptionPrice = 20;
}
@simpleprogrammer-shared
simpleprogrammer-shared / specification-based-test-design-3.cs
Created July 17, 2016 19:06
Specification-based Test Design Techniques for Enhancing Unit Tests (Part 1) 3
else if (age > 0 && age <= 5)
{
subscriptionPrice = 0;
}