nathanwailes

Coming up with edge cases

Apr 3rd, 2024
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. ## PROBLEM
  2.  
  3. https://leetcode.com/problems/valid-number/
  4.  
  5. A valid number can be split up into these components (in order):
  6.  
  7. - A decimal number or an integer.
  8. - (Optional) An 'e' or 'E', followed by an integer.
  9.  
  10. A decimal number can be split up into these components (in order):
  11.  
  12. - (Optional) A sign character (either '+' or '-').
  13. - One of the following formats:
  14. - One or more digits, followed by a dot '.'.
  15. - One or more digits, followed by a dot '.', followed by one or more digits.
  16. - A dot '.', followed by one or more digits.
  17.  
  18. An integer can be split up into these components (in order):
  19.  
  20. - (Optional) A sign character (either '+' or '-').
  21. - One or more digits.
  22.  
  23. For example, all the following are valid numbers: ["2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7", "+6e-1", "53.5e93", "-123.456e789"], while the following are not valid numbers: ["abc", "1a", "1e", "e3", "99e2.5", "--6", "-+3", "95a54e53"].
  24.  
  25. Given a string s, return true if s is a valid number.
  26.  
  27. Constraints:
  28. - 1 <= s.length <= 20
  29. - s consists of only English letters (both uppercase and lowercase), digits (0-9), plus '+', minus '-', or dot '.'.
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. ## SOLUTION
  45.  
  46. Let's come up with edge cases for these two cases separately, starting with the simpler one (integers):
  47.  
  48. ### Integers
  49. - Let's first consider edge cases without the sign characters.
  50. - Let's consider length as a source of edge cases:
  51. - '' is invalid
  52. - Anything with 'a', '1a',
  53. -
Advertisement
Add Comment
Please, Sign In to add comment