Skip to content

Instantly share code, notes, and snippets.

@dgg
Created March 9, 2018 09:24
Show Gist options
  • Save dgg/83a3ed53aac63e3260da861c2a3fd953 to your computer and use it in GitHub Desktop.
Save dgg/83a3ed53aac63e3260da861c2a3fd953 to your computer and use it in GitHub Desktop.
They-got-your-back
[Test]
[TestCase(2, 1, true)]
[TestCase(1, 2, false)]
[TestCase(1, 1, false)]
[TestCase(null, 1, false)]
[TestCase(1, null, false)]
[TestCase(null, null, false)]
public void Snippets_Are_Equivalent(int? qty1, int? qty2, bool result)
{
bool shouldCompare = qty1 != null && qty2 != null;
bool snippetOne = shouldCompare && (qty1.Value > qty2.Value);
bool snippetTwo = qty1 > qty2;
Assert.That(snippetOne, Is.EqualTo(snippetTwo).And.EqualTo(result));
}
int? qty1, qty2;
//...
bool shouldCompare = qty1 != null && qty2 != null;
if (shouldCompare && (qty1.Value > qty2.Value))
{
// do the thing when one is greater than the other
}
int? qty1, qty2;
//...
if (qty1 > qty2)
{
// do the thing when one is greater than the other
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment