Files
geek-calc/specs/001-build-a-single/data-model.md
snowprint 54f427ea21
Some checks failed
Deploy to GitHub Pages / build-and-deploy (push) Has been cancelled
init geek calc
2025-10-04 10:53:41 +08:00

45 lines
2.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Data Model: Geek Calculator
## Entities
### Calculation Expression
- **Representation**: String containing numbers, operators (+, -, ×, ÷), parentheses, percentage, +/- signs
- **Validation**: Must follow valid mathematical expression syntax rules
- **State transitions**: In-progress expression → evaluated expression → stored in history
### Calculation Result
- **Representation**: Number (JavaScript number type, may be Infinity or finite value)
- **Validation**: Must be a numeric result from evaluation
- **State transitions**: Calculated from expression → displayed → stored in history
### RPN Stack
- **Representation**: Array of numbers representing operands in Reverse Polish Notation
- **Operations**: Push, pop, peek, clear, size
- **Validation**: Elements must be valid numbers
- **State transitions**: Empty → populated with operands → modified through RPN operations
### Calculation History Entry
- **Fields**:
- expression (string): The original input expression
- result (number): The calculated result
- timestamp (Date): When the calculation was completed
- id (string): Unique identifier for recall
- **Validation**: Expression and result must be valid
- **State transitions**: New entry → stored → accessed → potentially deleted when limit reached
### Application Settings
- **Fields**:
- theme (string): 'dark' or other theme options
- mode (string): 'standard' or 'rpn' for calculation mode
- historyLimit (number): Maximum number of history entries to store
- **Validation**: Values must be from predefined sets
- **State transitions**: Default settings → user modified → saved to localStorage
### User Input State
- **Fields**:
- currentValue (string): The current value being entered
- operator (string): The current operator in use
- previousValue (number): The previous operand
- calculationPending (boolean): Whether a calculation is ready to execute
- **Validation**: Values must be consistent with calculator state
- **State transitions**: Initial state → value entry → operator selection → result calculation