assert - assertion compareTo in java -



assert - assertion compareTo in java -

string title ="a"; int year = 2009; string director = "zebra"; string title1 ="b"; int year1 = 2010; string director1 = "zzz"; videoobj = new videoobj(title,year,director); videoobj b = new videoobj(title2,year,director); assert.asserttrue( a.compareto(b) == -b.compareto(a) );

what meaning of - in assert.asserttrue( a.compareto(b) == -b.compareto(a) ); statement???

please can explanation?

thanks

the meaning of - negation, plain , simple. i've seen idiom in numeric comparisons homecoming -1, 0 or +1 value, depending on comparison. although work homecoming magnitude well, -n, 0, +n (where n identical).

it's checking compareto operations give opposite value when reverse operands. in other words, it's assertion compareto functions expected (but not guaranteed - see below).

if a < b , b < a (ie, a both less than, and greater b), have serious problem needs fixing :-)

from compareto documentation:

the implementor must ensure sgn(x.compareto(y)) == -sgn(y.compareto(x)) x , y.

in foregoing description, notation sgn(expression) designates mathematical signum function, defined homecoming 1 of -1, 0, or 1 according whether value of look negative, 0 or positive.

based on that, assertion not quite right, should comparing integer.signum (a.compareto (b)) rather a.compareto (b), unless has knowledge implementation of compareto guaranteed homecoming symmetrical (around zero) values.

java assert

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -