Skip to content

Commit

Permalink
Fix logic for generating title with random gender
Browse files Browse the repository at this point in the history
  • Loading branch information
daisy1754 authored and Pallinder committed Jun 2, 2019
1 parent e7937a3 commit 26f4a64
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
11 changes: 3 additions & 8 deletions random_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,14 @@ func randomFrom(source []string) string {

// Title returns a random title, gender decides the gender of the name
func Title(gender int) string {
var title = ""
switch gender {
case Male:
title = randomFrom(jsonData.MaleTitles)
break
return randomFrom(jsonData.MaleTitles)
case Female:
title = randomFrom(jsonData.FemaleTitles)
break
return randomFrom(jsonData.FemaleTitles)
default:
title = FirstName(privateRand.Intn(2))
break
return Title(privateRand.Intn(2))
}
return title
}

// FirstName returns a random first name, gender decides the gender of the name
Expand Down
22 changes: 22 additions & 0 deletions random_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ func TestCustomRand(t *testing.T) {
}
}

func TestTitle(t *testing.T) {
t.Log("TestTitle")
titleMale := Title(Male)
titleFemale := Title(Female)
randomTitle := Title(100)

if !findInSlice(jsonData.MaleTitles, titleMale) {
t.Error("titleMale empty or not in male titles")
}

if !findInSlice(jsonData.FemaleTitles, titleFemale) {
t.Error("firstNameFemale empty or not in female titles")
}

names := make([]string, len(jsonData.MaleTitles)+len(jsonData.FemaleTitles))
names = append(names, jsonData.MaleTitles...)
names = append(names, jsonData.FemaleTitles...)
if !findInSlice(names, randomTitle) {
t.Error("randomName empty or not in male and female titles")
}
}

func TestRandomStringDigits(t *testing.T) {
t.Log("TestRandomStringDigits")

Expand Down

0 comments on commit 26f4a64

Please sign in to comment.