次の方法で共有


A silly hallway conversation reminds me about boundary cases

Dan Escapa, Gary and I were having a hallway conversation about some obscure thing and somehow the phrase " to be or not to be" came up. I don’t know why I thought of this, but I saw it as a hexadecimal boolean logic question (computer geeks, I know) and the answer became quickly apparent:

"FF"

OK, fine, this is a silly computer math joke, and likely not original anyway. I told Dan that this topic would make a good blog article and went to type this text. As I was verifying my answer of "FF" = 2B or !2B (since testers verify everything), I used the Windows calculator. It gave this as its answer:

FFFFFFFFFFFFFFFF

Interesting - clearly we had the same thinking, but it used sixteen digits, and I cut my answer off at two digits. I had bounded my answer to the number of digits in the problem, and the calculator was bounded by 16 digits, or 64 bits.

When I converted the FFFFFFFFFFFFFFFF to decimal in calculator, I got -1. I had expected 18446744073709551616, which is 2^64. But as a tester, I can understand what is happening - it boils down to signed and unsigned values. If I convert 18446744073709551616 to hexadecimal in calculator, I get 1999999999999999. I won't go into the details here, and I am sure diligent readers can dig into what exactly is happening (and its worth digging, by the way). What this all boils down to is an example of a boundary value case. Since I am using a 64 bit machine, integers for most applications will probably have a maximum value of 2^64, or 18446744073709551616. So I know if I am testing code that has an integer in it, test cases with that integer near this value (+/-1) are probably going to be interesting. (And calculator reminds me that this number /2 would also be a nice test to try.) They will result in that value becoming too large to be held in 64 bits, and whatever I am testing needs to be able to deal with this case.

Anyway, as we were joking around about Hamlet, I thought I would just be able to blog about the silly joke. I'm happy it turned into a basic test case!

Questions, comments, concerns and criticisms always welcome,
John