Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jedib0t committed Apr 22, 2024
1 parent 959dbff commit defca0f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 36 deletions.
2 changes: 1 addition & 1 deletion passphrase/default_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ func TestGenerate(t *testing.T) {
assert.NotEmpty(t, Generate())

SetSeed(1)
assert.Equal(t, "Holisms-Shark6-Elating", Generate())
assert.Equal(t, "Holism-Sharing6-Elates", Generate())
}
2 changes: 2 additions & 0 deletions passphrase/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ func (g *generator) sanitize() (Generator, error) {
slices.DeleteFunc(g.dictionary, func(word string) bool {
return len(word) < g.wordLenMin || len(word) > g.wordLenMax
})
slices.Sort(g.dictionary)
slices.Compact(g.dictionary)
if len(g.dictionary) < MinWordsInDictionary {
return nil, ErrDictionaryTooSmall
}
Expand Down
17 changes: 17 additions & 0 deletions passphrase/generator_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package passphrase

import (
"testing"

"github.com/stretchr/testify/assert"
)

func BenchmarkGenerator_Generate(b *testing.B) {
g, err := NewGenerator()
assert.Nil(b, err)
assert.NotEmpty(b, g.Generate())

for idx := 0; idx < b.N; idx++ {
_ = g.Generate()
}
}
32 changes: 10 additions & 22 deletions passphrase/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ import (
"github.com/stretchr/testify/assert"
)

func BenchmarkGenerator_Generate(b *testing.B) {
g, err := NewGenerator()
assert.Nil(b, err)
assert.NotEmpty(b, g.Generate())

for idx := 0; idx < b.N; idx++ {
_ = g.Generate()
}
}

func TestGenerator_Generate(t *testing.T) {
g, err := NewGenerator(
WithCapitalizedWords(true),
Expand All @@ -33,18 +23,16 @@ func TestGenerator_Generate(t *testing.T) {
g.SetSeed(1)

expectedPassphrases := []string{
"Sans-Liber-Quale1",
"Defogs-Tael0-Hallo",
"Medium-Leader-Sesame2",
"Chelae-Tocsin8-Haling",
"Taxies1-Sordor-Banner",
"Kwanza-Molies-Lapses5",
"Scurf-Hookas-Beryl4",
"Repine-Dele-Loans3",
"Furore0-Geneva-Celts",
"Strew7-Tweed-Sannop",
"Quasi7-Vino-Optic",
"Alible8-Sherds-Fraena",
"Sannup-Libels-Quaky1",
"Defog-Tads0-Hallel",
"Medina-Leaden-Servos2",
"Chela-Tocher8-Halids",
"Taxied1-Sordid-Banned",
"Kwacha-Molest-Lapser5",
"Scups-Hookah-Berths4",
"Repin-Delays-Loaner3",
"Furor0-Genets-Celt",
"Stress7-Twee-Sank",
}
var actualPhrases []string
for idx := 0; idx < 1000; idx++ {
Expand Down
17 changes: 17 additions & 0 deletions password/generator_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package password

import (
"testing"

"github.com/stretchr/testify/assert"
)

func BenchmarkGenerator_Generate(b *testing.B) {
g, err := NewGenerator()
assert.Nil(b, err)
assert.NotEmpty(b, g.Generate())

for idx := 0; idx < b.N; idx++ {
_ = g.Generate()
}
}
13 changes: 0 additions & 13 deletions password/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ import (
"github.com/stretchr/testify/assert"
)

func BenchmarkGenerator_Generate(b *testing.B) {
g, err := NewGenerator(
WithCharset(charset.AlphaNumeric.WithoutAmbiguity().WithoutDuplicates()),
WithLength(12),
)
assert.Nil(b, err)
assert.NotEmpty(b, g.Generate())

for idx := 0; idx < b.N; idx++ {
_ = g.Generate()
}
}

func TestGenerator_Generate(t *testing.T) {
g, err := NewGenerator(
WithCharset(charset.AlphaNumeric.WithoutAmbiguity().WithoutDuplicates()),
Expand Down

0 comments on commit defca0f

Please sign in to comment.