Capitolo 1 - Count invocations with Closure #18
arialdomartini
started this conversation in
Games
Replies: 2 comments 10 replies
-
|
Beta Was this translation helpful? Give feedback.
10 replies
-
|
Visto il problema riscontrato (usare un contatore esterno statico che calcola male la count), mi sono permesso di riscrivere il test: [Fact]
void should_count()
{
Func<int, int> f = n => n * 2;
f(10).Should().Be(20);
f(10).Should().Be(20);
f(10).Should().Be(20);
var doubleCount = f.AndAlsoCountCalls();
var anotherDoubleCount = f.AndAlsoCountCalls();
{
var result = doubleCount(10);
result.value.Should().Be(20);
result.count.Should().Be(1);
}
{
var result = anotherDoubleCount(10);
result.value.Should().Be(20);
result.count.Should().Be(1);
}
{
var result = doubleCount(10);
result.value.Should().Be(20);
result.count.Should().Be(2);
}
{
var result = anotherDoubleCount(20);
result.value.Should().Be(40);
result.count.Should().Be(2);
}
{
var result = doubleCount(10);
result.value.Should().Be(20);
result.count.Should().Be(3);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Beta Was this translation helpful? Give feedback.
All reactions