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,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