Skip to content

Commit

Permalink
simplify sign casts
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed Jul 26, 2022
1 parent dfd6ae3 commit 4b08bf1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
18 changes: 9 additions & 9 deletions pkg/util/partition_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ var _ = Describe("Partition Message", func() {
}

testString := ""
for inputLen := uint(1); inputLen < 8000; inputLen++ {
for inputLen := 1; inputLen < 8000; inputLen++ {
// add a rune to the string using a repeatable pattern (single digit hex of position)
testString += strconv.FormatInt(int64(inputLen%16), 16)
items, omitted := PartitionMessage(testString, unalignedLimits, 7)
included := 0
for ii, item := range items {
expectedSize := unalignedLimits.ChunkSize
expectedSize := int(unalignedLimits.ChunkSize)

// The last chunk might be smaller than the preceeding chunks
if ii == len(items)-1 {
// the chunk size is the remainder of, the total size,
// or the max size, whatever is smallest,
// and the previous chunk sizes
chunkSize := UMin(inputLen, unalignedLimits.TotalChunkSize) % unalignedLimits.ChunkSize
chunkSize := Min(inputLen, int(unalignedLimits.TotalChunkSize)) % int(unalignedLimits.ChunkSize)
// if the "rest" of the runes needs another chunk
if chunkSize > 0 {
// expect the chunk to contain the "rest" of the runes
Expand All @@ -88,8 +88,8 @@ var _ = Describe("Partition Message", func() {
for ri, r := range item.Text {
runeOffset := (len(item.Text) - ri) - 1
runeVal, err := strconv.ParseUint(string(r), 16, 64)
expectedLen := UMin(inputLen, unalignedLimits.TotalChunkSize)
expectedVal := (expectedLen - uint(runeOffset)) % 16
expectedLen := Min(inputLen, int(unalignedLimits.TotalChunkSize))
expectedVal := (expectedLen - runeOffset) % 16

Expect(err).ToNot(HaveOccurred())
Expect(runeVal).To(BeEquivalentTo(expectedVal))
Expand Down Expand Up @@ -161,17 +161,17 @@ func testMessageItemsFromLines(hundreds int, limits types.MessageLimit, repeat i
return
}

func testPartitionMessage(hundreds uint, limits types.MessageLimit, distance int) (items []types.MessageItem, omitted int) {
func testPartitionMessage(hundreds int, limits types.MessageLimit, distance int) (items []types.MessageItem, omitted int) {
builder := strings.Builder{}

for i := uint(0); i < hundreds; i++ {
for i := 0; i < hundreds; i++ {
builder.WriteString(hundredChars)
}

items, omitted = PartitionMessage(builder.String(), limits, distance)

contentSize := UMin(hundreds*100, limits.TotalChunkSize)
expectedOmitted := UMax(0, (hundreds*100)-contentSize)
contentSize := Min(hundreds*100, int(limits.TotalChunkSize))
expectedOmitted := Max(0, (hundreds*100)-contentSize)

ExpectWithOffset(0, omitted).To(BeEquivalentTo(expectedOmitted))

Expand Down
16 changes: 0 additions & 16 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ func Min(a int, b int) int {
return b
}

// UMin returns the smallest of a and b
func UMin(a uint, b uint) uint {
if a < b {
return a
}
return b
}

// Max returns the largest of a and b
func Max(a int, b int) int {
if a > b {
Expand All @@ -29,13 +21,5 @@ func Max(a int, b int) int {
return b
}

// UMax returns the largest of a and b
func UMax(a uint, b uint) uint {
if a > b {
return a
}
return b
}

// DiscardLogger is a logger that discards any output written to it
var DiscardLogger = log.New(ioutil.Discard, "", 0)

0 comments on commit 4b08bf1

Please sign in to comment.