Skip to content

Commit

Permalink
Fixing Currency test and add ExpectInInt and ExpectInString test help…
Browse files Browse the repository at this point in the history
…ers (#98)
  • Loading branch information
jaswdr authored Jul 3, 2022
1 parent fa03b4e commit 351f236
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
21 changes: 12 additions & 9 deletions currency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,35 @@ import (

func TestCurrency(t *testing.T) {
c := New().Currency()
NotExpect(t, "", c.Currency())
currency := c.Currency()
NotExpect(t, "", currency)
ExpectInString(t, currency, currencies)
}

func TestCurrencyCode(t *testing.T) {
c := New().Currency()
code := c.Code()
if code != "" {
Expect(t, 3, len(code))
}
NotExpect(t, "", code)
ExpectInString(t, code, currenciesCodes)
}

func TestCurrencyNumber(t *testing.T) {
c := New().Currency()
NotExpect(t, 0, c.Number())
ExpectInInt(t, c.Number(), currenciesNumbers)
}

func TestCurrencyCountry(t *testing.T) {
c := New().Currency()
NotExpect(t, "", c.Country())
country := c.Country()
NotExpect(t, "", country)
ExpectInString(t, country, currenciesCountries)
}

func TestCurrencyAndCode(t *testing.T) {
c := New().Currency()
currency, code := c.CurrencyAndCode()
NotExpect(t, "", currency)
if code != "" {
Expect(t, 3, len(code))
}
NotExpect(t, "", code)
ExpectInString(t, currency, currencies)
ExpectInString(t, code, currenciesCodes)
}
30 changes: 30 additions & 0 deletions faker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,36 @@ func NotExpect(t *testing.T, notExpected, got interface{}, values ...interface{}
}
}

func ExpectInInt(t *testing.T, expected int, in []int) {
t.Helper()
isIn := false
for _, v := range in {
if expected == v {
isIn = true
break
}
}

if !isIn {
t.FailNow()
}
}

func ExpectInString(t *testing.T, expected string, in []string) {
t.Helper()
isIn := false
for _, v := range in {
if expected == v {
isIn = true
break
}
}

if !isIn {
t.FailNow()
}
}

func F(t *testing.T) Faker {
return NewWithSeed(rand.NewSource(0))
}
Expand Down

0 comments on commit 351f236

Please sign in to comment.