Skip to content

Commit

Permalink
refactor: replace custom random integer function with tester-utils me…
Browse files Browse the repository at this point in the history
…thod
  • Loading branch information
ryan-gang committed Dec 12, 2024
1 parent d995685 commit 7a78ebe
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions protocol/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package common

import (
"fmt"
"slices"
"sort"

"github.com/codecrafters-io/tester-utils/random"
Expand All @@ -26,7 +25,7 @@ var (
TOPIC1_NAME = topic_names[0]
TOPIC2_NAME = topic_names[1]
TOPIC3_NAME = topic_names[2]
random_topic_uuids = getUniqueRandomIntegers(10, 99, 3)
random_topic_uuids = random.RandomUniqueInts(10, 100, 3)
TOPIC1_UUID = fmt.Sprintf("00000000-0000-4000-8000-0000000000%02d", random_topic_uuids[0])
TOPIC2_UUID = fmt.Sprintf("00000000-0000-4000-8000-0000000000%02d", random_topic_uuids[1])
TOPIC3_UUID = fmt.Sprintf("00000000-0000-4000-8000-0000000000%02d", random_topic_uuids[2])
Expand All @@ -48,15 +47,3 @@ func GetSortedValues[T string](values []T) []T {
})
return values
}

func getUniqueRandomIntegers(min, max, count int) []int {
randomInts := []int{}
for i := 0; i < count; i++ {
randomInt := random.RandomInt(min, max)
for slices.Contains(randomInts, randomInt) {
randomInt = random.RandomInt(min, max)
}
randomInts = append(randomInts, randomInt)
}
return randomInts
}

0 comments on commit 7a78ebe

Please sign in to comment.