Skip to content

Instantly share code, notes, and snippets.

@ilkerde
Created March 31, 2011 07:40
Show Gist options
  • Save ilkerde/895974 to your computer and use it in GitHub Desktop.
Save ilkerde/895974 to your computer and use it in GitHub Desktop.
What do you expect? Fail or Pass? Me expects Fail!
/* Question:
What do you expect from assertion below? Fail or Pass?
*/
List<string> aList = new List<string> { "any" };
List<string> anEmptyList = new List<string>();
aList.ShouldContain(anEmptyList); // this currently passes!
/*
My opinion: above assertion should fail. My spec for this is:
*/
public class when_a_list_contains_an_element_and_another_list_is_empty
{
It should_fail_the__ShouldContains__assertion =
() => SpecException.ShouldBeOfType<SpecificationException>();
Because of =
() => SpecException = Catch.Exception(() => AList.ShouldContain(AnotherList));
Establish context =
() =>
{
Element = "An Element";
AList = new List<string> {Element};
AnotherList = new List<string>();
};
static Exception SpecException;
static List<string> AList;
static List<string> AnotherList;
static string Element;
}
/*
What do you think?
*/
@forki
Copy link

forki commented Apr 1, 2011

Hi Ilker,

Given a set A and B, it must be A ∩ B != {} and A ∩ B = B

this can be reduced to:

B != {} and A ∩ B = B

I would write this as two expression:

It should_be_a_subset_of_A = () => A.ShouldContainAllElementsOf(B);
It should_be_nonempty = () => B.ShouldNotBeEmpty();

I think this separation is valid since the mathematical notation also distincts both cases and it would be good to communicate this in the specs. It also reads better in the error report (it might be the case that only one statement is broken).

Inhabited Sets might be a valid solution but I think Constructivism terms and arguments are not that widespread. ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment