Skip to content

Conversation

@AliAlimohammadi
Copy link
Contributor

@AliAlimohammadi AliAlimohammadi commented Jan 20, 2026

Description

This PR adds comprehensive temperature conversion functionality supporting 8 major temperature scales using a clean, maintainable API design.

Design Approach

This implementation uses:

  • A single convert_temperature(value, from, to) function
  • A TemperatureUnit enum for type safety
  • Kelvin as an intermediary for all conversions

Scales Supported

  • Kelvin (K) - SI base unit
  • Celsius (°C) - Standard metric scale
  • Fahrenheit (°F) - Imperial scale
  • Rankine (°R) - Absolute Fahrenheit
  • Delisle (°De) - Historical inverted scale
  • Newton (°N) - Isaac Newton's scale
  • Réaumur (°Ré) - Historical European scale
  • Rømer (°Rø) - Historical Danish scale

API Usage

use conversions::{convert_temperature, TemperatureUnit};

// Convert 100°C to Fahrenheit
let fahrenheit = convert_temperature(100.0, TemperatureUnit::Celsius, TemperatureUnit::Fahrenheit);
// Result: 212.0

// Convert 0K to Celsius
let celsius = convert_temperature(0.0, TemperatureUnit::Kelvin, TemperatureUnit::Celsius);
// Result: -273.15

Changes

  • Added src/conversions/temperature.rs with:
    • TemperatureUnit enum
    • convert_temperature() function
    • Internal to_kelvin() and from_kelvin() methods
  • Updated src/conversions/mod.rs to export the public API
  • Comprehensive test coverage including:
    • Individual scale conversions
    • Round-trip validation for all 64 combinations
    • Special temperature points (absolute zero, water freezing/boiling)
    • Historical scale verification
    • Same-unit conversion (identity test)

Testing

  • ✅ All unit tests pass
  • ✅ Round-trip conversions verified for all 64 combinations
  • ✅ Clippy warnings resolved
  • ✅ Code formatted with cargo fmt
  • ✅ No dead code warnings

References

Checklist

  • Code follows the project's style guidelines
  • Tests added for new functionality
  • Module documentation added
  • All tests pass locally
  • Code formatted with cargo fmt
  • No clippy warnings
  • Public API exported in mod.rs
  • Type-safe enum-based design

@codecov-commenter
Copy link

codecov-commenter commented Jan 20, 2026

Codecov Report

❌ Patch coverage is 99.21875% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.07%. Comparing base (4402903) to head (4f3e46b).

Files with missing lines Patch % Lines
src/conversions/temperature.rs 99.21% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1002      +/-   ##
==========================================
+ Coverage   96.06%   96.07%   +0.01%     
==========================================
  Files         371      372       +1     
  Lines       25943    26071     +128     
==========================================
+ Hits        24922    25048     +126     
- Misses       1021     1023       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AliAlimohammadi
Copy link
Contributor Author

@siriak, this is ready to be merged.

@AliAlimohammadi AliAlimohammadi changed the title feat: add comprehensive temperature conversion functions feat: add comprehensive temperature conversion function Jan 20, 2026
@siriak siriak merged commit a6f9ffd into TheAlgorithms:master Jan 20, 2026
7 checks passed
@AliAlimohammadi AliAlimohammadi deleted the add-temperature-conversions branch January 20, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants