Skip to content

Add Constants Detection to Input Validation #3

@lordlogo2002

Description

@lordlogo2002

Description:

Currently, the calculator program's input validation functions (data.check_input_for_number) only detect numerical values entered by the user. However, to enhance the user experience and provide additional functionality, we want to extend the validation to detect and handle commonly used constants like "PI" in mathematical calculations. This will allow users to input constants directly instead of manually entering their values.

Task:

Modify the input validation functions to detect and handle constants like "PI" in addition to numerical values.

Implementation Steps:

  1. Identify the most commonly used constants that should be detected by the input validation functions. Here are the suggested constants to add:
  • PI (3.14159...)
  • E (2.71828...)
  • GOLDEN_RATIO (1.61803...)
  • SPEED_OF_LIGHT (299792458)
  • PLANCK_CONSTANT (6.62607015e-34)
  • ELECTRON_CHARGE (1.602176634e-19)
  • GRAVITATIONAL_CONSTANT (6.67430e-11)
  • BOLTZMANN_CONSTANT (1.380649e-23)
  • AVOGADRO_CONSTANT (6.02214076e23)
  • ELECTRON_MASS (9.10938356e-31)

Note: Feel free to add more constants, but keep it reasonable

  1. Update the data.check_input_for_number function to include the detection and handling of constants. The function should:

  2. Check if the input matches any of the defined constants.

  3. If a match is found, return the corresponding constant value.

  4. If the input is not a constant, proceed with the existing numerical input validation.

Acceptance Criteria:

Update the data.check_input_for_number function to detect and handle the commonly used constants mentioned above.
Constants like "PI" should be recognized and returned as their corresponding values.
Numerical inputs should still be validated correctly.
Write comprehensive unit tests to validate the behavior of the updated function, covering various scenarios.
Ensure the code is properly documented, providing clear instructions on how to use the updated input validation functions.

Deliverables:

  • Modify the data.check_input_for_number function to include constant detection and handling.

  • Document and update Readme like mentioned in Update Readme for release V1.0 #5

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions