Skip to content

Commit

Permalink
Added gosec
Browse files Browse the repository at this point in the history
  • Loading branch information
dooman87 committed Feb 3, 2025
1 parent 2ef3a56 commit 764ee04
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
11 changes: 7 additions & 4 deletions illustration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func main() {
count uint
currColor *imagick.PixelWand
pixelsCount = uint(0)
totalPixelsCount = float32(mw.GetImageHeight() * mw.GetImageWidth())
tenPercent = uint(totalPixelsCount * 0.1)
fiftyPercent = uint(totalPixelsCount * 0.5)
totalPixelsCount = mw.GetImageHeight() * mw.GetImageWidth()
tenPercent = totalPixelsCount / 10
fiftyPercent = totalPixelsCount / 2
isBackground = false
lastBackgroundColor *imagick.PixelWand
colorsInBackground = uint(0)
Expand Down Expand Up @@ -108,14 +108,17 @@ func main() {
pixelsInBackground = 0
} else {
pixelsCount += count
fiftyPercent = uint((totalPixelsCount - float32(pixelsInBackground)) * 0.5)
fiftyPercent = (totalPixelsCount - pixelsInBackground) / 2
}
}
default:
pixelsCount += count
}
}

if colorIdx < 0 {
log.Fatal("colorIdx < 0")
}
colorsCntIn50Pct := uint(colorIdx) - colorsInBackground

fmt.Print(colorsCntIn50Pct < 10 || (float32(colorsCntIn50Pct)/float32(colorsCnt)) <= 0.02)
Expand Down
16 changes: 16 additions & 0 deletions illustration/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import "testing"

func TestPercentage(t *testing.T) {

b := 1234
a := uint(float32(b) * 0.1)
if uint(b/10) != a {
t.Errorf("%d != %d", 1234/10, uint(float32(b)*0.1))
}

if a != uint(123) {
t.Errorf("%d != %d", a, uint(123))
}
}

0 comments on commit 764ee04

Please sign in to comment.