**FIND AN OUT BY ONE ERROR**

I did not know where to start with this challenge: what is an out by one error?

After some googling, I decided to stick to off-by-one error and its definition from Wikipedia:

*An off-by-one error is a logic error involving the discrete equivalent of a boundary condition. It often occurs in computer programming when an iterative loop iterates one time too many or too few. This problem could arise when a programmer makes mistakes such as using “is less than or equal to” where “is less than” should have been used in a comparison or fails to take into account that a sequence starts at zero rather than one (as with array indices in many languages).*

I did discuss this with some friends and they confirmed that it must be the same as “an out by one error”. They gave some more practical examples as well:

- an array has 10 elements and you want the fifth one, so you do arr[5], but since arrays might be indexed from 0, the fifth element is arr[4] and you’re off-by-one;
- Vitruvius fencepost error:
*if you build a straight fence 30 meters long with posts spaced 3 meters apart, how many posts do you need?*You may think that you need 10, but to make 10 sections, you need 11 posts.

I am super grateful for wonderful friends as one of them doubting that I will be able to find any of these errors as they are quite easy to check and rare in production, created my own broken counter! If you write a number to which this little program should count – it will start counting with 0 (intentional programmer’s error):

I did not want to give up this easily, so I invested some time checking other sites.I was thinking of where any kind of counting would be done, and, ended up checking e-commerce sites: their searches and price filtering (searching for < instead of =<).

I went to Vero Moda’s Day Dresses category. I decided to check if price filters are working as they say: if there is a price filter “10-20” I expect that it would include both 10 and 20. So, I checked first 10-20 filter and filtered results by High to Low price:

As you can see, there are no 20 pounds dresses. I may guess here that there is less than 20 filter (which user doesn’t know), not less or equal as you may assume. However, maybe site simply does not have dresses which are worth 20 pounds? So, I checked filter 20-30 and filtered prices from low to high to see if there are 20 pounds dresses:

And it turns out that there are dresses which are worth 20 pounds. This means that I found **an off-by-one error**:

**In Vero Moda’s price range filter, upper bound is not included: it is < instead of =<.**

This is definitely not a huge mistake, but may cost a lot: if user’s budget is up to 20 pounds after filtering to 10-20 price range she may not find what she wants, thus she may end up not buying anything. Maybe some of the dresses which were costing equally 20 dollars would have been most attractive to the user, but there was no chance to see them with the filter on.

30 Days of Testing is moving towards the end and I am so grateful that I need to google some of the definitions because I did encounter off-by-one errors before (especially with strict bounds), but never knew the exact name. Now I do and it feels great to have a term which describes a specific type of a problem!

[…] FIND AN OUT BY ONE ERROR: Off-by-one error hunt […]