Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why test for these numbers (2^16, 2^31 ....)

Going through Elisabeth Hendrickson's test heuristics cheatsheet , I see the following recommendations :

Numbers : 32768 (2^15) 32769 (2^15+ 1) 65536 (2^16) 65537 (2^16 +1) 2147483648 (2^31) 2147483649 (2^31+ 1) 4294967296 (2^32) 4294967297 (2^32+ 1)

Does someone know the reason for testing all theses cases ? My gut feeling goes with the data type the developer may have used ( integer, long, double...)

Similarly, with Strings :

Long (255, 256, 257, 1000, 1024, 2000, 2048 or more characters)

like image 758
user316054 Avatar asked Aug 14 '12 16:08

user316054


People also ask

What is the rule for the pattern of numbers?

When numbers in a pattern get larger as the sequence continues, they are in an ascending pattern. Ascending patterns often involve multiplication or addition. When numbers in a pattern get smaller as the sequence continues, they are in a descending pattern. Descending patterns often involve division or subtraction.

How does sequencing of number help you in finding the missing number?

Missing Number in a Sequence. Determine if the order of numbers is ascending (getting larger in value) or descending (becoming smaller in value). Find the difference between numbers that are next to each other. Use the difference between numbers to find the missing number.

Which of the following sequences is an arithmetic sequence why 2 4 8 16?

Expert-Verified Answer The first sequence is 2, 4, 8, 16, ... Since the differences of the terms are not equal, then the sequence is not an arithmetic sequence. The second sequence is - 8, - 6, - 4, - 2, ... and third term - second term = - 4 - (- 6) = - 4 + 6 = 2.

Why is 2 such a special number?

2 (two) is a number, numeral and digit. It is the natural number following 1 and preceding 3. It is the smallest and only even prime number. Because it forms the basis of a duality, it has religious and spiritual significance in many cultures.


1 Answers

These represent boundaries

Integers

  • 2^15 is at the bounds of signed 16-bit integers
  • 2^16 is at the bounds of unsigned 16-bit integers
  • 2^31 is at the bounds of signed 32-bit integers
  • 2^32 is at the bounds of unsigned 32-bit integers

Testing for values close to common boundaries tests whether overflow is correctly handled (either arithmetic overflow in the case of various integer types, or buffer overflow in the case of long strings that might potentially overflow a buffer).

Strings

  • 255/256 is at the bounds of numbers that can be represented in 8 bits
  • 1024 is at the bounds of numbers that can be represented in 10 bits
  • 2048 is at the bounds of numbers that can be represented in 11 bits

I suspect that the recommendations such as 255, 256, 1000, 1024, 2000, 2048 are based on experience/observation that some developers may allocate a fixed-size buffer that they feel is "big enough no matter what" and fail to check input. That attitude leads to buffer overflow attacks.

like image 93
Eric J. Avatar answered Sep 21 '22 12:09

Eric J.