Add a Celsius/Fahrenheit conversion module with rounding and unit tests #7

Merged
toasterson merged 1 commit from claude/wi-019fcd16-add-a-celsius-fahrenheit-conversion-modu into main 2026-08-16 09:20:15 +00:00
Owner

Anima work item 019fcd16-660a-7213-916d-b21771dfe07e.

What to build

The crate is a small hello-world. Cargo.toml is anima-canary 0.1.0, edition 2021,
no dependencies — keep it that way, do not add any crate.

Work from main as it stands. Ignore any other open branch on this repo.

1. src/temperature.rs (new file)

/// Convert Celsius to Fahrenheit.
pub fn c_to_f(c: f64) -> f64 { ... }

/// Convert Fahrenheit to Celsius.
pub fn f_to_c(f: f64) -> f64 { ... }

/// Round to `places` decimal places.
pub fn round_to(value: f64, places: u32) -> f64 { ... }

round_to(23.456, 2) must give 23.46. Implement it with 10f64.powi(places as i32),
not by formatting to a string.

2. Wire it into main.rs

Declare the module. Keep the existing first line of output, then print:

0C = 32F
100C = 212F
98.6F = 37C

Use round_to(.., 1) on the Fahrenheit-to-Celsius line so it prints 37 and not
36.99999999999999.

3. Unit tests

In src/temperature.rs, a #[cfg(test)] mod tests covering:

  • c_to_f(0.0) is 32.0
  • c_to_f(100.0) is 212.0
  • f_to_c(32.0) is 0.0
  • round_to(f_to_c(98.6), 1) is 37.0
  • -40.0 is the fixed point: c_to_f(-40.0) is -40.0
  • a round-trip: round_to(f_to_c(c_to_f(21.5)), 4) is 21.5

Compare floats with an epsilon ((a - b).abs() < 1e-9), not ==, except where the
value is exactly representable.

Acceptance

  • cargo build succeeds.
  • cargo test passes, with at least 6 tests.
  • cargo clippy -- -D warnings is clean.
  • No new dependencies.
  • cargo run prints the lines above, in that order.

Notes

This is a canary for the turn-completion fix that just deployed — the repo is trivial on
purpose. If something blocks you, say plainly what stopped you rather than working around
it.

Anima work item `019fcd16-660a-7213-916d-b21771dfe07e`. ## What to build The crate is a small hello-world. `Cargo.toml` is `anima-canary` 0.1.0, edition 2021, **no dependencies** — keep it that way, do not add any crate. Work from `main` as it stands. Ignore any other open branch on this repo. ### 1. `src/temperature.rs` (new file) ```rust /// Convert Celsius to Fahrenheit. pub fn c_to_f(c: f64) -> f64 { ... } /// Convert Fahrenheit to Celsius. pub fn f_to_c(f: f64) -> f64 { ... } /// Round to `places` decimal places. pub fn round_to(value: f64, places: u32) -> f64 { ... } ``` `round_to(23.456, 2)` must give `23.46`. Implement it with `10f64.powi(places as i32)`, not by formatting to a string. ### 2. Wire it into `main.rs` Declare the module. Keep the existing first line of output, then print: ``` 0C = 32F 100C = 212F 98.6F = 37C ``` Use `round_to(.., 1)` on the Fahrenheit-to-Celsius line so it prints `37` and not `36.99999999999999`. ### 3. Unit tests In `src/temperature.rs`, a `#[cfg(test)] mod tests` covering: - `c_to_f(0.0)` is `32.0` - `c_to_f(100.0)` is `212.0` - `f_to_c(32.0)` is `0.0` - `round_to(f_to_c(98.6), 1)` is `37.0` - `-40.0` is the fixed point: `c_to_f(-40.0)` is `-40.0` - a round-trip: `round_to(f_to_c(c_to_f(21.5)), 4)` is `21.5` Compare floats with an epsilon (`(a - b).abs() < 1e-9`), not `==`, except where the value is exactly representable. ## Acceptance - `cargo build` succeeds. - `cargo test` passes, with at least 6 tests. - `cargo clippy -- -D warnings` is clean. - No new dependencies. - `cargo run` prints the lines above, in that order. ## Notes This is a canary for the turn-completion fix that just deployed — the repo is trivial on purpose. If something blocks you, say plainly what stopped you rather than working around it.
toasterson changed title from WIP: Add a Celsius/Fahrenheit conversion module with rounding and unit tests to Add a Celsius/Fahrenheit conversion module with rounding and unit tests 2026-08-04 14:37:24 +00:00
toasterson force-pushed claude/wi-019fcd16-add-a-celsius-fahrenheit-conversion-modu from 4acf2f9100 to 2c7fb565f9 2026-08-16 09:20:09 +00:00 Compare
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
toasterson/anima-canary!7
No description provided.