@@ -5,20 +5,13 @@ expect.output.preferredWidth = 80;
5
5
6
6
expect . use ( require ( '../lib/unexpected-check' ) ) ;
7
7
8
- expect . addAssertion ( '<number> to be less than or equal to all <array>' , function ( expect , subject , array ) {
9
- expect ( array , 'to have items satisfying' , expect . it ( 'to be greater than or equal to' , subject ) ) ;
10
- } ) ;
11
-
12
- expect . addAssertion ( '<number> to be greater than or equal to all <array>' , function ( expect , subject , array ) {
13
- expect ( array , 'to have items satisfying' , expect . it ( 'to be less than or equal to' , subject ) ) ;
14
- } ) ;
15
-
16
- expect . addAssertion ( '<array> first item <assertion>' , function ( expect , subject ) {
17
- return expect . shift ( subject [ 0 ] ) ;
18
- } ) ;
19
-
20
- expect . addAssertion ( '<array> last item <assertion>' , function ( expect , subject ) {
21
- return expect . shift ( subject [ subject . length - 1 ] ) ;
8
+ expect . addAssertion ( '<array> to be sorted' , function ( expect , subject ) {
9
+ var isSorted = subject . every ( function ( x , i ) {
10
+ return subject . slice ( i ) . every ( function ( y ) {
11
+ return x <= y ;
12
+ } ) ;
13
+ } ) ;
14
+ expect ( isSorted , 'to be true' ) ;
22
15
} ) ;
23
16
24
17
function sort ( arr , cmp ) {
@@ -39,8 +32,7 @@ describe('unexpected-check', function () {
39
32
var sorted = sort ( arr ) ;
40
33
41
34
expect ( sorted , 'to have length' , arr . length )
42
- . and ( 'first item to be less than or equal to all' , arr )
43
- . and ( 'last item to be greater than or equal to all' , arr ) ;
35
+ . and ( 'to be sorted' ) ;
44
36
} , 'to be valid for all' , {
45
37
generators : [ arrays ] ,
46
38
maxIterations : 50 ,
@@ -53,12 +45,7 @@ describe('unexpected-check', function () {
53
45
'\n' +
54
46
' Generated input: [ -1, -2 ]\n' +
55
47
'\n' +
56
- ' expected [ -1, -2 ] first item to be less than or equal to all [ -1, -2 ]\n' +
57
- '\n' +
58
- ' [\n' +
59
- ' -1,\n' +
60
- ' -2 // should be greater than or equal to -1\n' +
61
- ' ]' ) ;
48
+ ' expected [ -1, -2 ] to be sorted' ) ;
62
49
} ) ;
63
50
64
51
it ( 'find errors in the specification' , function ( ) {
@@ -84,8 +71,7 @@ describe('unexpected-check', function () {
84
71
var sorted = sort ( arr , function ( a , b ) { return a - b ; } ) ;
85
72
86
73
expect ( sorted , 'to have length' , arr . length )
87
- . and ( 'first item to be less than or equal to all' , arr )
88
- . and ( 'last item to be greater than or equal to all' , arr ) ;
74
+ . and ( 'to be sorted' ) ;
89
75
} , 'to be valid for all' , arrays ) ;
90
76
} ) ;
91
77
0 commit comments