Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

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 cases 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 JeffJeff 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.

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 cases 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.

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 cases 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.

Corrected answer.; added 147 characters in body
Source Link
afsantos
  • 5.2k
  • 4
  • 32
  • 55

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 cases has to be correct.

The only case on the switch expects x to be exactly 2.
SoSo, 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, to sum upas Jeff noted, you don't expectthe xcase to be greater thanhas no 0break, aswhich means the first assertion says, you expect xdefault towill always be executed, leading, in every scenario, to 2assert false and nothing else. Thus

Conclusion: The go method should always result in an error, the assertion is notmaking assert false properly used appropriately, while assert x > 0 isn't correct at all.

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 cases 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.

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 cases 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.

Source Link
afsantos
  • 5.2k
  • 4
  • 32
  • 55

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 cases 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.