New assertion: ShouldNotBeChronological
diff --git a/README.md b/README.md
index 58e51e9..208a404 100644
--- a/README.md
+++ b/README.md
@@ -69,7 +69,7 @@
```go
func ShouldBeChronological(actual interface{}, expected ...interface{}) string
```
-ShouldBeChronological receives a []time.Time slice and asserts that the are in
+ShouldBeChronological receives a []time.Time slice and asserts that they are in
chronological order starting with the first time.Time as the earliest.
#### func ShouldBeEmpty
@@ -345,6 +345,14 @@
ShouldNotBeBlank receives exactly 1 string parameter and ensures that it is
equal to "".
+#### func ShouldNotBeChronological
+
+```go
+func ShouldNotBeChronological(actual interface{}, expected ...interface{}) string
+```
+ShouldNotBeChronological receives a []time.Time slice and asserts that they are
+NOT in chronological order.
+
#### func ShouldNotBeEmpty
```go
diff --git a/messages.go b/messages.go
index 6ed7dc2..bf9e640 100644
--- a/messages.go
+++ b/messages.go
@@ -94,4 +94,5 @@
// format params: incorrect-index, previous-index, previous-time, incorrect-index, incorrect-time
shouldHaveBeenChronological = "The 'Time' at index [%d] should have happened after the previous one (but it didn't!):\n [%d]: %s\n [%d]: %s (see, it happened before!)"
+ shouldNotHaveBeenchronological = "The provided times should NOT be chronological, but they were."
)
diff --git a/should/should.go b/should/should.go
index 2cc7bae..25d1342 100644
--- a/should/should.go
+++ b/should/should.go
@@ -72,6 +72,7 @@
HappenWithin = assertions.ShouldHappenWithin
NotHappenWithin = assertions.ShouldNotHappenWithin
BeChronological = assertions.ShouldBeChronological
+ NotBeChronological = assertions.ShouldNotBeChronological
BeError = assertions.ShouldBeError
)
diff --git a/time.go b/time.go
index 7e05026..918ee28 100644
--- a/time.go
+++ b/time.go
@@ -178,7 +178,7 @@
return ShouldNotHappenOnOrBetween(actualTime, min, max)
}
-// ShouldBeChronological receives a []time.Time slice and asserts that the are
+// ShouldBeChronological receives a []time.Time slice and asserts that they are
// in chronological order starting with the first time.Time as the earliest.
func ShouldBeChronological(actual interface{}, expected ...interface{}) string {
if fail := need(0, expected); fail != success {
@@ -200,3 +200,19 @@
}
return ""
}
+
+// ShouldNotBeChronological receives a []time.Time slice and asserts that they are
+// NOT in chronological order.
+func ShouldNotBeChronological(actual interface{}, expected ...interface{}) string {
+ if fail := need(0, expected); fail != success {
+ return fail
+ }
+ if _, ok := actual.([]time.Time); !ok {
+ return shouldUseTimeSlice
+ }
+ result := ShouldBeChronological(actual, expected...)
+ if result != "" {
+ return ""
+ }
+ return shouldNotHaveBeenchronological
+}
diff --git a/time_test.go b/time_test.go
index 6929962..c988589 100644
--- a/time_test.go
+++ b/time_test.go
@@ -142,6 +142,15 @@
this.pass(so([]time.Time{january1, january2, january3, january4, january5}, ShouldBeChronological))
}
+func (this *AssertionsFixture) TestShouldNotBeChronological() {
+ this.fail(so(0, ShouldNotBeChronological, 1, 2, 3), "This assertion requires exactly 0 comparison values (you provided 3).")
+ this.fail(so(0, ShouldNotBeChronological), shouldUseTimeSlice)
+ this.fail(so([]time.Time{january1, january5}, ShouldNotBeChronological),
+ "The provided times should NOT be chronological, but they were.")
+
+ this.pass(so([]time.Time{january2, january1, january3, january4, january5}, ShouldNotBeChronological))
+}
+
const layout = "2006-01-02 15:04"
var january1, _ = time.Parse(layout, "2013-01-01 00:00")