Skip to content

TheFishPilot/FluxConvert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Flux-Convert: Multi-Unit Logic Engine

A complex conversion tool handling non-linear units with TDD architecture.

Project Philosophy

Unit conversion sounds simple until you deal with non-linear mapping (Celsius to Fahrenheit) or live rates (Currency). Flux-Convert is built to demonstrate Test-Driven Development (TDD) and Clean Architecture. It separates the "business logic" of conversion from the UI, ensuring robust and testable code.

Key Features

  • Multi-Category Support: Length, Weight, Temperature, Data, Currency.
  • Precision Handling: Correctly handles floating point math (e.g., IEEE 754 errors).
  • Separation of Concerns: Logic is decoupled from the DOM.
  • Unit Tested: Comprehensive test suite verifying edge cases.

Tech Stack

JavaScript Jest

  • JavaScript (ES6+): Core logic.
  • Jest: Testing framework (or a lightweight custom runner if preferred).
  • CSS Grid: for the converter UI layout.

How I Built This / Challenges

Floating Point Precision

JavaScript's 0.1 + 0.2 !== 0.3 issue is fatal for a precision tool. I implemented a utility helper to handle decimal rounding and epsilon comparisons to ensure conversions like "GB to Bytes" remain accurate to the specific decimal place.

Architecture Design

I strictly separated the conversion functions into a logic.js module. This allowed me to write tests for convert(20, 'C', 'F') without needing a browser environment. It proves the ability to write modular, testable code.

Extension Scalability

Hardcoding if (unit == 'kg') is a bad pattern. I designed a configuration object (Strategy Pattern) where adding a new unit is as simple as adding a conversion factor to a JSON list, rather than rewriting the logic functions.

Quick Start

Prerequisites

  • Node.js (for running tests)

Installation & Run

# Clone the repository
git clone https://github.com/yourusername/antigravity-opencode.git
cd 09-flux-convert

# Install dependencies (for testing)
npm install

Usage

  1. Run Tests:
    npm test
  2. Use App: Open index.html in your browser. Select category, input value, and see the result.

Project Structure

09-flux-convert/
├── index.html
├── logic.js
├── dom.js
├── logic.test.js
└── style.css

Contributing

Please maintain the TDD cycle when adding new units.


About

Logic-heavy unit conversion engine dealing with non-linear units and precision math.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors