Starting by go2
, it is easy to understand the assert.
The method does nothing, it just asserts your expectation, that x < 0
.
The go
method, on the other hand, has a switch
.
It is good practice to assert false
on the default
clause, if you absolutely do not expect your program to fall under this clause, ie, under normal circumstances, one of the case
s has to be correct.
The only case on the switch
expects x
to be exactly 2
.
So, to sum up, you don't expect x
to be greater than 0
, as the first assertion says, you expect x
to be 2
and nothing else. Thus, the assertion is not used appropriately.
However, as Jeff noted, the case
has no break
, which means the default
will always be executed, leading, in every scenario, to assert false
.
Conclusion: The go
method should always result in an error, making assert false
properly used, while assert x > 0
isn't correct at all.