39 lines
898 B
Go
39 lines
898 B
Go
package validasi
|
|
|
|
import "testing"
|
|
|
|
func TestIsUsiaProduktif(t *testing.T) {
|
|
cases := []struct{
|
|
age int
|
|
want bool
|
|
}{
|
|
{17, false},
|
|
{18, true},
|
|
{30, true},
|
|
{60, true},
|
|
{61, false},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
got := IsUsiaProduktif(c.age)
|
|
if got != c.want {
|
|
t.Fatalf("IsUsiaProduktif(%d) = %v; want %v", c.age, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestValidateUsia(t *testing.T) {
|
|
if err := ValidateUsia(-1); err == nil {
|
|
t.Fatalf("expected error for negative age")
|
|
}
|
|
if err := ValidateUsia(18); err != nil {
|
|
t.Fatalf("unexpected error for age 18: %v", err)
|
|
}
|
|
if err := ValidateUsia(60); err != nil {
|
|
t.Fatalf("unexpected error for age 60: %v", err)
|
|
}
|
|
if err := ValidateUsia(61); err == nil {
|
|
t.Fatalf("expected error for age 61")
|
|
}
|
|
}
|