feat: reorganize workbook into 3 tracks (core, engineering-2026, ecosystems)

This commit is contained in:
soda64 committed 2026-11-30 22:30:53 +01:00
1 parent 82677455b2
commit 2e002b6176
64 files changed
+2295 -196

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
[package]
name = "core01-basics"
version = "0.1.0"
edition = "2021"
+20
View File
@@ -0,0 +1,20 @@
# 01 — Podstawy, pętle, warunki i funkcje
## Zakres
* Zmienne (`let`, `let mut`), shadowing, typy skalarne, krotki i tablice
* Funkcje, wyrażenia vs instrukcje (*expressions vs statements*)
* Instrukcje warunkowe (`if` jako wyrażenie, `match` z zakresami i strażnikami `if`)
* Pętle (`loop` zwracające wartość, `while`, `for`)
## Zadania (`src/lib.rs`)
1. `celsius_to_fahrenheit(c: f64) -> f64` — przelicz temperaturę ($F = C \cdot 1.8 + 32$).
2. `classify_score(score: u8) -> &'static str` — użyj `match` z zakresami: `0..=49` -> `"fail"`, `50..=74` -> `"pass"`, `75..=89` -> `"good"`, `90..=100` -> `"excellent"`, powyżej `100` -> `"invalid"`.
3. `sum_up_to(n: u32) -> u32` — suma liczb od `1` do `n` włącznie (pętla `for`).
4. `first_power_of_two_gte(target: u32) -> u32` — znajdź najmniejszą potęgę dwójki $\ge \text{target}$ używając pętli `loop` lub `while` (np. dla `1` -> `1`, dla `5` -> `8`, dla `16` -> `16`).
5. `min_max(values: &[i32]) -> Option<(i32, i32)>` — zwróć krotkę `(min, max)` dla niepustego wycinka lub `None` dla pustego.
6. `fizzbuzz_label(n: u32) -> String` — `"Fizz"`, `"Buzz"`, `"FizzBuzz"` lub zapis liczby.
## Uruchomienie testów
```bash
make test PKG=core01-basics
```
+77
View File
@@ -0,0 +1,77 @@
#![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 classify_score(score: u8) -> &'static str {
todo!("Użyj match z zakresami 0..=49, 50..=74, 75..=89, 90..=100, _")
}
pub fn sum_up_to(n: u32) -> u32 {
todo!("Zsumuj liczby od 1 do n włącznie")
}
pub fn first_power_of_two_gte(target: u32) -> u32 {
todo!("Znajdź najmniejszą potęgę dwójki >= target (dla 0 lub 1 zwróć 1)")
}
pub fn min_max(values: &[i32]) -> Option<(i32, i32)> {
todo!("Zwróć Some((min, max)) lub None dla pustego wycinka")
}
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 classifies_scores_with_ranges() {
assert_eq!(classify_score(0), "fail");
assert_eq!(classify_score(49), "fail");
assert_eq!(classify_score(50), "pass");
assert_eq!(classify_score(80), "good");
assert_eq!(classify_score(95), "excellent");
assert_eq!(classify_score(101), "invalid");
}
#[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 finds_power_of_two() {
assert_eq!(first_power_of_two_gte(0), 1);
assert_eq!(first_power_of_two_gte(1), 1);
assert_eq!(first_power_of_two_gte(5), 8);
assert_eq!(first_power_of_two_gte(16), 16);
}
#[test]
fn computes_min_and_max() {
assert_eq!(min_max(&[]), None);
assert_eq!(min_max(&[42]), Some((42, 42)));
assert_eq!(min_max(&[3, -10, 7, 25, 0]), Some((-10, 25)));
}
#[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");
}
}