Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .cursor/plans/scientific-calculator-3075674a.plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<!-- 3075674a-d8ff-42c4-9ab2-45b044ce3b25 281033a6-8c0c-431d-94b1-812cae00e512 -->
# Scientific Calculator Implementation Plan

## Overview

Extend the existing calculator architecture in `Models/` to add scientific computing capabilities, following the project's C# coding standards with `m_` prefix for private fields, `#region` blocks, and XML documentation.

## Implementation Steps

### 1. Create Scientific Calculator Interface

**File**: `Models/IScientificCalculator.cs`

- Extend `ICalculator` interface
- Add methods for scientific operations:
- Trigonometric: `Sin()`, `Cos()`, `Tan()`, `Asin()`, `Acos()`, `Atan()`
- Logarithmic: `Log()`, `Log10()`, `Ln()`
- Power/Root: `Power()`, `SquareRoot()`, `CubeRoot()`, `NthRoot()`
- Other: `Factorial()`, `Absolute()`, `Modulus()`
- Constants: Properties for `Pi`, `E`

### 2. Implement Scientific Calculator

**File**: `Models/ScientificCalculator.cs`

- Inherit from `Calculator` class
- Implement `IScientificCalculator` interface
- Use proper `#region` blocks (Private Fields, Constructors, Public Methods, Private Methods)
- Add angle mode support (Degrees/Radians) with private field `m_angleMode`
- Implement all scientific operations using `System.Math`
- Include proper error handling (negative factorial, domain errors for trig)
- Record operations in history (inherited from base)
- Add XML documentation for all public methods

### 3. Create Console Application

**File**: `Demo/ScientificCalculatorApp.cs`

- Create console UI with menu system
- Display available operations grouped by category (Basic, Trigonometric, Logarithmic, Power/Root, Other)
- Input validation for numbers and operation selection
- Support for angle mode toggle (Degrees/Radians)
- Display memory and history features
- Exit option
- Use proper `#region` blocks and follow naming conventions

### 4. Create Comprehensive Unit Tests

**File**: `Tests/ScientificCalculatorTests.cs`

- Follow test naming: `MethodName_StateUnderTest_ExpectedBehavior`
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggested test naming convention uses underscores, but C# best practices recommend PascalCase for test method names like MethodNameStateUnderTestExpectedBehavior or using the Given_When_Then pattern.

Suggested change
- Follow test naming: `MethodName_StateUnderTest_ExpectedBehavior`
- Follow test naming: `MethodNameStateUnderTestExpectedBehavior` or use the GivenWhenThen pattern in PascalCase (e.g., `GivenInput_WhenAction_ThenExpectedResult`)

Copilot uses AI. Check for mistakes.

- Use Arrange-Act-Assert pattern
- Test categories:
- **Basic Operations**: Verify inherited Add/Subtract/Multiply/Divide still work
- **Trigonometric Tests**: Test Sin/Cos/Tan in both degrees and radians, edge cases (0, 90, 180, 360 degrees)
- **Inverse Trigonometric Tests**: Test Asin/Acos/Atan with valid ranges
- **Logarithmic Tests**: Test Log/Log10/Ln with positive numbers, verify domain errors for negative/zero
- **Power/Root Tests**: Test Power, SquareRoot, CubeRoot, NthRoot with various inputs
- **Factorial Tests**: Test positive integers, zero, verify error for negatives
- **Angle Mode Tests**: Verify degree/radian conversions work correctly
- **Memory Tests**: Verify memory operations inherited from base
- **History Tests**: Verify scientific operations are recorded
- **Error Handling Tests**: Test all exception scenarios

### 5. Update Existing Files (if needed)

- Add namespace references if required
- No changes to existing `ICalculator` or `Calculator` to maintain backward compatibility

## Key Design Decisions

- **Inheritance**: `ScientificCalculator` extends `Calculator` to reuse memory and history functionality
- **Interface Hierarchy**: `IScientificCalculator` extends `ICalculator` for polymorphism
- **Angle Handling**: Default to Radians, provide mode toggle, convert internally when needed
- **Constants**: Expose `Math.PI` and `Math.E` as properties for convenience
- **Error Handling**: Use specific exceptions (`ArgumentException`, `ArgumentOutOfRangeException`) with clear messages

## Files to Create

1. `Models/IScientificCalculator.cs` - Interface definition
2. `Models/ScientificCalculator.cs` - Implementation (~200-250 lines)
3. `Demo/ScientificCalculatorApp.cs` - Console application
4. `Tests/ScientificCalculatorTests.cs` - Comprehensive unit tests (~500-600 lines)

### To-dos

- [ ] Create IScientificCalculator interface extending ICalculator with scientific operation methods
- [ ] Implement ScientificCalculator class with all scientific operations, angle mode support, and error handling
- [ ] Build console application with menu system for scientific calculator operations
- [ ] Create comprehensive unit tests covering all scientific operations, edge cases, and error handling