Hi,
Assertions are in theory for testing code invariants, assumptions that must be true in order for the code to complete properly.
The example shown is testing for valid input, which isn't a typical usage for an assertion because it is, generally, user supplied.
Assertions aren't generally used in production code because there is an overhead and it is assumed that situations where the invariants fail
have been caught as coding errors during development and testing. LINE-5 and LINE-13 are trying to validate the input, that's why they are
in-appropriate usage ofassertion. Additionally, your assumption is correct that test2 can be used for some other way also, but currently the
author is talking about context of the example so in this example, the way assertion has been used is in-appropriate.
Correct syntax of assertion is
assert <boolean expression>;
Program is using it in a wrong way.
means: a MUST have a lenght equals 2 else is an error. Please check
OracleDocumentation
HTH,
Ben