26 lines
471 B
Go
26 lines
471 B
Go
package creditcards_test
|
|
|
|
import (
|
|
"creditcards"
|
|
"testing"
|
|
)
|
|
|
|
func TestNew(t *testing.T) {
|
|
t.Parallel()
|
|
want := "1234567890"
|
|
cc, err := creditcards.New(want)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := cc.Number()
|
|
if want != got {
|
|
t.Errorf("want %q, got %q", want, got)
|
|
}
|
|
}
|
|
func TestNewInvalidReturnsError(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := creditcards.New("")
|
|
if err == nil {
|
|
t.Fatal("want error for invalid card number, got nil")
|
|
}
|
|
} |