-
Notifications
You must be signed in to change notification settings - Fork 6
Tables
msuarz edited this page Nov 2, 2010
·
10 revisions
Mostly used in Setup and Verify steps. The default behavior results in bi-dimensional array passed into the step. The types are inferred.
Scenario: Dead cell with 0 neighbors stays dead Given the following setup | . | . | . | | . | . | . | | . | . | . | When I evolve the board Then the center cell should be "dead"
[TestMethod]
public void DeadCellWith0NeighborsStaysDead()
{
Given_the_following_setup
(
new[] {".", ".", "."},
new[] {".", ".", "."},
new[] {".", ".", "."}
);
When_I_evolve_the_board();
Then_the_center_cell_should_be("dead");
}
public void Given_the_following_setup(params string[][] Cells)
{
...
}
Use [ and ] on the first row to make it a header. Instead of a 2D array the step is called multiple times passing 1 row at a time. The step definition could use 1 arg per column or a params array.
Scenario: Sum A plus B = C [A |B |C ] |0 |0 |0 | |0 |1 |1 | |21|21|42|
[TestMethod]
public void Sum()
{
A_plus_B___C(0, 0, 0);
A_plus_B___C(0, 1, 1);
A_plus_B___C(21, 21, 42);
}
// 1 arg per value
void A_plus_B___C(int A, int B, int C)
{
(A + B).ShouldBe(C);
}
// array with the values
void A_plus_B___C(params int[] Row)
{
Row.Take(Row.Length - 1)
.Sum().ShouldBe(Row.Last());
}