chore: initialize containerized Go learning workbook (2026 DevOps/SRE)

This commit is contained in:
soda64 committed 2026-11-30 23:03:31 +01:00
commit 84be3e5d77
64 files changed
+1382

No files matched your search

@@ -0,0 +1,10 @@
# 03 — Struktury i Wskaźniki (Value vs Pointer Receivers)
## Zadania (`pointers.go`)
1. `BankAccount` z prywatnym polem `balance int`, metodami `Deposit(amount int)`, `Withdraw(amount int) bool`, `Balance() int`.
2. `IncrementAll(nums []int, delta int)` — zmodyfikuj elementy wycinka w miejscu.
## Uruchomienie testów
```bash
make test PKG=./exercises/01-core/03-structs-pointers
```
@@ -0,0 +1,25 @@
package pointers
type BankAccount struct {
balance int
}
func NewBankAccount(initial int) *BankAccount {
panic("TODO: zwróć &BankAccount{balance: initial}")
}
func (a *BankAccount) Deposit(amount int) {
panic("TODO: dodaj amount jeśli > 0")
}
func (a *BankAccount) Withdraw(amount int) bool {
panic("TODO: wypłać jeśli amount > 0 && a.balance >= amount")
}
func (a *BankAccount) Balance() int {
return a.balance
}
func IncrementAll(nums []int, delta int) {
panic("TODO: zwiększ każdy element nums o delta w miejscu")
}
@@ -0,0 +1,28 @@
package pointers
import (
"reflect"
"testing"
)
func TestBankAccount(t *testing.T) {
acc := NewBankAccount(100)
acc.Deposit(50)
if acc.Balance() != 150 {
t.Fatalf("got %d, want 150", acc.Balance())
}
if !acc.Withdraw(40) || acc.Balance() != 110 {
t.Fatalf("withdraw failed, balance=%d", acc.Balance())
}
if acc.Withdraw(500) || acc.Balance() != 110 {
t.Fatalf("expected overdraft rejection, balance=%d", acc.Balance())
}
}
func TestIncrementAll(t *testing.T) {
nums := []int{1, 2, 3}
IncrementAll(nums, 10)
if !reflect.DeepEqual(nums, []int{11, 12, 13}) {
t.Fatalf("got %v, want [11 12 13]", nums)
}
}