nickel 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,55 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'compare.rb')
2
- require 'pp'
3
-
4
- module NLPTestsHelper
5
-
6
- # Removing pretty print and pretty_inspect dramatically improves test time.
7
- PRETTY = false
8
-
9
- def assert_nlp(nlpobj, occ_array)
10
- nlp_occ_array = nlpobj.parse
11
- inspect_method = PRETTY ? :pretty_inspect : :inspect
12
- compare = Compare::ArrayofObjects.new(nlp_occ_array, occ_array)
13
- err_msg = "\n\n\e[44mExpected\e[0m\n " + occ_array.send(inspect_method) +
14
- "\n\n\e[44mGot\e[0m\n " + nlp_occ_array.send(inspect_method) +
15
- "\n\n" + nlpobj.debug_str(inspect_method)
16
- assert_block(err_msg){ compare.same? }
17
- end
18
-
19
- def assert_message(nlpobj, expected_message)
20
- nlpobj.parse
21
- message = nlpobj.message
22
- err_msg = "\n\nQuery:\n" + nlpobj.query +
23
- "\n\n\e[44mExpected Message\e[0m\n" + expected_message.inspect +
24
- "\n\n\e[44mGot\e[0m\n" + message.inspect
25
- assert_block(err_msg){ message == expected_message }
26
- end
27
- end
28
-
29
-
30
-
31
- # Could use this instead of test/unit
32
- # class Testis
33
- # def initialize
34
- # #find all methods with test_ and run them
35
- # methods_to_run = self.methods.select {|mname| mname =~ /^test_/}
36
- # methods_to_run.each do |meth|
37
- # eval(meth)
38
- # end
39
- # end
40
- #
41
- # def assert_nlp(nlpobj, occ_array)
42
- # nlp_occ_array = nlpobj.parse
43
- # compare = Compare::ArrayofObjects.new(nlp_occ_array.dup, occ_array.dup)
44
- # cval = compare.same?
45
- # puts cval
46
- # if !cval
47
- # puts nlp_occ_array.inspect
48
- # puts "\n\n\n"
49
- # puts occ_array.inspect
50
- # end
51
- # end
52
- # end
53
-
54
-
55
-
data/test/zdate_test.rb DELETED
@@ -1,44 +0,0 @@
1
- require 'test/unit'
2
-
3
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'nickel', 'ruby_ext', 'to_s2.rb'))
4
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'nickel', 'zdate.rb'))
5
-
6
- include Nickel
7
-
8
- class ZDateTest < Test::Unit::TestCase
9
-
10
- def test_get_next_date_from_date_of_month
11
- d1 = ZDate.new('20090927')
12
- assert_equal ZDate.new('20090928'), d1.get_next_date_from_date_of_month(28)
13
- assert_equal ZDate.new('20091005'), d1.get_next_date_from_date_of_month(5)
14
- assert_equal nil, d1.get_next_date_from_date_of_month(31)
15
- end
16
-
17
- # def test_get_date_from_day_and_week_of_month
18
- # d1 = ZDate.new('20090927')
19
- # assert_equal ZDate.new('20090930'), d1.get_date_from_day_and_week_of_month(Z::WED, -1)
20
- # assert_equal ZDate.new('20090930'), d1.get_date_from_day_and_week_of_month(Z::WED, 5)
21
- # # there is no 5th thursday this sept
22
- # assert_equal nil, d1.get_date_from_day_and_week_of_month(Z::THU, 5)
23
- # end
24
-
25
- def test_diff_in_days_to_this
26
- d1 = ZDate.new('20090927')
27
- assert_equal 0, d1.diff_in_days_to_this(ZDate::SUN)
28
- assert_equal 1, d1.diff_in_days_to_this(ZDate::MON)
29
- assert_equal 2, d1.diff_in_days_to_this(ZDate::TUE)
30
- assert_equal 3, d1.diff_in_days_to_this(ZDate::WED)
31
- assert_equal 4, d1.diff_in_days_to_this(ZDate::THU)
32
- assert_equal 5, d1.diff_in_days_to_this(ZDate::FRI)
33
- assert_equal 6, d1.diff_in_days_to_this(ZDate::SAT)
34
-
35
- d2 = ZDate.new('20090930')
36
- assert_equal 0, d2.diff_in_days_to_this(ZDate::WED)
37
- assert_equal 1, d2.diff_in_days_to_this(ZDate::THU)
38
- assert_equal 2, d2.diff_in_days_to_this(ZDate::FRI)
39
- assert_equal 3, d2.diff_in_days_to_this(ZDate::SAT)
40
- assert_equal 4, d2.diff_in_days_to_this(ZDate::SUN)
41
- assert_equal 5, d2.diff_in_days_to_this(ZDate::MON)
42
- assert_equal 6, d2.diff_in_days_to_this(ZDate::TUE)
43
- end
44
- end
data/test/ztime_test.rb DELETED
@@ -1,429 +0,0 @@
1
- require 'test/unit'
2
-
3
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'nickel', 'ruby_ext', 'to_s2.rb'))
4
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'nickel', 'ztime.rb'))
5
-
6
- include Nickel
7
-
8
- class ZTimeTest < Test::Unit::TestCase
9
-
10
- def test_12_to_12am
11
- t1 = ZTime.new("1200")
12
- t2 = ZTime.new("1200", :am)
13
- t1_after_modify = t1.dup # t1 should not change
14
- t1.modify_such_that_is_before(t2)
15
- assert_equal(t1_after_modify, t1)
16
- end
17
-
18
- def test_12pm_to_12
19
- t1 = ZTime.new("1200", :pm)
20
- t2 = ZTime.new("1200")
21
- t2_after_modify = ZTime.new("1200", :am)
22
- t2.modify_such_that_is_after(t1)
23
- assert_equal(t2_after_modify, t2)
24
- end
25
-
26
- def test_12_to_12pm
27
- t1 = ZTime.new("1200")
28
- t2 = ZTime.new("1200", :pm)
29
- t1_after_modify = ZTime.new("12", :am)
30
- t1.modify_such_that_is_before(t2)
31
- assert_equal(t1_after_modify, t1)
32
- end
33
-
34
- def test_12am_to_12
35
- t1 = ZTime.new("1200", :am)
36
- t2 = ZTime.new("1200")
37
- t2_after_modify = t2.dup
38
- t2.modify_such_that_is_after(t1)
39
- assert_equal(t2_after_modify, t2)
40
- end
41
-
42
- def test_1_to_2am
43
- t1 = ZTime.new("1")
44
- t2 = ZTime.new("2", :am)
45
- t1_after_modify = t1.dup # t1 should not change
46
- t1.modify_such_that_is_before(t2)
47
- assert_equal(t1_after_modify, t1)
48
- end
49
-
50
- def test_1am_to_2
51
- t1 = ZTime.new("1", :am)
52
- t2 = ZTime.new("2")
53
- t2_after_modify = t2.dup
54
- t2.modify_such_that_is_after(t1)
55
- assert_equal(t2_after_modify, t2)
56
- end
57
-
58
- def test_10_to_11pm
59
- t1 = ZTime.new("10")
60
- t2 = ZTime.new("11", :pm)
61
- t1_after_modify = ZTime.new("10", :pm) # should really be 10pm
62
- t1.modify_such_that_is_before(t2)
63
- assert_equal(t1_after_modify, t1)
64
- end
65
-
66
- def test_10pm_to_11
67
- t1 = ZTime.new("10", :pm)
68
- t2 = ZTime.new("11")
69
- t2_after_modify = ZTime.new("11", :pm)
70
- t2.modify_such_that_is_after(t1)
71
- assert_equal(t2_after_modify, t2)
72
- end
73
-
74
- def test_8_to_12pm
75
- t1 = ZTime.new("8")
76
- t2 = ZTime.new("12", :pm)
77
- t1_after_modify = t1.dup
78
- t1.modify_such_that_is_before(t2)
79
- assert_equal(t1_after_modify, t1)
80
- end
81
-
82
- def test_8am_to_12
83
- t1 = ZTime.new("8", :am)
84
- t2 = ZTime.new("12")
85
- t2_after_modify = t2.dup
86
- t2.modify_such_that_is_after(t1)
87
- assert_equal(t2_after_modify, t2)
88
- end
89
-
90
- def test_830_to_835am
91
- t1 = ZTime.new("0830")
92
- t2 = ZTime.new("0835", :am)
93
- t1_after_modify = t1.dup
94
- t1.modify_such_that_is_before(t2)
95
- assert_equal(t1_after_modify, t1)
96
- end
97
-
98
- def test_830am_to_835
99
- t1 = ZTime.new("0830", :am)
100
- t2 = ZTime.new("0835")
101
- t2_after_modify = t2.dup
102
- t2.modify_such_that_is_after(t1)
103
- assert_equal(t2_after_modify, t2)
104
- end
105
-
106
- def test_830_to_835pm
107
- t1 = ZTime.new("0830")
108
- t2 = ZTime.new("0835", :pm)
109
- t1_after_modify = ZTime.new("0830", :pm)
110
- t1.modify_such_that_is_before(t2)
111
- assert_equal(t1_after_modify, t1)
112
- end
113
-
114
- def test_830pm_to_835
115
- t1 = ZTime.new("0830", :pm)
116
- t2 = ZTime.new("0835")
117
- t2_after_modify = ZTime.new("0835", :pm)
118
- t2.modify_such_that_is_after(t1)
119
- assert_equal(t2_after_modify, t2)
120
- end
121
-
122
- def test_835_to_835pm
123
- t1 = ZTime.new("0835")
124
- t2 = ZTime.new("0835", :pm)
125
- t1_after_modify = t1.dup
126
- t1.modify_such_that_is_before(t2)
127
- assert_equal(t1_after_modify, t1)
128
- end
129
-
130
- def test_835am_to_835
131
- t1 = ZTime.new("0835", :am)
132
- t2 = ZTime.new("0835")
133
- t2_after_modify = ZTime.new("0835", :pm)
134
- t2.modify_such_that_is_after(t1)
135
- assert_equal(t2_after_modify, t2)
136
- end
137
-
138
- def test_835pm_to_835
139
- t1 = ZTime.new("0835", :pm)
140
- t2 = ZTime.new("0835")
141
- t2_after_modify = t2.dup
142
- t2.modify_such_that_is_after(t1)
143
- assert_equal(t2_after_modify, t2)
144
- end
145
-
146
- def test_1021_to_1223am
147
- t1 = ZTime.new("1021")
148
- t2 = ZTime.new("1223", :am)
149
- t1_after_modify = ZTime.new("1021", :pm)
150
- t1.modify_such_that_is_before(t2)
151
- assert_equal(t1_after_modify, t1)
152
- end
153
-
154
- def test_1021pm_to_1223
155
- t1 = ZTime.new("1021", :pm)
156
- t2 = ZTime.new("1223")
157
- t2_after_modify = ZTime.new("1223", :am)
158
- t2.modify_such_that_is_after(t1)
159
- assert_equal(t2_after_modify, t2)
160
- end
161
-
162
- def test_12_to_2am
163
- t1 = ZTime.new("12")
164
- t2 = ZTime.new("2", :am)
165
- t1_after_modify = ZTime.new("12", :am)
166
- t1.modify_such_that_is_before(t2)
167
- assert_equal(t1_after_modify, t1)
168
- end
169
-
170
- def test_12am_to_2
171
- t1 = ZTime.new("12", :am)
172
- t2 = ZTime.new("2")
173
- t2_after_modify = t2.dup
174
- t2.modify_such_that_is_after(t1)
175
- assert_equal(t2_after_modify, t2)
176
- end
177
-
178
- def test_1220_to_2am
179
- t1 = ZTime.new("1220")
180
- t2 = ZTime.new("2", :am)
181
- t1_after_modify = ZTime.new("1220", :am)
182
- t1.modify_such_that_is_before(t2)
183
- assert_equal(t1_after_modify, t1)
184
- end
185
-
186
- def test_1220am_to_2
187
- t1 = ZTime.new("1220", :am)
188
- t2 = ZTime.new("2")
189
- t2_after_modify = t2.dup
190
- t2.modify_such_that_is_after(t1)
191
- assert_equal(t2_after_modify, t2)
192
- end
193
-
194
- def test_1220_to_12am
195
- t1 = ZTime.new("1220")
196
- t2 = ZTime.new("12", :am)
197
- t1_after_modify = t1.dup
198
- t1.modify_such_that_is_before(t2)
199
- assert_equal(t1_after_modify, t1)
200
- end
201
-
202
- def test_1220am_to_12
203
- t1 = ZTime.new("1220", :am)
204
- t2 = ZTime.new("12")
205
- t2_after_modify = t2.dup
206
- t2.modify_such_that_is_after(t1)
207
- assert_equal(t2_after_modify, t2)
208
- end
209
-
210
- def test_1220_to_1220am
211
- t1 = ZTime.new("1220")
212
- t2 = ZTime.new("1220", :am)
213
- t1_after_modify = t1.dup
214
- t1.modify_such_that_is_before(t2)
215
- assert_equal(t1_after_modify, t1)
216
- end
217
-
218
- def test_1220pm_to_1220
219
- t1 = ZTime.new("1220", :pm)
220
- t2 = ZTime.new("1220")
221
- t2_after_modify = ZTime.new("1220", :am)
222
- t2.modify_such_that_is_after(t1)
223
- assert_equal(t2_after_modify, t2)
224
- end
225
-
226
- def test_930_to_5pm
227
- t1 = ZTime.new("0930")
228
- t2 = ZTime.new("5", :pm)
229
- t1_after_modify = t1.dup
230
- t1.modify_such_that_is_before(t2)
231
- assert_equal(t1_after_modify, t1)
232
- end
233
-
234
- def test_930am_to_5
235
- t1 = ZTime.new("0930", :am)
236
- t2 = ZTime.new("5")
237
- t2_after_modify = ZTime.new("5", :pm)
238
- t2.modify_such_that_is_after(t1)
239
- assert_equal(t2_after_modify, t2)
240
- end
241
-
242
- def test_930_to_5am
243
- t1 = ZTime.new("0930")
244
- t2 = ZTime.new("5", :am)
245
- t1_after_modify = ZTime.new("0930", :pm)
246
- t1.modify_such_that_is_before(t2)
247
- assert_equal(t1_after_modify, t1)
248
- end
249
-
250
- def test_930pm_to_5
251
- t1 = ZTime.new("0930", :pm)
252
- t2 = ZTime.new("5")
253
- t2_after_modify = t2.dup
254
- t2.modify_such_that_is_after(t1)
255
- assert_equal(t2_after_modify, t2)
256
- end
257
-
258
- def test_1100_to_425pm
259
- t1 = ZTime.new("1100")
260
- t2 = ZTime.new("0425", :pm)
261
- t1_after_modify = t1.dup
262
- t1.modify_such_that_is_before(t2)
263
- assert_equal(t1_after_modify, t1)
264
- end
265
-
266
- def test_1100am_to_425
267
- t1 = ZTime.new("1100", :am)
268
- t2 = ZTime.new("0425")
269
- t2_after_modify = ZTime.new("0425", :pm)
270
- t2.modify_such_that_is_after(t1)
271
- assert_equal(t2_after_modify, t2)
272
- end
273
-
274
- def test_1100_to_425am
275
- t1 = ZTime.new("1100")
276
- t2 = ZTime.new("0425", :am)
277
- t1_after_modify = ZTime.new("1100", :pm)
278
- t1.modify_such_that_is_before(t2)
279
- assert_equal(t1_after_modify, t1)
280
- end
281
-
282
- def test_1100pm_to_425
283
- t1 = ZTime.new("1100", :pm)
284
- t2 = ZTime.new("0425")
285
- t2_after_modify = t2.dup
286
- t2.modify_such_that_is_after(t1)
287
- assert_equal(t2_after_modify, t2)
288
- end
289
-
290
- def test_0115_to_0120am
291
- t1 = ZTime.new("0115")
292
- t2 = ZTime.new("0120", :am)
293
- t1_after_modify = t1.dup
294
- t1.modify_such_that_is_before(t2)
295
- assert_equal(t1_after_modify, t1)
296
- end
297
-
298
- def test_0115am_to_0120
299
- t1 = ZTime.new("0115", :am)
300
- t2 = ZTime.new("0120")
301
- t2_after_modify = t2.dup
302
- t2.modify_such_that_is_after(t1)
303
- assert_equal(t2_after_modify, t2)
304
- end
305
-
306
- def test_0115_to_0120pm
307
- t1 = ZTime.new("0115")
308
- t2 = ZTime.new("0120", :pm)
309
- t1_after_modify = ZTime.new("0115", :pm)
310
- t1.modify_such_that_is_before(t2)
311
- assert_equal(t1_after_modify, t1)
312
- end
313
-
314
- def test_0115pm_to_0120
315
- t1 = ZTime.new("0115", :pm)
316
- t2 = ZTime.new("0120")
317
- t2_after_modify = ZTime.new("0120", :pm)
318
- t2.modify_such_that_is_after(t1)
319
- assert_equal(t2_after_modify, t2)
320
- end
321
-
322
- def test_1020_to_1015am
323
- t1 = ZTime.new("1020")
324
- t2 = ZTime.new("1015", :am)
325
- t1_after_modify = ZTime.new("1020", :pm)
326
- t1.modify_such_that_is_before(t2)
327
- assert_equal(t1_after_modify, t1)
328
- end
329
-
330
- def test_1020pm_to_1015
331
- t1 = ZTime.new("1020", :pm)
332
- t2 = ZTime.new("1015")
333
- t2_after_modify = t2.dup
334
- t2.modify_such_that_is_after(t1)
335
- assert_equal(t2_after_modify, t2)
336
- end
337
-
338
- def test_1020_to_1015pm
339
- t1 = ZTime.new("1020")
340
- t2 = ZTime.new("1015", :pm)
341
- t1_after_modify = t1.dup
342
- t1.modify_such_that_is_before(t2)
343
- assert_equal(t1_after_modify, t1)
344
- end
345
-
346
- def test_1020am_to_1015
347
- t1 = ZTime.new("1020", :am)
348
- t2 = ZTime.new("1015")
349
- t2_after_modify = ZTime.new("1015", :pm)
350
- t2.modify_such_that_is_after(t1)
351
- assert_equal(t2_after_modify, t2)
352
- end
353
-
354
- def test_1015_to_1020am
355
- t1 = ZTime.new("1015")
356
- t2 = ZTime.new("1020", :am)
357
- t1_after_modify = t1.dup
358
- t1.modify_such_that_is_before(t2)
359
- assert_equal(t1_after_modify, t1)
360
- end
361
-
362
- def test_1015pm_to_1020
363
- t1 = ZTime.new("1015", :pm)
364
- t2 = ZTime.new("1020")
365
- t2_after_modify = ZTime.new("1020", :pm)
366
- t2.modify_such_that_is_after(t1)
367
- assert_equal(t2_after_modify, t2)
368
- end
369
-
370
- def test_1015_to_1020pm
371
- t1 = ZTime.new("1015")
372
- t2 = ZTime.new("1020", :pm)
373
- t1_after_modify = ZTime.new("1015", :pm)
374
- t1.modify_such_that_is_before(t2)
375
- assert_equal(t1_after_modify, t1)
376
- end
377
-
378
- def test_1015am_to_1020
379
- t1 = ZTime.new("1015", :am)
380
- t2 = ZTime.new("1020")
381
- t2_after_modify = t2.dup
382
- t2.modify_such_that_is_after(t1)
383
- assert_equal(t2_after_modify, t2)
384
- end
385
-
386
- def test_am_pm_modifier1
387
- t1 = ZTime.new("7", :pm)
388
- t1d = t1.dup
389
- ZTime.am_pm_modifier(t1)
390
- assert_equal(t1d, t1)
391
- end
392
-
393
- def test_am_pm_modifier2
394
- t1 = ZTime.new("7", :pm)
395
- t2 = ZTime.new("8")
396
- t1d = t1.dup
397
- ZTime.am_pm_modifier(t1,t2)
398
- assert_equal(t1d, t1)
399
- assert_equal(ZTime.new("8", :pm), t2)
400
- end
401
-
402
- def test_am_pm_modifier3
403
- t1 = ZTime.new("7")
404
- t2 = ZTime.new("8", :pm)
405
- t2d = t2.dup
406
- t3 = ZTime.new("9")
407
-
408
- ZTime.am_pm_modifier(t1,t2,t3)
409
- assert_equal(ZTime.new("7", :pm), t1)
410
- assert_equal(t2d, t2)
411
- assert_equal(ZTime.new("9", :pm), t3)
412
- end
413
-
414
- def test_am_pm_modifier4
415
- t1 = ZTime.new("7")
416
- t2 = ZTime.new("8", :am)
417
- t3 = ZTime.new("9")
418
- t4 = ZTime.new("4", :pm)
419
- t5 = ZTime.new("7")
420
-
421
- ZTime.am_pm_modifier(t1,t2,t3,t4,t5)
422
- assert_equal(ZTime.new("7", :am), t1)
423
- assert_equal(ZTime.new("8", :am), t2)
424
- assert_equal(ZTime.new("9", :am), t3)
425
- assert_equal(ZTime.new("4", :pm), t4)
426
- assert_equal(ZTime.new("7", :pm), t5)
427
- end
428
- end
429
-