chore: initialize containerized Go learning workbook (2026 DevOps/SRE)
This commit is contained in:
commit
84be3e5d77
64 files changed
+1382
No files matched your search
@@ -0,0 +1,12 @@
|
||||
# 01 — Podstawy Go (`:=`, `if`, `switch`, `for`, multiple return values)
|
||||
|
||||
## Zadania (`basics.go`)
|
||||
1. `CelsiusToFahrenheit(c float64) float64` — $F = C \cdot 1.8 + 32$.
|
||||
2. `ClassifyScore(score int) string` — `switch` bez warunku: `0..49` -> `"fail"`, `50..74` -> `"pass"`, `75..89` -> `"good"`, `90..100` -> `"excellent"`, inaczej `"invalid"`.
|
||||
3. `SumUpTo(n int) int` — suma `1..n` włącznie (dla `<= 0` zwróć `0`).
|
||||
4. `DivMod(a, b int) (int, int, bool)` — zwróć `(iloraz, reszta, true)` lub `(0, 0, false)` przy `b == 0`.
|
||||
|
||||
## Uruchomienie testów
|
||||
```bash
|
||||
make test PKG=./exercises/01-core/01-basics
|
||||
```
|
||||
@@ -0,0 +1,17 @@
|
||||
package basics
|
||||
|
||||
func CelsiusToFahrenheit(c float64) float64 {
|
||||
panic("TODO: przelicz Celsjusze na Fahrenheity: c*1.8 + 32")
|
||||
}
|
||||
|
||||
func ClassifyScore(score int) string {
|
||||
panic("TODO: użyj switch do klasyfikacji 0..100 lub 'invalid'")
|
||||
}
|
||||
|
||||
func SumUpTo(n int) int {
|
||||
panic("TODO: zsumuj liczby od 1 do n włącznie")
|
||||
}
|
||||
|
||||
func DivMod(a, b int) (int, int, bool) {
|
||||
panic("TODO: zwróć (a/b, a%b, true) lub (0, 0, false) dla b == 0")
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package basics
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCelsiusToFahrenheit(t *testing.T) {
|
||||
if math.Abs(CelsiusToFahrenheit(0)-32) > 1e-9 {
|
||||
t.Fatalf("expected 32, got %v", CelsiusToFahrenheit(0))
|
||||
}
|
||||
if math.Abs(CelsiusToFahrenheit(100)-212) > 1e-9 {
|
||||
t.Fatalf("expected 212, got %v", CelsiusToFahrenheit(100))
|
||||
}
|
||||
}
|
||||
|
||||
func TestClassifyScore(t *testing.T) {
|
||||
cases := []struct {
|
||||
score int
|
||||
want string
|
||||
}{
|
||||
{0, "fail"}, {50, "pass"}, {80, "good"}, {95, "excellent"}, {101, "invalid"}, {-1, "invalid"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
if got := ClassifyScore(tc.score); got != tc.want {
|
||||
t.Errorf("ClassifyScore(%d) = %q, want %q", tc.score, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSumUpTo(t *testing.T) {
|
||||
if got := SumUpTo(0); got != 0 {
|
||||
t.Errorf("got %d, want 0", got)
|
||||
}
|
||||
if got := SumUpTo(10); got != 55 {
|
||||
t.Errorf("got %d, want 55", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDivMod(t *testing.T) {
|
||||
q, r, ok := DivMod(10, 3)
|
||||
if !ok || q != 3 || r != 1 {
|
||||
t.Fatalf("got (%d, %d, %v), want (3, 1, true)", q, r, ok)
|
||||
}
|
||||
if _, _, ok := DivMod(10, 0); ok {
|
||||
t.Fatal("expected ok=false for division by zero")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user