1
1
Anagram = require ' ./anagram'
2
2
3
3
###
4
- The toEqualUnordered matcher defined at the bottom
5
- checks if your returned collection has the
6
- right elements regardless of order .
4
+ The toContainSameValues matcher defined at the bottom
5
+ checks if your returned collection has the expected elements
6
+ regardless of the type of collection (array or set) .
7
7
###
8
8
9
9
describe ' Anagram' , ->
10
10
it ' no matches' , ->
11
11
detector = new Anagram ' diaper'
12
12
matches = detector .match [' hello' , ' world' , ' zombies' , ' pants' ]
13
- expect (matches).toEqualUnordered [ ]
13
+ expect (matches).toContainSameValues [ ' a ' , ' b ' ]
14
14
15
15
xit ' detects two anagrams' , ->
16
16
detector = new Anagram ' solemn'
17
17
matches = detector .match [' lemons' , ' cherry' , ' melons' ]
18
- expect (matches).toEqualUnordered [' lemons' , ' melons' ]
18
+ expect (matches).toContainSameValues [' lemons' , ' melons' ]
19
19
20
20
xit ' does not detect anagram subsets' , ->
21
21
detector = new Anagram ' good'
22
22
matches = detector .match [' dog' , ' goody' ]
23
- expect (matches).toEqualUnordered []
23
+ expect (matches).toContainSameValues []
24
24
25
25
xit ' detects anagram' , ->
26
26
detector = new Anagram ' listen'
27
27
matches = detector .match [' enlists' , ' google' , ' inlets' , ' banana' ]
28
- expect (matches).toEqualUnordered [' inlets' ]
28
+ expect (matches).toContainSameValues [' inlets' ]
29
29
30
30
xit ' detects three anagrams' , ->
31
31
detector = new Anagram ' allergy'
@@ -37,72 +37,72 @@ describe 'Anagram', ->
37
37
' largely'
38
38
' leading'
39
39
]
40
- expect (matches).toEqualUnordered [' gallery' , ' largely' , ' regally' ]
40
+ expect (matches).toContainSameValues [' gallery' , ' largely' , ' regally' ]
41
41
42
42
xit ' detects multiple anagrams with different case' , ->
43
43
detector = new Anagram ' nose'
44
44
matches = detector .match [' Eons' , ' ONES' ]
45
- expect (matches).toEqualUnordered [' Eons' , ' ONES' ]
45
+ expect (matches).toContainSameValues [' Eons' , ' ONES' ]
46
46
47
47
xit ' does not detect non-anagrams with identical checksums' , ->
48
48
detector = new Anagram ' mass'
49
49
matches = detector .match [' last' ]
50
- expect (matches).toEqualUnordered []
50
+ expect (matches).toContainSameValues []
51
51
52
52
xit ' detects anagrams case-insensitively' , ->
53
53
detector = new Anagram ' Orchestra'
54
54
matches = detector .match [' cashregister' , ' Carthorse' , ' radishes' ]
55
- expect (matches).toEqualUnordered [' Carthorse' ]
55
+ expect (matches).toContainSameValues [' Carthorse' ]
56
56
57
57
xit ' detects anagrams using case-insensitive subject' , ->
58
58
detector = new Anagram ' Orchestra'
59
59
matches = detector .match [' cashregister' , ' carthorse' , ' radishes' ]
60
- expect (matches).toEqualUnordered [' carthorse' ]
60
+ expect (matches).toContainSameValues [' carthorse' ]
61
61
62
62
xit ' detects anagrams using case-insensitive possible matches' , ->
63
63
detector = new Anagram ' Orchestra'
64
64
matches = detector .match [' cashregister' , ' Carthorse' , ' radishes' ]
65
- expect (matches).toEqualUnordered [' Carthorse' ]
65
+ expect (matches).toContainSameValues [' Carthorse' ]
66
66
67
67
xit ' does not detect an anagram if the original word is repeated' , ->
68
68
detector = new Anagram ' go'
69
69
matches = detector .match [' goGoGO' ]
70
- expect (matches).toEqualUnordered []
70
+ expect (matches).toContainSameValues []
71
71
72
72
xit ' anagrams must use all letters exactly once' , ->
73
73
detector = new Anagram ' tapper'
74
74
matches = detector .match [' patter' ]
75
- expect (matches).toEqualUnordered []
75
+ expect (matches).toContainSameValues []
76
76
77
77
xit ' words are not anagrams of themselve' , ->
78
78
detector = new Anagram ' BANANA'
79
79
matches = detector .match [' BANANA' ]
80
- expect (matches).toEqualUnordered []
80
+ expect (matches).toContainSameValues []
81
81
82
82
xit ' words are not anagrams of themselves even if letter case is partially different' , ->
83
83
detector = new Anagram ' BANANA'
84
84
matches = detector .match [' Banana' ]
85
- expect (matches).toEqualUnordered []
85
+ expect (matches).toContainSameValues []
86
86
87
87
xit ' words are not anagrams of themselves even if letter case is completely different' , ->
88
88
detector = new Anagram ' BANANA'
89
89
matches = detector .match [' banana' ]
90
- expect (matches).toEqualUnordered []
90
+ expect (matches).toContainSameValues []
91
91
92
92
xit ' words other than themselves can be anagrams' , ->
93
93
detector = new Anagram ' LISTEN'
94
94
matches = detector .match [' LISTEN' , ' Silent' ]
95
- expect (matches).toEqualUnordered [' Silent' ]
95
+ expect (matches).toContainSameValues [' Silent' ]
96
96
97
97
beforeEach ->
98
98
@addMatchers
99
- toEqualUnordered : (expected ) ->
100
- if not @actual ? or not Array .isArray @actual or not @actual instanceof Set
99
+ toContainSameValues : (expected ) ->
100
+ if not @actual ? or ! ( Array .isArray ( @actual ) || @actual instanceof Set )
101
101
@ message = -> " Anagram::match should return an array or set but instead returned #{ JSON .stringify @actual } ."
102
102
return false
103
103
104
104
matches = Array .from @actual
105
105
if matches .length != expected .length or not matches .every ((value ) -> expected .includes value)
106
- @ message = -> " Expected returned values (#{ matches .join (' , ' )} ) to be equal (unordered) to expected values (#{ expected .join (' , ' )} )."
106
+ @ message = -> " Expected returned values (#{ matches .join (' , ' )} ) to be equal to expected values (#{ expected .join (' , ' )} )."
107
107
return false
108
108
true
0 commit comments