chore: initialize containerized Rust learning workbook

This commit is contained in:
soda64 committed 2026-11-30 22:07:47 +01:00
commit 05ffbd18bf
23 files changed
+549

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
[package]
name = "ex01-basics"
version = "0.1.0"
edition = "2021"
+18
View File
@@ -0,0 +1,18 @@
# 01 — Podstawy (Basics)
## Zakres
* Zmienne (`let`, `let mut`), shadowing
* Typy skalarne (`i32`, `u32`, `f64`, `bool`, `char`)
* Funkcje, wyrażenia vs instrukcje (*expressions vs statements*)
* Przepływ sterowania (`if`, `loop`, `while`, `for`)
## Zadania (`src/lib.rs`)
1. `celsius_to_fahrenheit(c: f64) -> f64` — przelicz temperaturę ze stopni Celsjusza na Fahrenheita ($F = C \cdot 1.8 + 32$).
2. `is_even(n: i32) -> bool` — zwróć `true`, jeśli liczba jest parzysta.
3. `sum_up_to(n: u32) -> u32` — oblicz sumę liczb od `1` do `n` włącznie (dla `0` zwróć `0`).
4. `fizzbuzz_label(n: u32) -> String` — klasyczny FizzBuzz dla pojedynczej liczby (`"Fizz"`, `"Buzz"`, `"FizzBuzz"` lub zapis liczby).
## Uruchomienie testów
```bash
make test PKG=ex01-basics
```
+53
View File
@@ -0,0 +1,53 @@
#![allow(unused_variables, dead_code)]
pub fn celsius_to_fahrenheit(c: f64) -> f64 {
todo!("Przelicz stopnie Celsjusza na Fahrenheita: c * 1.8 + 32.0")
}
pub fn is_even(n: i32) -> bool {
todo!("Zwróć true jeśli n jest parzyste")
}
pub fn sum_up_to(n: u32) -> u32 {
todo!("Zsumuj liczby od 1 do n włącznie")
}
pub fn fizzbuzz_label(n: u32) -> String {
todo!("Zwróć Fizz / Buzz / FizzBuzz lub n.to_string()")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn converts_temperatures() {
assert!((celsius_to_fahrenheit(0.0) - 32.0).abs() < f64::EPSILON);
assert!((celsius_to_fahrenheit(100.0) - 212.0).abs() < f64::EPSILON);
assert!((celsius_to_fahrenheit(-40.0) - (-40.0)).abs() < f64::EPSILON);
}
#[test]
fn checks_even_numbers() {
assert!(is_even(0));
assert!(is_even(42));
assert!(is_even(-8));
assert!(!is_even(7));
assert!(!is_even(-3));
}
#[test]
fn sums_range() {
assert_eq!(sum_up_to(0), 0);
assert_eq!(sum_up_to(1), 1);
assert_eq!(sum_up_to(10), 55);
}
#[test]
fn formats_fizzbuzz() {
assert_eq!(fizzbuzz_label(1), "1");
assert_eq!(fizzbuzz_label(3), "Fizz");
assert_eq!(fizzbuzz_label(5), "Buzz");
assert_eq!(fizzbuzz_label(15), "FizzBuzz");
}
}