-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
154 lines (100 loc) · 3.37 KB
/
Copy pathtest.js
File metadata and controls
154 lines (100 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
const between = require('./index.js')
describe('between()', () => {
test('should be a higher order function',
() => {
const fn = between(100, 1000)
expect(typeof fn === 'function').toBe(true)
})
test('should return true if target number is between ranges',
() => {
const isBetween1And10 = between(1, 10)
let target = 5
expect(isBetween1And10(target)).toBe(true)
target = 10
expect(isBetween1And10(target)).toBe(false)
target = 1
expect(isBetween1And10(target)).toBe(false)
target = 11
expect(isBetween1And10(target)).toBe(false)
target = 0
expect(isBetween1And10(target)).toBe(false)
target = 2.2
expect(isBetween1And10(target)).toBe(true)
target = 2
expect(between(-Infinity, Infinity)(target)).toBe(true)
expect(between(3, 4, true)(4)).toBe(true)
})
test('should return true if target number is one of the boundaries.', () => {
expect(between(3, 4, true)(4)).toBe(true)
expect(between(3, 4, true)(3)).toBe(true)
})
test('should return true if target alphabet string is between ranges. ', () => {
let target = 'd'
expect(between('a', 'z')(target)).toBe(true)
target = 'a'
expect(between('a', 'z')(target)).toBe(false)
target = 'z'
expect(between('a', 'z')(target)).toBe(false)
target = 'z'
expect(between('a', 'b')(target)).toBe(false)
target = 'c'
expect(between('a', 'b')(target)).toBe(false)
target = 'C'
expect(between('a', 'b')(target)).toBe(false)
target = 'b'
expect(between('A', 'z')(target)).toBe(true)
})
test('should return true if target alphabet string is one of the ranges. ',
() => {
expect(between('a', 'b', true)('b')).toBe(true)
expect(between('a', 'b', true)('a')).toBe(true)
})
test('should return true if target Date is between ranges',
() => {
let myGraduation = new Date('October 13, 2014 11:13:00')
let myFirstJob = new Date('September 1, 2015 11:13:00')
let myBirthday = new Date('January 10, 2015 10:11:03')
expect(between(myGraduation, myFirstJob)(myBirthday)).toBe(true)
})
test('should return true if target Date is one of the boundaries.',
() => {
let myGraduation = new Date('October 13, 2014 11:13:00')
let myFirstJob = new Date('September 1, 2015 11:13:00')
let myBirthday = new Date('September 1, 2015 11:13:00')
expect(between(myGraduation, myFirstJob, true)(myBirthday)).toBe(true)
})
test('should throw error if args are not a valid an alphabet character', () => {
expect(() => {
between('#', '/')('%')
}).toThrow()
expect(() => {
between('💩', '💩')('💩')
}).toThrow()
expect(() => {
between(-Infinity, '💩')('💩')
}).toThrow()
})
test('should throw error if args are not of the same type', () => {
expect(() => {
between(1, 10)('s')
}).toThrow()
expect(() => {
between(1, '3')(2)
}).toThrow()
expect(() => {
between(new Date(), 2)(2)
}).toThrow()
})
test('should throw error if args are not numbers, strings or Dates',
() => {
expect(() => {
between(null, null)(null)
}).toThrow()
expect(() => {
between(undefined, undefined)(undefined)
}).toThrow()
expect(() => {
between({}, {})({})
}).toThrow()
})
})