Skip to content

Commit

Permalink
Merge pull request #8 from peterhellberg/ph/short-test-of-uniques
Browse files Browse the repository at this point in the history
test: Allow the use of the `-short` flag (`1K` iterations instead of `1M`)
  • Loading branch information
peterhellberg authored Aug 28, 2023
2 parents 8016418 + c09f356 commit 1acb030
Showing 1 changed file with 75 additions and 70 deletions.
145 changes: 75 additions & 70 deletions uniques_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,103 +5,108 @@ import (
"testing"
)

const upper = 1_000_000
func TestUniques(t *testing.T) {
u := upper()

func TestUniquesWithPadding(t *testing.T) {
minLength := len(DefaultAlphabet)
s, err := NewCustom(Options{
MinLength: &minLength,
})
if err != nil {
t.Fatal(err)
}
t.Run("WithPadding", func(t *testing.T) {
minLength := len(DefaultAlphabet)

s, err := NewCustom(Options{
MinLength: &minLength,
})
if err != nil {
t.Fatal(err)
}

set := make(map[string]struct{})

set := make(map[string]struct{})
for i := uint64(0); i < u; i++ {
numbers := []uint64{i}

for i := uint64(0); i < upper; i++ {
numbers := []uint64{i}
id, _ := s.Encode(numbers)
set[id] = struct{}{}
id, _ := s.Encode(numbers)
set[id] = struct{}{}

decodedNumbers := s.Decode(id)
if !reflect.DeepEqual(numbers, decodedNumbers) {
t.Errorf("Decoding `%v` should produce `%v`, but instead produced `%v`", id, numbers, decodedNumbers)
decodedNumbers := s.Decode(id)
if !reflect.DeepEqual(numbers, decodedNumbers) {
t.Errorf("Decoding `%v` should produce `%v`, but instead produced `%v`", id, numbers, decodedNumbers)
}
}
}

if len(set) != upper {
t.Errorf("Invalid set count")
}
}
if len(set) != int(u) {
t.Errorf("Invalid set count")
}
})

func TestUniquesLowRanges(t *testing.T) {
s, err := New()
if err != nil {
t.Fatal(err)
}

set := make(map[string]struct{})
t.Run("LowRanges", func(t *testing.T) {
set := make(map[string]struct{})

for i := uint64(0); i < u; i++ {
numbers := []uint64{i}

for i := uint64(0); i < upper; i++ {
numbers := []uint64{i}
id, _ := s.Encode(numbers)
set[id] = struct{}{}
id, _ := s.Encode(numbers)
set[id] = struct{}{}

decodedNumbers := s.Decode(id)
if !reflect.DeepEqual(numbers, decodedNumbers) {
t.Errorf("Decoding `%v` should produce `%v`, but instead produced `%v`", id, numbers, decodedNumbers)
decodedNumbers := s.Decode(id)
if !reflect.DeepEqual(numbers, decodedNumbers) {
t.Errorf("Decoding `%v` should produce `%v`, but instead produced `%v`", id, numbers, decodedNumbers)
}
}
}

if len(set) != upper {
t.Errorf("Invalid set count")
}
}
if len(set) != int(u) {
t.Errorf("Invalid set count")
}
})

func TestUniquesHighRanges(t *testing.T) {
s, err := New()
if err != nil {
t.Fatal(err)
}
t.Run("HighRanges", func(t *testing.T) {
set := make(map[string]struct{})

set := make(map[string]struct{})
for i := uint64(100_000_000); i < 100_000_000+u; i++ {
numbers := []uint64{i}

for i := uint64(100_000_000); i < 100_000_000+upper; i++ {
numbers := []uint64{i}
id, _ := s.Encode(numbers)
set[id] = struct{}{}
id, _ := s.Encode(numbers)
set[id] = struct{}{}

decodedNumbers := s.Decode(id)
if !reflect.DeepEqual(numbers, decodedNumbers) {
t.Errorf("Decoding `%v` should produce `%v`, but instead produced `%v`", id, numbers, decodedNumbers)
decodedNumbers := s.Decode(id)
if !reflect.DeepEqual(numbers, decodedNumbers) {
t.Errorf("Decoding `%v` should produce `%v`, but instead produced `%v`", id, numbers, decodedNumbers)
}
}
}

if len(set) != upper {
t.Errorf("Invalid set count")
}
}
if len(set) != int(u) {
t.Errorf("Invalid set count")
}
})

func TestUniquesMulti(t *testing.T) {
s, err := New()
if err != nil {
t.Fatal(err)
}
t.Run("Multi", func(t *testing.T) {
set := make(map[string]struct{})

set := make(map[string]struct{})
for i := uint64(0); i < u; i++ {
numbers := []uint64{i, i, i, i, i}

for i := uint64(0); i < upper; i++ {
numbers := []uint64{i, i, i, i, i}
id, _ := s.Encode(numbers)
set[id] = struct{}{}
id, _ := s.Encode(numbers)
set[id] = struct{}{}

decodedNumbers := s.Decode(id)
if !reflect.DeepEqual(numbers, decodedNumbers) {
t.Errorf("Decoding `%v` should produce `%v`, but instead produced `%v`", id, numbers, decodedNumbers)
decodedNumbers := s.Decode(id)
if !reflect.DeepEqual(numbers, decodedNumbers) {
t.Errorf("Decoding `%v` should produce `%v`, but instead produced `%v`", id, numbers, decodedNumbers)
}
}
}

if len(set) != upper {
t.Errorf("Invalid set count")
if len(set) != int(u) {
t.Errorf("Invalid set count")
}
})
}

func upper() uint64 {
if testing.Short() {
return 1_000
}

return 1_000_000
}

0 comments on commit 1acb030

Please sign in to comment.