go-predictive-name-generator/generate-name_test.go

58 lines
1.3 KiB
Go
Raw Normal View History

2024-06-04 17:34:27 +00:00
package gopredictivenamegenerator
import (
"hash/crc32"
"hash/crc64"
"math/rand"
"testing"
"github.com/stretchr/testify/assert"
)
// this string was found to return "boring-wozniak" when run with the
// predictive option. (This will change if the lists are altered.)
const seedString string = "1717521489308073576"
func TestNew(t *testing.T) {
n := New()
assert.IsType(t, NameGenerator{}, n)
}
func TestGetRandomName(t *testing.T) {
var n NameGenerator
testingSeed := crc64.Checksum([]byte(seedString), crc64.MakeTable(crc32.IEEE))
n.rand = rand.New(rand.NewSource(int64(testingSeed)))
name := n.GetRandom()
assert.Equal(t, name, "elegant-solomon")
}
func TestGetRandomNameExclude(t *testing.T) {
n := New()
// this value will select "boring-wozniak".
n.rand = rand.New(rand.NewSource(1717521489308012347))
name := n.GetRandom()
assert.Equal(t, name, "infallible-varahamihira")
}
func TestGetPredictiveName(t *testing.T) {
var n NameGenerator
name := n.GetPredictive(seedString)
assert.EqualValues(t, name, "elegant-solomon")
}
func TestExclusions(t *testing.T) {
answer := exclusions("boring-wozniak")
assert.True(t, answer)
answer = exclusions("sane-beeblebrox")
assert.True(t, answer)
answer = exclusions("sane-jannings")
assert.False(t, answer)
}