Files

27 lines
704 B
Go
Raw Permalink Normal View History

package utils
import (
"testing"
"time"
)
func TestCalcAge_NilBirthDate(t *testing.T) {
if age := CalcAge(nil); age != 0 {
t.Fatalf("expected 0 for nil birth date, got %d", age)
}
}
func TestCalcAge_BirthdayAlreadyPassedThisYear(t *testing.T) {
birth := time.Now().AddDate(-25, -1, 0) // ۲۵ سال و ۱ ماه پیش -> تولد امسال رد شده
if age := CalcAge(&birth); age != 25 {
t.Fatalf("expected age 25, got %d", age)
}
}
func TestCalcAge_BirthdayNotYetThisYear(t *testing.T) {
birth := time.Now().AddDate(-25, 1, 0) // تولد ۱ ماه دیگه‌ست -> هنوز ۲۴ سالشه
if age := CalcAge(&birth); age != 24 {
t.Fatalf("expected age 24, got %d", age)
}
}