Skip to content

Commit

Permalink
optimized some error calls
Browse files Browse the repository at this point in the history
  • Loading branch information
duysqubix committed Oct 12, 2023
1 parent f590424 commit d878443
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
12 changes: 6 additions & 6 deletions tests/math_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pixel_test

import (
"fmt"
"math"
"testing"

Expand All @@ -10,10 +9,11 @@ import (

// closeEnough will shift the decimal point by the accuracy required, truncates the results and compares them.
// Effectively this compares two floats to a given decimal point.
// Example:
// closeEnough(100.125342432, 100.125, 2) == true
// closeEnough(math.Pi, 3.14, 2) == true
// closeEnough(0.1234, 0.1245, 3) == false
//
// Example:
// closeEnough(100.125342432, 100.125, 2) == true
// closeEnough(math.Pi, 3.14, 2) == true
// closeEnough(0.1234, 0.1245, 3) == false
func closeEnough(got, expected float64, decimalAccuracy int) bool {
gotShifted := got * math.Pow10(decimalAccuracy)
expectedShifted := expected * math.Pow10(decimalAccuracy)
Expand All @@ -40,7 +40,7 @@ func TestClamp(t *testing.T) {
for _, tc := range tests {
result := pixel.Clamp(tc.number, tc.min, tc.max)
if result != tc.expected {
t.Error(fmt.Sprintf("Clamping %v with min %v and max %v should have given %v, but gave %v", tc.number, tc.min, tc.max, tc.expected, result))
t.Errorf("Clamping %v with min %v and max %v should have given %v, but gave %v", tc.number, tc.min, tc.max, tc.expected, result)
}
}
}
3 changes: 1 addition & 2 deletions tests/vector_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pixel_test

import (
"fmt"
"testing"

"github.com/gopxl/pixel/v2"
Expand All @@ -21,7 +20,7 @@ func TestFloor(t *testing.T) {
for _, tc := range tests {
result := tc.input.Floor()
if result != tc.expected {
t.Error(fmt.Sprintf("Expected %v but got %v", tc.expected, result))
t.Errorf("Expected %v but got %v", tc.expected, result)
}
}
}

0 comments on commit d878443

Please sign in to comment.