Add overflow check

Adds a check to make sure badges don't automatically get assigned
out-of-range.
Add new tests for next_badge_num

Improves and adds unit tests for the next_badge_num function.