Repository: MarvinJWendt/testza
Pull request #153 (2022-04-10 00:04:33)

Added `AssertLessOrEqual` and `AssertGreaterOrEqual`


Patch:
diff --git a/README.md b/README.md
index 0e35483..cbd5577 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@
 </a>
 
 <a href="https://codecov.io/gh/MarvinJWendt/testza">
-<!-- unittestcount:start --><img src="https://img.shields.io/badge/Unit_Tests-3213-magenta?style=flat-square" alt="Unit test count"><!-- unittestcount:end -->
+<!-- unittestcount:start --><img src="https://img.shields.io/badge/Unit_Tests-3215-magenta?style=flat-square" alt="Unit test count"><!-- unittestcount:end -->
 </a>
   
 <a href="https://pkg.go.dev/github.com/MarvinJWendt/testza" target="_blank">
@@ -168,11 +168,13 @@ testza.FuzzStringRunTests(t, emailAddresses, func(t *testing.T, index int, str s
   - [AssertFalse](https://github.com/MarvinJWendt/testza#AssertFalse)
   - [AssertFileExists](https://github.com/MarvinJWendt/testza#AssertFileExists)
   - [AssertGreater](https://github.com/MarvinJWendt/testza#AssertGreater)
+  - [AssertGreaterOrEqual](https://github.com/MarvinJWendt/testza#AssertGreaterOrEqual)
   - [AssertImplements](https://github.com/MarvinJWendt/testza#AssertImplements)
   - [AssertIncreasing](https://github.com/MarvinJWendt/testza#AssertIncreasing)
   - [AssertKindOf](https://github.com/MarvinJWendt/testza#AssertKindOf)
   - [AssertLen](https://github.com/MarvinJWendt/testza#AssertLen)
   - [AssertLess](https://github.com/MarvinJWendt/testza#AssertLess)
+  - [AssertLessOrEqual](https://github.com/MarvinJWendt/testza#AssertLessOrEqual)
   - [AssertNil](https://github.com/MarvinJWendt/testza#AssertNil)
   - [AssertNoDirExists](https://github.com/MarvinJWendt/testza#AssertNoDirExists)
   - [AssertNoError](https://github.com/MarvinJWendt/testza#AssertNoError)
@@ -538,6 +540,25 @@ Example:
     testza.AssertGreater(t, 5, 1)
     testza.AssertGreater(t, 10, -10)
 
+#### AssertGreaterOrEqual
+
+```go
+func AssertGreaterOrEqual(t testRunner, object1, object2 interface{}, msg ...interface{})
+```
+
+AssertGreaterOrEqual asserts that the first object is greater than or equal
+to the second.
+
+When using a custom message, the same formatting as with fmt.Sprintf() is
+used.
+
+Example:
+
+    testza.AssertGreaterOrEqual(t, 5, 1)
+    testza.AssertGreaterOrEqual(t, 10, -10)
+
+testza.AssertGreaterOrEqual(t, 10, 10)
+
 #### AssertImplements
 
 ```go
@@ -627,6 +648,24 @@ Example:
     testza.AssertLess(t, 1, 5)
     testza.AssertLess(t, -10, 10)
 
+#### AssertLessOrEqual
+
+```go
+func AssertLessOrEqual(t testRunner, object1, object2 interface{}, msg ...interface{})
+```
+
+AssertLessOrEqual asserts that the first object is less than or equal to the
+second.
+
+When using a custom message, the same formatting as with fmt.Sprintf() is
+used.
+
+Example:
+
+    testza.AssertLessOrEqual(t, 1, 5)
+    testza.AssertLessOrEqual(t, -10, 10)
+    testza.AssertLessOrEqual(t, 1, 1)
+
 #### AssertNil
 
 ```go
diff --git a/assert.go b/assert.go
index fb7db22..df608ec 100644
--- a/assert.go
+++ b/assert.go
@@ -565,6 +565,31 @@ func AssertGreater(t testRunner, object1, object2 interface{}, msg ...interface{
 	}
 }
 
+// AssertGreaterOrEqual asserts that the first object is greater than or equal to the second.
+//
+// When using a custom message, the same formatting as with fmt.Sprintf() is used.
+//
+// Example:
+//  testza.AssertGreaterOrEqual(t, 5, 1)
+//  testza.AssertGreaterOrEqual(t, 10, -10)
+// testza.AssertGreaterOrEqual(t, 10, 10)
+func AssertGreaterOrEqual(t testRunner, object1, object2 interface{}, msg ...interface{}) {
+	if test, ok := t.(helper); ok {
+		test.Helper()
+	}
+
+	v1, err := strconv.ParseFloat(fmt.Sprint(object1), 64)
+	v2, err2 := strconv.ParseFloat(fmt.Sprint(object2), 64)
+
+	if err != nil || err2 != nil {
+		internal.Fail(t, "An error occurred while parsing the objects as numbers.", internal.NewObjectsUnknown(object1, object2), msg...)
+	}
+
+	if !(v1 >= v2) {
+		internal.Fail(t, "An object that !!should be greater!! than the second object is not.", internal.Objects{{Name: "Object 1", Data: object1}, {Name: "Should be greater than object 2", Data: object2}}, msg...)
+	}
+}
+
 // AssertLess asserts that the first object is less than the second.
 //
 // When using a custom message, the same formatting as with fmt.Sprintf() is used.
@@ -592,6 +617,34 @@ func AssertLess(t testRunner, object1, object2 interface{}, msg ...interface{})
 	}
 }
 
+// AssertLessOrEqual asserts that the first object is less than or equal to the second.
+//
+// When using a custom message, the same formatting as with fmt.Sprintf() is used.
+//
+// Example:
+//  testza.AssertLessOrEqual(t, 1, 5)
+//  testza.AssertLessOrEqual(t, -10, 10)
+//  testza.AssertLessOrEqual(t, 1, 1)
+func AssertLessOrEqual(t testRunner, object1, object2 interface{}, msg ...interface{}) {
+	if test, ok := t.(helper); ok {
+		test.Helper()
+	}
+
+	v1, err := strconv.ParseFloat(fmt.Sprint(object1), 64)
+	v2, err2 := strconv.ParseFloat(fmt.Sprint(object2), 64)
+
+	if err != nil || err2 != nil {
+		internal.Fail(t, "An error occurred while parsing the objects as numbers.", internal.NewObjectsUnknown(object1, object2), msg...)
+	}
+
+	if !(v1 <= v2) {
+		internal.Fail(t, "An object that !!should be less or equal!! than the second object is not.", internal.Objects{
+			internal.NewObjectsSingleNamed("Should be less or equal to", object1)[0],
+			internal.NewObjectsSingleNamed("Actual", object2)[0],
+		}, msg...)
+	}
+}
+
 // AssertTestFails asserts that a unit test fails.
 // A unit test fails if one of the following methods is called in the test function: Error, Errorf, Fail, FailNow, Fatal, Fatalf
 //
diff --git a/go.mod b/go.mod
index b021d12..a5a0580 100644
--- a/go.mod
+++ b/go.mod
@@ -7,4 +7,5 @@ require (
 	github.com/klauspost/cpuid/v2 v2.0.12
 	github.com/pterm/pterm v0.12.40
 	github.com/sergi/go-diff v1.2.0
+	github.com/stretchr/testify v1.7.0
 )


Test patch:
diff --git a/assert_test.go b/assert_test.go
index 363a8bd..2efe3a1 100644
--- a/assert_test.go
+++ b/assert_test.go
@@ -15,6 +15,7 @@ import (
 	"time"
 
 	"github.com/pterm/pterm"
+	"github.com/stretchr/testify/assert"
 
 	. "github.com/MarvinJWendt/testza"
 )
@@ -717,6 +718,26 @@ func TestAssertGreater_fails(t *testing.T) {
 	AssertTestFails(t, func(t TestingPackageWithFailFunctions) {
 		AssertGreater(t, 4, 5)
 	})
+
+	AssertTestFails(t, func(t TestingPackageWithFailFunctions) {
+		AssertGreater(t, 5, 5)
+	})
+}
+
+func TestAssertGreaterOrEqual(t *testing.T) {
+	assert.GreaterOrEqual(t, 2, 1)
+	assert.GreaterOrEqual(t, 5, 4)
+	assert.GreaterOrEqual(t, 5, 5)
+}
+
+func TestAssertGreaterOrEqual_fails(t *testing.T) {
+	AssertTestFails(t, func(t TestingPackageWithFailFunctions) {
+		assert.GreaterOrEqual(t, 1, 2)
+	})
+
+	AssertTestFails(t, func(t TestingPackageWithFailFunctions) {
+		assert.GreaterOrEqual(t, 4, 5)
+	})
 }
 
 func TestAssertLess(t *testing.T) {
@@ -732,6 +753,26 @@ func TestAssertLess_fails(t *testing.T) {
 	AssertTestFails(t, func(t TestingPackageWithFailFunctions) {
 		AssertLess(t, 5, 4)
 	})
+
+	AssertTestFails(t, func(t TestingPackageWithFailFunctions) {
+		AssertLess(t, 5, 5)
+	})
+}
+
+func TestAssertLessOrEqual(t *testing.T) {
+	AssertLessOrEqual(t, 1, 2)
+	AssertLessOrEqual(t, 4, 5)
+	AssertLessOrEqual(t, 5, 5)
+}
+
+func TestAssertLessOrEqual_fails(t *testing.T) {
+	AssertTestFails(t, func(t TestingPackageWithFailFunctions) {
+		AssertLessOrEqual(t, 2, 1)
+	})
+
+	AssertTestFails(t, func(t TestingPackageWithFailFunctions) {
+		AssertLessOrEqual(t, 5, 4)
+	})
 }
 
 func TestAssertTestFails(t *testing.T) {