From zenspider at rubyforge.org Tue May 17 23:55:39 2005 From: zenspider at rubyforge.org (zenspider@rubyforge.org) Date: Tue May 17 23:55:40 2005 Subject: [Rubytests-commit] rubicon rubicon_tests.rb Message-ID: <200505180355.j4I3tddS013412@rubyforge.org> Update of /var/cvs/rubytests/rubicon In directory rubyforge.org:/tmp/cvs-serv13404 Modified Files: rubicon_tests.rb Log Message: Restored the ability to use -n from test/unit's testrunner. Index: rubicon_tests.rb =================================================================== RCS file: /var/cvs/rubytests/rubicon/rubicon_tests.rb,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** rubicon_tests.rb 31 Mar 2005 00:25:17 -0000 1.14 --- rubicon_tests.rb 18 May 2005 03:55:37 -0000 1.15 *************** *** 43,47 **** suite = Test::Unit::TestSuite.new selected_testmethods.each do |testmethod| ! suite << testClass.new(testmethod) end end --- 43,49 ---- suite = Test::Unit::TestSuite.new selected_testmethods.each do |testmethod| ! catch(:invalid_test) do ! suite << testClass.new(testmethod) ! end end end From zenspider at rubyforge.org Tue May 17 23:55:47 2005 From: zenspider at rubyforge.org (zenspider@rubyforge.org) Date: Tue May 17 23:55:48 2005 Subject: [Rubytests-commit] rubicon/builtin ArrayBase.rb Message-ID: <200505180355.j4I3tldS013437@rubyforge.org> Update of /var/cvs/rubytests/rubicon/builtin In directory rubyforge.org:/tmp/cvs-serv13430/builtin Modified Files: ArrayBase.rb Log Message: Moved test_pack to new pack test file. This better reflects ruby's layout. Improved values_at and added zip. Index: ArrayBase.rb =================================================================== RCS file: /var/cvs/rubytests/rubicon/builtin/ArrayBase.rb,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** ArrayBase.rb 11 Nov 2004 22:15:12 -0000 1.21 --- ArrayBase.rb 18 May 2005 03:55:45 -0000 1.22 *************** *** 894,981 **** end - def test_pack - a = @cls[*%w( cat wombat x yy)] - assert_equal("catwomx yy ", a.pack("A3A3A3A3")) - assert_equal("cat", a.pack("A*")) - assert_equal("cwx yy ", a.pack("A3@1A3@2A3A3")) - assert_equal("catwomx\000\000yy\000", a.pack("a3a3a3a3")) - assert_equal("cat", a.pack("a*")) - assert_equal("ca", a.pack("a2")) - assert_equal("cat\000\000", a.pack("a5")) - - assert_equal("\x61", @cls["01100001"].pack("B8")) - assert_equal("\x61", @cls["01100001"].pack("B*")) - assert_equal("\x61", @cls["0110000100110111"].pack("B8")) - assert_equal("\x61\x37", @cls["0110000100110111"].pack("B16")) - assert_equal("\x61\x37", @cls["01100001", "00110111"].pack("B8B8")) - assert_equal("\x60", @cls["01100001"].pack("B4")) - assert_equal("\x40", @cls["01100001"].pack("B2")) - - assert_equal("\x86", @cls["01100001"].pack("b8")) - assert_equal("\x86", @cls["01100001"].pack("b*")) - assert_equal("\x86", @cls["0110000100110111"].pack("b8")) - assert_equal("\x86\xec", @cls["0110000100110111"].pack("b16")) - assert_equal("\x86\xec", @cls["01100001", "00110111"].pack("b8b8")) - assert_equal("\x06", @cls["01100001"].pack("b4")) - assert_equal("\x02", @cls["01100001"].pack("b2")) - - assert_equal("ABC", @cls[ 65, 66, 67 ].pack("C3")) - assert_equal("\377BC", @cls[ -1, 66, 67 ].pack("C*")) - assert_equal("ABC", @cls[ 65, 66, 67 ].pack("c3")) - assert_equal("\377BC", @cls[ -1, 66, 67 ].pack("c*")) - - - assert_equal("AB\n\x10", @cls["4142", "0a", "12"].pack("H4H2H1")) - assert_equal("AB\n\x02", @cls["1424", "a0", "21"].pack("h4h2h1")) - - assert_equal("abc=02def=\ncat=\n=01=\n", - @cls["abc\002def", "cat", "\001"].pack("M9M3M4")) - - assert_equal("aGVsbG8K\n", @cls["hello\n"].pack("m")) - assert_equal(",:&5L;&\\*:&5L;&\\*\n", @cls["hello\nhello\n"].pack("u")) - - assert_equal("\xc2\xa9B\xe2\x89\xa0", @cls[0xa9, 0x42, 0x2260].pack("U*")) - - - format = "c2x5CCxsdils_l_a6"; - # Need the expression in here to force ary[5] to be numeric. This avoids - # test2 failing because ary2 goes str->numeric->str and ary does not. - ary = [1, -100, 127, 128, 32767, 987.654321098/100.0, - 12345, 123456, -32767, -123456, "abcdef"] - x = ary.pack(format) - ary2 = x.unpack(format) - - assert_equal(ary.length, ary2.length) - assert_equal(ary.join(':'), ary2.join(':')) - assert_not_nil(x =~ /def/) - - - - skipping "Not tested: - D,d & double-precision float, native format\\ - E & double-precision float, little-endian byte order\\ - e & single-precision float, little-endian byte order\\ - F,f & single-precision float, native format\\ - G & double-precision float, network (big-endian) byte order\\ - g & single-precision float, network (big-endian) byte order\\ - I & unsigned integer\\ - i & integer\\ - L & unsigned long\\ - l & long\\ - - N & long, network (big-endian) byte order\\ - n & short, network (big-endian) byte-order\\ - P & pointer to a structure (fixed-length string)\\ - p & pointer to a null-terminated string\\ - S & unsigned short\\ - s & short\\ - V & long, little-endian byte order\\ - v & short, little-endian byte order\\ - X & back up a byte\\ - x & null byte\\ - Z & ASCII string (null padded, count is width)\\ - " - end - def test_pop a = @cls[ 'cat', 'dog' ] --- 894,897 ---- *************** *** 1277,1280 **** --- 1193,1197 ---- assert_equal(%w(a c e), %w(a b c d e).values_at(0.0, 2.0, 4.0)) # float as index assert_equal(%w(b), %w(a b c d e).values_at(1.8)) # float as index + assert_equal(%w(b c d), %w(a b c d e).values_at(1..3)) assert_raises(TypeError) { %w(a b c).values_at(nil) } assert_raises(TypeError) { %w(a b c).values_at("x") } *************** *** 1295,1297 **** --- 1212,1224 ---- end + def test_zip + a = @cls[4, 5, 6] + b = @cls[7, 8, 9] + + assert_equal([[1, 4, 7], [2, 5, 8], [3, 6, 9]], @cls[1, 2, 3].zip(a, b)) + assert_equal([[1, 4, 7], [2, 5, 8]], @cls[1, 2].zip(a, b)) + assert_equal([[4, 1, 8], [5, 2, nil], [6, nil, nil]], a.zip([1, 2], [8])) + end + end + From zenspider at rubyforge.org Tue May 17 23:55:54 2005 From: zenspider at rubyforge.org (zenspider@rubyforge.org) Date: Tue May 17 23:55:54 2005 Subject: [Rubytests-commit] rubicon/builtin StringBase.rb Message-ID: <200505180355.j4I3tsdS013465@rubyforge.org> Update of /var/cvs/rubytests/rubicon/builtin In directory rubyforge.org:/tmp/cvs-serv13460/builtin Modified Files: StringBase.rb Log Message: Moved test_unpack to new pack test file. This better reflects ruby's layout. Index: StringBase.rb =================================================================== RCS file: /var/cvs/rubytests/rubicon/builtin/StringBase.rb,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** StringBase.rb 9 Apr 2005 22:01:49 -0000 1.16 --- StringBase.rb 18 May 2005 03:55:52 -0000 1.17 *************** *** 1326,1406 **** end - def test_unpack - a = [S("cat"), S("wom"), S("x"), S("yy")] - assert_equal(a, S("catwomx yy ").unpack(S("A3A3A3A3"))) - - assert_equal([S("cat")], S("cat \000\000").unpack(S("A*"))) - assert_equal([S("cwx"), S("wx"), S("x"), S("yy")], - S("cwx yy ").unpack(S("A3@1A3@2A3A3"))) - assert_equal([S("cat"), S("wom"), S("x\000\000"), S("yy\000")], - S("catwomx\000\000yy\000").unpack(S("a3a3a3a3"))) - assert_equal([S("cat \000\000")], S("cat \000\000").unpack(S("a*"))) - assert_equal([S("ca")], S("catdog").unpack(S("a2"))) - - assert_equal([S("cat\000\000")], - S("cat\000\000\000\000\000dog").unpack(S("a5"))) - - assert_equal([S("01100001")], S("\x61").unpack(S("B8"))) - assert_equal([S("01100001")], S("\x61").unpack(S("B*"))) - assert_equal([S("0110000100110111")], S("\x61\x37").unpack(S("B16"))) - assert_equal([S("01100001"), S("00110111")], S("\x61\x37").unpack(S("B8B8"))) - assert_equal([S("0110")], S("\x60").unpack(S("B4"))) - - assert_equal([S("01")], S("\x40").unpack(S("B2"))) - - assert_equal([S("01100001")], S("\x86").unpack(S("b8"))) - assert_equal([S("01100001")], S("\x86").unpack(S("b*"))) - - assert_equal([S("0110000100110111")], S("\x86\xec").unpack(S("b16"))) - assert_equal([S("01100001"), S("00110111")], S("\x86\xec").unpack(S("b8b8"))) - - assert_equal([S("0110")], S("\x06").unpack(S("b4"))) - assert_equal([S("01")], S("\x02").unpack(S("b2"))) - - assert_equal([ 65, 66, 67 ], S("ABC").unpack(S("C3"))) - assert_equal([ 255, 66, 67 ], S("\377BC").unpack("C*")) - assert_equal([ 65, 66, 67 ], S("ABC").unpack("c3")) - assert_equal([ -1, 66, 67 ], S("\377BC").unpack("c*")) - - - assert_equal([S("4142"), S("0a"), S("1")], S("AB\n\x10").unpack(S("H4H2H1"))) - assert_equal([S("1424"), S("a0"), S("2")], S("AB\n\x02").unpack(S("h4h2h1"))) - - assert_equal([S("abc\002defcat\001"), S(""), S("")], - S("abc=02def=\ncat=\n=01=\n").unpack(S("M9M3M4"))) - - assert_equal([S("hello\n")], S("aGVsbG8K\n").unpack(S("m"))) - - assert_equal([S("hello\nhello\n")], S(",:&5L;&\\*:&5L;&\\*\n").unpack(S("u"))) - - assert_equal([0xa9, 0x42, 0x2260], S("\xc2\xa9B\xe2\x89\xa0").unpack(S("U*"))) - - skipping "Not tested: - D,d & double-precision float, native format\\ - E & double-precision float, little-endian byte order\\ - e & single-precision float, little-endian byte order\\ - F,f & single-precision float, native format\\ - G & double-precision float, network (big-endian) byte order\\ - g & single-precision float, network (big-endian) byte order\\ - I & unsigned integer\\ - i & integer\\ - L & unsigned long\\ - l & long\\ - - m & string encoded in base64 (uuencoded)\\ - N & long, network (big-endian) byte order\\ - n & short, network (big-endian) byte-order\\ - P & pointer to a structure (fixed-length string)\\ - p & pointer to a null-terminated string\\ - S & unsigned short\\ - s & short\\ - V & long, little-endian byte order\\ - v & short, little-endian byte order\\ - X & back up a byte\\ - x & null byte\\ - Z & ASCII string (null padded, count is width)\\ - " - end - def test_upcase assert_equal(S("HELLO"), S("hello").upcase) --- 1326,1329 ---- From zenspider at rubyforge.org Tue May 17 23:55:59 2005 From: zenspider at rubyforge.org (zenspider@rubyforge.org) Date: Tue May 17 23:56:01 2005 Subject: [Rubytests-commit] rubicon/builtin TestTime.rb Message-ID: <200505180355.j4I3txdS013488@rubyforge.org> Update of /var/cvs/rubytests/rubicon/builtin In directory rubyforge.org:/tmp/cvs-serv13480/builtin Modified Files: TestTime.rb Log Message: Started switch to predefined values instead of Time.now for everything. Re-commented out load/dump tests... because I'm lazy. Removed audit-added tests that slipped in from time.rb. Implemented all other audit-added tests. Switched nearly everything over to assert_equal, assert_not_equal, and assert_in_delta. Refactored several tests, but not fully. Cleaned up some really needless stuff. Improved error messages. Got rid of terribly exhaustive yday tests for proper edge case boundary tests. Index: TestTime.rb =================================================================== RCS file: /var/cvs/rubytests/rubicon/builtin/TestTime.rb,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TestTime.rb 24 Mar 2005 01:00:03 -0000 1.7 --- TestTime.rb 18 May 2005 03:55:57 -0000 1.8 *************** *** 105,111 **** --- 105,124 ---- end + def setup + @orig_zone = ENV['TZ'] + ENV['TZ'] = 'PST8PDT' + @utc = Time.utc(2001, 2, 3, 4, 5, 6) + @loc = Time.local(2001, 2, 3, 4, 5, 6) + @zone = @loc.zone + end + + def teardown + ENV['TZ'] = @orig_zone + end + # # Ensure against time travel # + def test_00sanity # ZenTest SKIP assert_operator Time.now.to_i, :>, 960312287 # Tue Jun 6 13:25:06 EDT 2000 *************** *** 115,132 **** def test_class__load ! raise NotImplementedError, 'Need to write test_class__load' end def test_class_at ! t = Time.now ! sec = t.to_i assert_equal(0, Time.at(0).to_i) ! assert_equal(t, Time.at(t)) ! assert((Time.at(sec,1000000).to_f - Time.at(sec).to_f) == 1.0) end def test_class_gm assert_raises(ArgumentError) { Time.gm } ! assert(Time.gm(2000) != Time.local(2000)) assert_equal(Time.gm(2000), Time.gm(2000,1,1,0,0,0)) assert_equal(Time.gm(2000,nil,nil,nil,nil,nil), Time.gm(2000,1,1,0,0,0)) --- 128,153 ---- def test_class__load ! # TODO: raise NotImplementedError, 'Need to write test_class__load' end def test_class_at ! loc = Time.now ! sec = loc.to_i assert_equal(0, Time.at(0).to_i) ! assert_equal(loc, Time.at(loc)) ! assert((Time.at(sec,1000000).to_f - Time.at(sec).to_f) == 1.0) # FIX ! end ! ! def test_class_at_utc ! utc1 = Time.now.utc ! utc2 = Time.at(utc1) ! assert(utc1.utc?) ! assert(utc2.utc?) ! assert_equal(utc1.to_i, utc2.to_i) end def test_class_gm assert_raises(ArgumentError) { Time.gm } ! assert_not_equal(Time.gm(2000), Time.local(2000)) assert_equal(Time.gm(2000), Time.gm(2000,1,1,0,0,0)) assert_equal(Time.gm(2000,nil,nil,nil,nil,nil), Time.gm(2000,1,1,0,0,0)) *************** *** 145,159 **** end - def test_class_httpdate - raise NotImplementedError, 'Need to write test_class_httpdate' - end - - def test_class_iso8601 - raise NotImplementedError, 'Need to write test_class_iso8601' - end - def test_class_local assert_raises(ArgumentError) { Time.local } ! assert(Time.gm(2000) != Time.local(2000)) assert_equal(Time.local(2000), Time.local(2000,1,1,0,0,0)) assert_equal(Time.local(2000,nil,nil,nil,nil,nil), Time.local(2000,1,1,0,0,0)) --- 166,172 ---- end def test_class_local assert_raises(ArgumentError) { Time.local } ! assert_not_equal(Time.gm(2000), Time.local(2000)) assert_equal(Time.local(2000), Time.local(2000,1,1,0,0,0)) assert_equal(Time.local(2000,nil,nil,nil,nil,nil), Time.local(2000,1,1,0,0,0)) *************** *** 177,181 **** # assert_raises(ArgumentError) { Time.mktime } ! assert(Time.gm(2000) != Time.mktime(2000)) assert_equal(Time.mktime(2000), Time.mktime(2000,1,1,0,0,0)) assert_equal(Time.mktime(2000,nil,nil,nil,nil,nil), Time.mktime(2000,1,1,0,0,0)) --- 190,194 ---- # assert_raises(ArgumentError) { Time.mktime } ! assert_not_equal(Time.gm(2000), Time.mktime(2000)) assert_equal(Time.mktime(2000), Time.mktime(2000,1,1,0,0,0)) assert_equal(Time.mktime(2000,nil,nil,nil,nil,nil), Time.mktime(2000,1,1,0,0,0)) *************** *** 198,219 **** end ! def test_class_now ! t1 = Time.now ! sleep 1 ! t2 = Time.now d = t2.to_f - t1.to_f ! assert(d > 0.9 && d < 1.1) ! end ! ! def test_class_parse ! raise NotImplementedError, 'Need to write test_class_parse' ! end ! ! def test_class_rfc2822 ! raise NotImplementedError, 'Need to write test_class_rfc2822' end ! def test_class_rfc822 ! raise NotImplementedError, 'Need to write test_class_rfc822' end --- 211,224 ---- end ! def util_class_now(method) ! t1 = Time.send(method) ! sleep 0.1 ! t2 = Time.send(method) d = t2.to_f - t1.to_f ! assert_in_delta(0.1, d, 0.01) end ! def test_class_now ! util_class_now(:now) end *************** *** 228,240 **** def test_class_utc ! raise NotImplementedError, 'Need to write test_class_utc' ! end ! ! def test_class_xmlschema ! raise NotImplementedError, 'Need to write test_class_xmlschema' ! end ! ! def test_class_zone_offset ! raise NotImplementedError, 'Need to write test_class_zone_offset' end --- 233,237 ---- def test_class_utc ! test_class_gm # TODO: refactor to ensure they really are synonyms end *************** *** 242,246 **** def test__dump ! raise NotImplementedError, 'Need to write test__dump' end --- 239,243 ---- def test__dump ! # TODO: raise NotImplementedError, 'Need to write test__dump' end *************** *** 259,263 **** assert_equal(a, b) ! assert(a.__id__ != b.__id__) assert_equal(a.frozen?, b.frozen?) assert_equal(a.tainted?, b.tainted?) --- 256,260 ---- assert_equal(a, b) ! assert_not_equal(a.__id__, b.__id__) assert_equal(a.frozen?, b.frozen?) assert_equal(a.tainted?, b.tainted?) *************** *** 276,301 **** def test_dst_eh ! raise NotImplementedError, 'Need to write test_dst_eh' end def test_eql_eh ! t1=Time.now ! t2=t1 ! t2+= 2e-6 ! sleep(0.1) ! assert(!t1.eql?(Time.now)) ! assert(!t1.eql?(t2)) end def test_getgm ! raise NotImplementedError, 'Need to write test_getgm' end def test_getlocal ! raise NotImplementedError, 'Need to write test_getlocal' end def test_getutc ! raise NotImplementedError, 'Need to write test_getutc' end --- 273,323 ---- def test_dst_eh ! test_isdst # TODO: refactor to test that they really are the same end def test_eql_eh ! t1 = Time.now ! t2 = Time.at(t1) ! t3 = t1 + 2e-6 ! t4 = t1 + 1 ! assert(t1.eql?(t1)) ! assert(t1.eql?(t2)) ! assert(!t1.eql?(t3)) ! assert(!t1.eql?(t4)) ! assert(t1.eql?(t1.getutc)) end def test_getgm ! # TODO: this only tests local -> gm ! t1 = Time.now ! loc = Time.at(t1) ! assert(!t1.gmt?) ! t2 = t1.getgm ! assert(!t1.gmt?) ! assert(t2.gmt?) ! assert_equal(t1, loc) ! assert_equal(t1.asctime, loc.asctime) ! assert_not_equal(t2.asctime, loc.asctime) ! assert_not_equal(t1.asctime, t2.asctime) ! assert_equal(t1, t2) end def test_getlocal ! # TODO: this only tests gm -> local ! t1 = Time.now.gmtime ! utc = Time.at(t1) ! assert(t1.gmt?) ! t2 = t1.getlocal ! assert(t1.gmt?) ! assert(!t2.gmt?) ! assert_equal(t1, utc) ! assert_equal(t1.asctime, utc.asctime) ! assert_not_equal(t2.asctime, utc.asctime) ! assert_not_equal(t1.asctime, t2.asctime) ! assert_equal(t1, t2) end def test_getutc ! test_getgm # REFACTOR to test both calls end *************** *** 308,315 **** def test_gmt_offset ! raise NotImplementedError, 'Need to write test_gmt_offset' end def test_gmtime t = Time.now loc = Time.at(t) --- 330,338 ---- def test_gmt_offset ! test_utc_offset # REFACTOR to test both methods end def test_gmtime + # TODO: this only tests local -> gm t = Time.now loc = Time.at(t) *************** *** 317,334 **** t.gmtime assert(t.gmt?) ! assert(t.asctime != loc.asctime) end def test_gmtoff ! raise NotImplementedError, 'Need to write test_gmtoff' end def test_hash ! t = Time.now ! t2 = Time.at(t) ! sleep(0.1) ! t3 = Time.now ! assert_equal(t.hash, t2.hash) ! assert_not_equal(t.hash, t3.hash) end --- 340,356 ---- t.gmtime assert(t.gmt?) ! assert_not_equal(t.asctime, loc.asctime) end def test_gmtoff ! test_utc_offset # REFACTOR to test both methods end def test_hash ! t1 = @utc ! t2 = Time.at(t1) ! t3 = @utc + 1 ! assert_equal(t1.hash, t2.hash) ! assert_not_equal(t1.hash, t3.hash) end *************** *** 337,354 **** end - def test_httpdate - raise NotImplementedError, 'Need to write test_httpdate' - end - def test_initialize ! t1 = Time.new ! sleep 1 ! t2 = Time.new ! d = t2.to_f - t1.to_f ! assert(d > 0.9 && d < 1.1) end def test_inspect ! raise NotImplementedError, 'Need to write test_inspect' end --- 359,369 ---- end def test_initialize ! util_class_now(:new) end def test_inspect ! assert_equal("Sat Feb 03 04:05:06 UTC 2001", @utc.inspect) ! assert_equal("Sat Feb 03 04:05:06 #{@zone} 2001", @loc.inspect) end *************** *** 361,391 **** # better ideas - zone = Time.now.zone - # Are we in the US? - if ["EST", "EDT", "CST", "CDT", "MST", "MDT", ! "PST", "PDT"].include? zone dtest = [ [false, 2000, 1, 1], [true, 2000, 7, 1], ] - dtest.push( - [true, 2000, 4, 2, 4], - [false, 2000, 10, 29, 4], - [false, 2000, 4,2,1,59], # Spring forward - [true, 2000, 4,2,3,0], - [true, 2000, 10,29,0,59], # Fall back - [false, 2000, 10,29,2,0] - ) - dtest.each do |x| result = x.shift assert_equal(result, Time.local(*x).isdst, ! "\nExpected #{x.join(',')} to be dst=#{result}") end else --- 376,400 ---- # better ideas # Are we in the US? if ["EST", "EDT", "CST", "CDT", "MST", "MDT", ! "PST", "PDT"].include? @zone dtest = [ [false, 2000, 1, 1], [true, 2000, 7, 1], + [true, 2000, 4, 2, 4], + [false, 2000, 10, 29, 4], + [false, 2000, 4,2,1,59], # Spring forward + [true, 2000, 4,2,3,0], + [true, 2000, 10,29,0,59], # Fall back + [false, 2000, 10,29,2,0] ] dtest.each do |x| result = x.shift assert_equal(result, Time.local(*x).isdst, ! "\nExpected Time.local(#{x.join(',')}).isdst == #{result}") end else *************** *** 394,402 **** end - def test_iso8601 - raise NotImplementedError, 'Need to write test_iso8601' - end - def test_localtime t = Time.now.gmtime utc = Time.at(t) --- 403,408 ---- end def test_localtime + # TODO: this only tests gm -> local t = Time.now.gmtime utc = Time.at(t) *************** *** 404,408 **** t.localtime assert(!t.gmt?) ! assert(t.asctime != utc.asctime) end --- 410,414 ---- t.localtime assert(!t.gmt?) ! assert_not_equal(t.asctime, utc.asctime) end *************** *** 441,452 **** end - def test_rfc2822 - raise NotImplementedError, 'Need to write test_rfc2822' - end - - def test_rfc822 - raise NotImplementedError, 'Need to write test_rfc822' - end - def test_sec checkComponent(:sec, 5) --- 447,450 ---- *************** *** 507,511 **** def test_succ ! raise NotImplementedError, 'Need to write test_succ' end --- 505,512 ---- def test_succ ! t1 = @loc ! t2 = t1 + 1 ! t3 = t1.succ ! assert_equal(t2, t3) end *************** *** 527,531 **** def test_to_f t = Time.at(10000,1066) ! assert_equal(10000.001066, t.to_f) end --- 528,532 ---- def test_to_f t = Time.at(10000,1066) ! assert_in_delta(10000.001066, t.to_f, 1e-7) end *************** *** 538,544 **** def test_to_s ! flunk "You can't use strftime to test to_s!" ! t = Time.now ! assert_equal(t.strftime("%a %b %d %H:%M:%S %Z %Y"),t.to_s) end --- 539,544 ---- def test_to_s ! assert_equal("Sat Feb 03 04:05:06 UTC 2001", @utc.to_s) ! assert_equal("Sat Feb 03 04:05:06 #{@zone} 2001", @loc.to_s) end *************** *** 550,573 **** end def test_tv_usec ! t = Time.at(10000,1066) ! assert_equal(1066,t.tv_usec) end def test_usec ! t = Time.at(10000,1066) ! assert_equal(1066,t.usec) end def test_utc ! raise NotImplementedError, 'Need to write test_utc' end def test_utc_eh ! raise NotImplementedError, 'Need to write test_utc_eh' end def test_utc_offset ! raise NotImplementedError, 'Need to write test_utc_offset' end --- 550,581 ---- end + def util_usec(s, u, method) + t = Time.at(s,u) + assert_equal(u,t.send(method)) + end + def test_tv_usec ! util_usec(10000, 1066, :tv_usec) ! util_usec(10000, 0, :tv_usec) end def test_usec ! util_usec(10000, 1066, :usec) ! util_usec(10000, 0, :usec) end def test_utc ! test_gmtime # REFACTOR to test both methods end def test_utc_eh ! test_gmt_eh # REFACTOR to test both methods end def test_utc_offset ! # TODO: figure out the year, month, & day edgecase setups ! off = @utc - @loc ! assert_equal(0, @utc.utc_offset) ! assert_equal(off, @loc.utc_offset) end *************** *** 575,579 **** t = Time.local(2001, 4, 1) ! 6.times {|i| assert_equal(i,t.wday) t += ONEDAYSEC --- 583,587 ---- t = Time.local(2001, 4, 1) ! 7.times { |i| assert_equal(i,t.wday) t += ONEDAYSEC *************** *** 581,595 **** end - def test_xmlschema - raise NotImplementedError, 'Need to write test_xmlschema' - end - def test_yday ! t = Time.local(2001, 1, 1) ! 365.times {|i| ! assert_equal(i+1,t.yday) ! t += ONEDAYSEC ! } ! end --- 589,618 ---- end def test_yday ! # non-leap 1/1, 2/28, 3/1, 12/31 ! # leap 1/1, 2/28, 2/29, 3/1, 12/31 ! # leap century (2000) ! # want to do a non-leap century, but they are out of range. ! # any others? ! ! # non-leap year: ! assert_equal( 1, Time.local(1999, 1, 1).yday) ! assert_equal( 59, Time.local(1999, 2, 28).yday) ! assert_equal( 60, Time.local(1999, 3, 1).yday) ! assert_equal(365, Time.local(1999, 12, 31).yday) ! ! # leap century: ! assert_equal( 1, Time.local(2000, 1, 1).yday) ! assert_equal( 59, Time.local(2000, 2, 28).yday) ! assert_equal( 60, Time.local(2000, 2, 29).yday) ! assert_equal( 61, Time.local(2000, 3, 1).yday) ! assert_equal(366, Time.local(2000, 12, 31).yday) ! ! # leap year: ! assert_equal( 1, Time.local(2004, 1, 1).yday) ! assert_equal( 59, Time.local(2004, 2, 28).yday) ! assert_equal( 60, Time.local(2004, 2, 29).yday) ! assert_equal( 61, Time.local(2004, 3, 1).yday) ! assert_equal(366, Time.local(2004, 12, 31).yday) end *************** *** 604,608 **** assert_equal(gmt, t.zone) t = Time.now ! assert(gmt != t.zone) end --- 627,631 ---- assert_equal(gmt, t.zone) t = Time.now ! assert_not_equal(gmt, t.zone) end From zenspider at rubyforge.org Tue May 17 23:56:04 2005 From: zenspider at rubyforge.org (zenspider@rubyforge.org) Date: Tue May 17 23:56:06 2005 Subject: [Rubytests-commit] rubicon/builtin TestPack.rb Message-ID: <200505180356.j4I3u4dS013514@rubyforge.org> Update of /var/cvs/rubytests/rubicon/builtin In directory rubyforge.org:/tmp/cvs-serv13508/builtin Added Files: TestPack.rb Log Message: Added: Pulled in pack/unpack tests from Array/String. --- NEW FILE: TestPack.rb --- $: << File.dirname($0) << File.join(File.dirname($0), "..") require 'rubicon' class TestPack < Rubicon::TestCase def test_pack_A a = %w(cat wombat x yy) assert_equal "catwomx yy ", a.pack("A3A3A3A3") assert_equal "cat", a.pack("A*") assert_equal "cwx yy ", a.pack("A3@1A3@2A3A3") end def test_pack_a a = %w(cat wombat x yy) assert_equal "catwomx\000\000yy\000", a.pack("a3a3a3a3") assert_equal "cat", a.pack("a*") assert_equal "ca", a.pack("a2") assert_equal "cat\000\000", a.pack("a5") end def test_pack_B assert_equal "\x61", ["01100001"].pack("B8") assert_equal "\x61", ["01100001"].pack("B*") assert_equal "\x61", ["0110000100110111"].pack("B8") assert_equal "\x61\x37", ["0110000100110111"].pack("B16") assert_equal "\x61\x37", ["01100001", "00110111"].pack("B8B8") assert_equal "\x60", ["01100001"].pack("B4") assert_equal "\x40", ["01100001"].pack("B2") end def test_pack_b assert_equal "\x86", ["01100001"].pack("b8") assert_equal "\x86", ["01100001"].pack("b*") assert_equal "\x86", ["0110000100110111"].pack("b8") assert_equal "\x86\xec", ["0110000100110111"].pack("b16") assert_equal "\x86\xec", ["01100001", "00110111"].pack("b8b8") assert_equal "\x06", ["01100001"].pack("b4") assert_equal "\x02", ["01100001"].pack("b2") end def test_pack_C assert_equal "ABC", [ 65, 66, 67 ].pack("C3") assert_equal "\377BC", [ -1, 66, 67 ].pack("C*") end def test_pack_c assert_equal "ABC", [ 65, 66, 67 ].pack("c3") assert_equal "\377BC", [ -1, 66, 67 ].pack("c*") end def test_pack_H assert_equal "AB\n\x10", ["4142", "0a", "12"].pack("H4H2H1") assert_equal "AB\n\x02", ["1424", "a0", "21"].pack("h4h2h1") end def test_pack_M assert_equal("abc=02def=\ncat=\n=01=\n", ["abc\002def", "cat", "\001"].pack("M9M3M4")) end def test_pack_m assert_equal "aGVsbG8K\n", ["hello\n"].pack("m") end def test_pack_u assert_equal ",:&5L;&\\*:&5L;&\\*\n", ["hello\nhello\n"].pack("u") end def test_pack_U assert_equal "\xc2\xa9B\xe2\x89\xa0", [0xa9, 0x42, 0x2260].pack("U*") end def test_pack_ugly format = "c2x5CCxsdils_l_a6"; # Need the expression in here to force ary[5] to be numeric. This avoids # test2 failing because ary2 goes str->numeric->str and ary does not. ary = [1, -100, 127, 128, 32767, 987.654321098/100.0, 12345, 123456, -32767, -123456, "abcdef"] x = ary.pack(format) ary2 = x.unpack(format) assert_equal ary.length, ary2.length assert_equal ary.join(':'), ary2.join(':') assert_not_nil(x =~ /def/) end def test_pack_untested skipping "Not tested: D,d & double-precision float, native format\\ E & double-precision float, little-endian byte order\\ e & single-precision float, little-endian byte order\\ F,f & single-precision float, native format\\ G & double-precision float, network (big-endian) byte order\\ g & single-precision float, network (big-endian) byte order\\ I & unsigned integer\\ i & integer\\ L & unsigned long\\ l & long\\ N & long, network (big-endian) byte order\\ n & short, network (big-endian) byte-order\\ P & pointer to a structure (fixed-length string)\\ p & pointer to a null-terminated string\\ S & unsigned short\\ s & short\\ V & long, little-endian byte order\\ v & short, little-endian byte order\\ X & back up a byte\\ x & null byte\\ Z & ASCII string (null padded, count is width)\\ " end end class TestUnpack < Rubicon::TestCase def test_unpack_A assert_equal ["cat", "wom", "x", "yy"], "catwomx yy ".unpack("A3A3A3A3") assert_equal ["cat"], "cat \000\000".unpack("A*") assert_equal ["cwx", "wx", "x", "yy"], "cwx yy ".unpack("A3@1A3@2A3A3") end def test_unpack_a assert_equal ["cat", "wom", "x\000\000", "yy\000"], "catwomx\000\000yy\000".unpack("a3a3a3a3") assert_equal ["cat \000\000"], "cat \000\000".unpack("a*") assert_equal ["ca"], "catdog".unpack("a2") assert_equal ["cat\000\000"], "cat\000\000\000\000\000dog".unpack("a5") end def test_unpack_B assert_equal ["01100001"], "\x61".unpack("B8") assert_equal ["01100001"], "\x61".unpack("B*") assert_equal ["0110000100110111"], "\x61\x37".unpack("B16") assert_equal ["01100001", "00110111"], "\x61\x37".unpack("B8B8") assert_equal ["0110"], "\x60".unpack("B4") assert_equal ["01"], "\x40".unpack("B2") end def test_unpack_b assert_equal ["01100001"], "\x86".unpack("b8") assert_equal ["01100001"], "\x86".unpack("b*") assert_equal ["0110000100110111"], "\x86\xec".unpack("b16") assert_equal ["01100001", "00110111"], "\x86\xec".unpack("b8b8") assert_equal ["0110"], "\x06".unpack("b4") assert_equal ["01"], "\x02".unpack("b2") end def test_unpack_C assert_equal [ 65, 66, 67 ], "ABC".unpack("C3") assert_equal [ 255, 66, 67 ], "\377BC".unpack("C*") end def test_unpack_c assert_equal [ 65, 66, 67 ], "ABC".unpack("c3") assert_equal [ -1, 66, 67 ], "\377BC".unpack("c*") end def test_unpack_H assert_equal ["4142", "0a", "1"], "AB\n\x10".unpack("H4H2H1") end def test_unpack_h assert_equal ["1424", "a0", "2"], "AB\n\x02".unpack("h4h2h1") end def test_unpack_M assert_equal ["abc\002defcat\001", "", ""], "abc=02def=\ncat=\n=01=\n".unpack("M9M3M4") end def test_unpack_m assert_equal ["hello\n"], "aGVsbG8K\n".unpack("m") end def test_unpack_u assert_equal ["hello\nhello\n"], ",:&5L;&\\*:&5L;&\\*\n".unpack("u") end def test_unpack_U assert_equal [0xa9, 0x42, 0x2260], "\xc2\xa9B\xe2\x89\xa0".unpack("U*") end def test_unpack_skipped skipping "Not tested: D,d & double-precision float, native format\\ E & double-precision float, little-endian byte order\\ e & single-precision float, little-endian byte order\\ F,f & single-precision float, native format\\ G & double-precision float, network (big-endian) byte order\\ g & single-precision float, network (big-endian) byte order\\ I & unsigned integer\\ i & integer\\ L & unsigned long\\ l & long\\ m & string encoded in base64 (uuencoded)\\ N & long, network (big-endian) byte order\\ n & short, network (big-endian) byte-order\\ P & pointer to a structure (fixed-length string)\\ p & pointer to a null-terminated string\\ S & unsigned short\\ s & short\\ V & long, little-endian byte order\\ v & short, little-endian byte order\\ X & back up a byte\\ x & null byte\\ Z & ASCII string (null padded, count is width)\\ " end end if __FILE__ == $0 then Rubicon::handleTests TestPack Rubicon::handleTests TestUnpack end From zenspider at rubyforge.org Wed May 18 04:46:47 2005 From: zenspider at rubyforge.org (zenspider@rubyforge.org) Date: Wed May 18 04:46:48 2005 Subject: [Rubytests-commit] rubicon/builtin TestTime.rb Message-ID: <200505180846.j4I8kldS004321@rubyforge.org> Update of /var/cvs/rubytests/rubicon/builtin In directory rubyforge.org:/tmp/cvs-serv4315/builtin Modified Files: TestTime.rb Log Message: Rearranged setup, teardown, and util methods. Cleaned up util_class_now to be more reliable and more clear about errors. I really wish we didn't have to use sleep to test this. Now, only new/now call new/now. All other tests are independent of them and use fixed values, usually via @utc or @loc. Renamed checkComponent to util_check_component to remain consistant and because camelCase sucks and is very non-standard. Eric Hodel made these changes in a ping-pong pairing session. Index: TestTime.rb =================================================================== RCS file: /var/cvs/rubytests/rubicon/builtin/TestTime.rb,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TestTime.rb 18 May 2005 03:55:57 -0000 1.8 --- TestTime.rb 18 May 2005 08:46:45 -0000 1.9 *************** *** 42,46 **** } - # # A random selection of interesting dates --- 42,45 ---- *************** *** 83,92 **** ] ! # # Check a particular date component -- m is the method (day, month, etc) # and i is the index in the date specifications above. ! # ! def checkComponent(m, i) @@dates.each do |x| assert_equal(x.orig[i], Time.local(*x.orig).send(m)) --- 82,102 ---- ] + def setup + @orig_zone = ENV['TZ'] + ENV['TZ'] = 'PST8PDT' + @utc = Time.utc(2001, 2, 3, 4, 5, 6) + @loc = Time.local(2001, 2, 3, 4, 5, 6) + @zone = @loc.zone + end + + def teardown + ENV['TZ'] = @orig_zone + end ! ## # Check a particular date component -- m is the method (day, month, etc) # and i is the index in the date specifications above. ! ! def util_check_component(m, i) @@dates.each do |x| assert_equal(x.orig[i], Time.local(*x.orig).send(m)) *************** *** 97,102 **** end ! def os_specific_epoch ! if $os == MsWin32 || $os == JRuby "Thu Jan 01 00:00:00 1970" else --- 107,123 ---- end ! def util_class_now(method) ! min = 0.1 ! max = min * 3.0 # some ruby impls will be SLOOOW ! t1 = Time.send(method) ! sleep min ! t2 = Time.send(method) ! delta = t2.to_f - t1.to_f ! assert(delta >= min, "time difference must be at least #{min}") ! assert(max >= delta, "time difference should not be more than #{max}") ! end ! ! def util_os_specific_epoch ! if $os == MsWin32 || $os == JRuby then "Thu Jan 01 00:00:00 1970" else *************** *** 105,126 **** end ! def setup ! @orig_zone = ENV['TZ'] ! ENV['TZ'] = 'PST8PDT' ! @utc = Time.utc(2001, 2, 3, 4, 5, 6) ! @loc = Time.local(2001, 2, 3, 4, 5, 6) ! @zone = @loc.zone ! end ! ! def teardown ! ENV['TZ'] = @orig_zone ! end ! ! # ! # Ensure against time travel ! # def test_00sanity # ZenTest SKIP ! assert_operator Time.now.to_i, :>, 960312287 # Tue Jun 6 13:25:06 EDT 2000 end --- 126,139 ---- end ! ## ! # If this test is failing, you've got big problems. Start with Time::at, ! # Time::utc and Time::local before looking at bugs in any of your other ! # code. def test_00sanity # ZenTest SKIP ! assert_equal(Time.at(981173106), Time.utc(2001, 2, 3, 4, 5, 6), ! "If this test fails, don't bother debugging anything else.") ! assert_equal(Time.at(981201906), Time.local(2001, 2, 3, 4, 5, 6), ! "If this test fails, don't bother debugging anything else.") end *************** *** 132,145 **** def test_class_at ! loc = Time.now ! sec = loc.to_i assert_equal(0, Time.at(0).to_i) ! assert_equal(loc, Time.at(loc)) ! assert((Time.at(sec,1000000).to_f - Time.at(sec).to_f) == 1.0) # FIX end def test_class_at_utc ! utc1 = Time.now.utc ! utc2 = Time.at(utc1) assert(utc1.utc?) assert(utc2.utc?) --- 145,157 ---- def test_class_at ! sec = @loc.to_i assert_equal(0, Time.at(0).to_i) ! assert_equal(@loc, Time.at(@loc)) ! assert_in_delta(Time.at(sec,1_000_000).to_f, Time.at(sec).to_f, 1.0) end def test_class_at_utc ! utc1 = @utc ! utc2 = Time.at(@utc) assert(utc1.utc?) assert(utc2.utc?) *************** *** 211,224 **** end - def util_class_now(method) - t1 = Time.send(method) - sleep 0.1 - t2 = Time.send(method) - d = t2.to_f - t1.to_f - assert_in_delta(0.1, d, 0.01) - end - def test_class_now ! util_class_now(:now) end --- 223,228 ---- end def test_class_now ! util_class_now(:now) # Time.now end *************** *** 243,247 **** def test_asctime ! expected = os_specific_epoch assert_equal(expected, Time.at(0).gmtime.asctime) end --- 247,251 ---- def test_asctime ! expected = util_os_specific_epoch assert_equal(expected, Time.at(0).gmtime.asctime) end *************** *** 250,254 **** for taint in [ false, true ] for frozen in [ false, true ] ! a = Time.now a.taint if taint a.freeze if frozen --- 254,258 ---- for taint in [ false, true ] for frozen in [ false, true ] ! a = @loc.dup a.taint if taint a.freeze if frozen *************** *** 264,273 **** def test_ctime ! expected = os_specific_epoch assert_equal(expected, Time.at(0).gmtime.ctime) end def test_day ! checkComponent(:day, 2) end --- 268,277 ---- def test_ctime ! expected = util_os_specific_epoch assert_equal(expected, Time.at(0).gmtime.ctime) end def test_day ! util_check_component(:day, 2) end *************** *** 277,281 **** def test_eql_eh ! t1 = Time.now t2 = Time.at(t1) t3 = t1 + 2e-6 --- 281,285 ---- def test_eql_eh ! t1 = @loc t2 = Time.at(t1) t3 = t1 + 2e-6 *************** *** 290,294 **** def test_getgm # TODO: this only tests local -> gm ! t1 = Time.now loc = Time.at(t1) assert(!t1.gmt?) --- 294,298 ---- def test_getgm # TODO: this only tests local -> gm ! t1 = @loc loc = Time.at(t1) assert(!t1.gmt?) *************** *** 305,309 **** def test_getlocal # TODO: this only tests gm -> local ! t1 = Time.now.gmtime utc = Time.at(t1) assert(t1.gmt?) --- 309,313 ---- def test_getlocal # TODO: this only tests gm -> local ! t1 = @utc utc = Time.at(t1) assert(t1.gmt?) *************** *** 323,328 **** def test_gmt_eh ! assert(!Time.now.gmt?) ! assert(Time.now.gmtime.gmt?) assert(!Time.local(2000).gmt?) assert(Time.gm(2000).gmt?) --- 327,332 ---- def test_gmt_eh ! assert(!@loc.gmt?) ! assert(@utc.gmt?) assert(!Time.local(2000).gmt?) assert(Time.gm(2000).gmt?) *************** *** 335,339 **** def test_gmtime # TODO: this only tests local -> gm ! t = Time.now loc = Time.at(t) assert(!t.gmt?) --- 339,343 ---- def test_gmtime # TODO: this only tests local -> gm ! t = @loc loc = Time.at(t) assert(!t.gmt?) *************** *** 356,364 **** def test_hour ! checkComponent(:hour, 3) end def test_initialize ! util_class_now(:new) end --- 360,368 ---- def test_hour ! util_check_component(:hour, 3) end def test_initialize ! util_class_now(:new) # Time.new end *************** *** 405,409 **** def test_localtime # TODO: this only tests gm -> local ! t = Time.now.gmtime utc = Time.at(t) assert(t.gmt?) --- 409,413 ---- def test_localtime # TODO: this only tests gm -> local ! t = @utc utc = Time.at(t) assert(t.gmt?) *************** *** 414,422 **** def test_mday ! checkComponent(:mday, 2) end def test_min ! checkComponent(:min, 4) end --- 418,426 ---- def test_mday ! util_check_component(:mday, 2) end def test_min ! util_check_component(:min, 4) end *************** *** 433,441 **** def test_mon ! checkComponent(:mon, 1) end def test_month ! checkComponent(:month, 1) end --- 437,445 ---- def test_mon ! util_check_component(:mon, 1) end def test_month ! util_check_component(:month, 1) end *************** *** 448,452 **** def test_sec ! checkComponent(:sec, 5) end --- 452,456 ---- def test_sec ! util_check_component(:sec, 5) end *************** *** 512,516 **** def test_to_a ! t = Time.now a = t.to_a assert_equal(t.sec, a[0]) --- 516,520 ---- def test_to_a ! t = @loc a = t.to_a assert_equal(t.sec, a[0]) *************** *** 618,622 **** def test_year ! checkComponent(:year, 0) end --- 622,626 ---- def test_year ! util_check_component(:year, 0) end *************** *** 624,630 **** gmt = "UTC" Version.less_than("1.7") do gmt = "GMT" end ! t = Time.now.gmtime assert_equal(gmt, t.zone) ! t = Time.now assert_not_equal(gmt, t.zone) end --- 628,634 ---- gmt = "UTC" Version.less_than("1.7") do gmt = "GMT" end ! t = @utc assert_equal(gmt, t.zone) ! t = @loc assert_not_equal(gmt, t.zone) end From zenspider at rubyforge.org Thu May 26 18:19:54 2005 From: zenspider at rubyforge.org (zenspider@rubyforge.org) Date: Thu May 26 18:19:56 2005 Subject: [Rubytests-commit] rubicon/builtin TestRange.rb Message-ID: <200505262219.j4QMJsdS028037@rubyforge.org> Update of /var/cvs/rubytests/rubicon/builtin In directory rubyforge.org:/tmp/cvs-serv28032/builtin Modified Files: TestRange.rb Log Message: Revamped TestRange: + switched from first..last to Range.new(first, last) to test custom impls. + Hopefully syntax tests do a good job on .. and ... + refactored synonymous tests... lots of code duplication + Filled in some missing edge cases, esp for non-int/string tests. + Added missing test methods: test_inspect Index: TestRange.rb =================================================================== RCS file: /var/cvs/rubytests/rubicon/builtin/TestRange.rb,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TestRange.rb 29 Dec 2004 23:32:52 -0000 1.7 --- TestRange.rb 26 May 2005 22:19:51 -0000 1.8 *************** *** 2,11 **** require 'rubicon' - class TestRange < Rubicon::TestCase ! def test_EQUAL # '==' ! generic_test_EQUAL(:==) ! end # --- 2,9 ---- require 'rubicon' class TestRange < Rubicon::TestCase ! ############################################################ ! # Test Utilities: # *************** *** 19,100 **** # the methods == and eql? differ. # ! def generic_test_EQUAL(method) # closed interval ! assert_equal(false, ((3..5).send(method, 3..4))) ! assert_equal(true, ((3..5).send(method, 3..5))) ! assert_equal(false, ((3..5).send(method, 3..6))) ! assert_equal(false, ((3..5).send(method, 2..5))) ! assert_equal(false, ((3..5).send(method, 4..5))) # half-open interval ! assert_equal(false, ((3...5).send(method, 3...4))) ! assert_equal(true, ((3...5).send(method, 3...5))) ! assert_equal(false, ((3...5).send(method, 3...6))) ! assert_equal(false, ((3...5).send(method, 2...5))) ! assert_equal(false, ((3...5).send(method, 4...5))) # half-open / closed interval: never equal ! assert_equal(false, ((3...5).send(method, 3..4))) ! assert_equal(false, ((3...5).send(method, 3..5))) ! assert_equal(false, ((3...5).send(method, 3..6))) ! assert_equal(false, ((3...5).send(method, 2..5))) ! assert_equal(false, ((3...5).send(method, 4..5))) # closed / half-open interval: never equal ! assert_equal(false, ((3..5).send(method, 3...4))) ! assert_equal(false, ((3..5).send(method, 3...5))) ! assert_equal(false, ((3..5).send(method, 3...6))) ! assert_equal(false, ((3..5).send(method, 2...5))) ! assert_equal(false, ((3..5).send(method, 4...5))) # non-Range argument ! assert_equal(false, ((5..10).send(method, Object.new))) ! assert_equal(false, ((5...10).send(method, Object.new))) end ! def test_VERY_EQUAL # '===' ! # closed interval ! assert_equal(false, ((5..10) === 4)) ! assert_equal(true, ((5..10) === 5)) ! assert_equal(true, ((5..10) === 6)) ! assert_equal(true, ((5..10) === 9)) ! assert_equal(true, ((5..10) === 10)) ! assert_equal(false, ((5..10) === 11)) ! assert_equal(false, ((5..10) === 4.5)) ! assert_equal(true, ((5..10) === 5.5)) ! assert_equal(true, ((5..10) === 7.5)) ! assert_equal(true, ((5..10) === 9.5)) ! assert_equal(false, ((5..10) === 10.5)) ! # half-open interval ! assert_equal(false, ((5...10) === 4)) ! assert_equal(true, ((5...10) === 5)) ! assert_equal(true, ((5...10) === 6)) ! assert_equal(true, ((5...10) === 9)) ! assert_equal(false, ((5...10) === 10)) ! assert_equal(false, ((5...10) === 11)) ! assert_equal(false, ((5...10) === 4.5)) ! assert_equal(true, ((5...10) === 5.5)) ! assert_equal(true, ((5...10) === 7.5)) ! assert_equal(true, ((5...10) === 9.5)) ! assert_equal(false, ((5...10) === 10.5)) # non-comparable argument ! assert_equal(false, ((5..10) === Object.new)) ! assert_equal(false, ((5...10) === Object.new)) # misc gotit = false case 52 ! when 0..49 fail("Shouldn't have matched") ! when 50..75 gotit = true else --- 17,174 ---- # the methods == and eql? differ. # ! def util_test_equals(method) ! ! r25 = Range.new(2, 5) ! r34 = Range.new(3, 4) ! r35 = Range.new(3, 5) ! r36 = Range.new(3, 6) ! r45 = Range.new(4, 5) ! rx25 = Range.new(2, 5, true) ! rx34 = Range.new(3, 4, true) ! rx35 = Range.new(3, 5, true) ! rx36 = Range.new(3, 6, true) ! rx45 = Range.new(4, 5, true) ! # closed interval ! assert_equal(false, r35.send(method, r34)) ! assert_equal(true, r35.send(method, r35)) ! assert_equal(false, r35.send(method, r36)) ! assert_equal(false, r35.send(method, r25)) ! assert_equal(false, r35.send(method, r45)) # half-open interval ! assert_equal(false, rx35.send(method, rx34)) ! assert_equal(true, rx35.send(method, rx35)) ! assert_equal(false, rx35.send(method, rx36)) ! assert_equal(false, rx35.send(method, rx25)) ! assert_equal(false, rx35.send(method, rx45)) # half-open / closed interval: never equal ! assert_equal(false, rx35.send(method, r34)) ! assert_equal(false, rx35.send(method, r35)) ! assert_equal(false, rx35.send(method, r36)) ! assert_equal(false, rx35.send(method, r25)) ! assert_equal(false, rx35.send(method, r45)) # closed / half-open interval: never equal ! assert_equal(false, r35.send(method, rx34)) ! assert_equal(false, r35.send(method, rx35)) ! assert_equal(false, r35.send(method, rx36)) ! assert_equal(false, r35.send(method, rx25)) ! assert_equal(false, r35.send(method, rx45)) # non-Range argument ! assert_equal(false, r35.send(method, Object.new)) ! assert_equal(false, rx35.send(method, Object.new)) end ! def util_test_end(msg) ! assert_equal(10, Range.new(1, 10).send(msg)) ! assert_equal(11, Range.new(1, 11, true).send(msg)) ! assert_equal("z", Range.new("a", "z").send(msg)) ! assert_equal("A", Range.new("a", "A", true).send(msg)) ! end ! def util_member(method) ! is = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] ! xs = is.map {|x| 0.5 + x} ! iss = ["aj", "ak", "al", "am", "an" ,"ao" "ap"] ! xss = ["ajjj", "akkk", "alll", "ammm", "annn" ,"aooo" "appp"] ! r47 = Range.new(4, 7) ! rx47 = Range.new(4, 7, true) ! r_akam = Range.new("ak", "am") ! rx_akam = Range.new("ak", "am", true) ! # as discrete range ! assert_equal([4, 5, 6, 7 ], is.select {|i| r47.send(method, i) }) ! assert_equal([4, 5, 6], is.select {|i| rx47.send(method, i) }) ! ! assert_equal(["ak","al","am"], iss.select {|i| r_akam.send(method, i) }) ! assert_equal(["ak","al"], iss.select {|i| rx_akam.send(method, i) }) ! ! # as continuous range ! assert_equal([4.5, 5.5, 6.5], xs.select {|x| r47.send(method, x) }) ! assert_equal([4.5, 5.5, 6.5], xs.select {|x| rx47.send(method, x) }) ! ! assert_equal(["akkk","alll"], xss.select {|i| r_akam.send(method, i) }) ! assert_equal(["akkk","alll"], xss.select {|i| rx_akam.send(method, i) }) # non-comparable argument ! assert_equal(false, Range.new(5, 10) === Object.new) ! assert_equal(false, Range.new(5, 10, true) === Object.new) ! end ! ! def util_step_tester(acc_facit, range, *step_args) ! acc = [] ! res = range.step(*step_args) {|x| acc << x } ! assert_equal(acc_facit, acc) ! assert_same(range, res) ! end ! ! def util_each(first, last, exclude, expected) ! index = first ! count = 0 ! Range.new(first, last, exclude).each do |x| ! assert_equal(index, x) ! index = index.succ ! count += 1 ! end ! assert_equal(expected, count) ! end ! ! ############################################################ ! # Test Methods ! ! # TODO: need to test new/initialize, esp w/ bad values ! ! def test_begin ! assert_equal(1, Range.new(1, 10).begin) ! assert_equal("a", Range.new("a", "z").begin) ! assert_equal(1, Range.new(1, 10, true).begin) ! assert_equal("a", Range.new("a", "z", true).begin) ! end ! ! def test_each ! util_each(1, 10, false, 10) ! util_each(1, 10, true, 9) ! ! util_each("A", "J", false, 10) ! util_each("A", "J", true, 9) ! ! # TODO: test something that has a .succ, but is neither int nor string ! t1 = Time.at(1) ! t10 = Time.at(10) ! util_each(t1, t10, false, 10) ! util_each(t1, t10, true, 9) ! ! # test something that has no .succ: ! # HACK: ! # util_each(Object.new, Object.new, false, 10) ! # util_each(Object.new, Object.new, true, 9) ! end ! ! def test_eql_eh ! util_test_equals(:eql?) ! end ! ! def test_equals2 # '==' ! util_test_equals(:==) ! end ! ! def test_equals3 # '===' ! util_member(:===) # misc gotit = false case 52 ! when Range.new(0, 49) fail("Shouldn't have matched") ! when Range.new(50, 75) gotit = true else *************** *** 105,111 **** gotit = false case 50 ! when 0..49 fail("Shouldn't have matched") ! when 50..75 gotit = true else --- 179,185 ---- gotit = false case 50 ! when Range.new(0, 49) fail("Shouldn't have matched") ! when Range.new(50, 75) gotit = true else *************** *** 116,122 **** gotit = false case 75 ! when 0..49 fail("Shouldn't have matched") ! when 50..75 gotit = true else --- 190,196 ---- gotit = false case 75 ! when Range.new(0, 49) fail("Shouldn't have matched") ! when Range.new(50, 75) gotit = true else *************** *** 126,306 **** end ! def test_begin ! assert_equal(1, (1..10).begin) ! assert_equal("a", ("a".."z").begin) ! assert_equal(1, (1...10).begin) ! assert_equal("a", ("a"..."z").begin) ! end ! ! def test_each ! index = 1 ! count = 0 ! (1..10).each {|x| assert_equal(index, x) ! index += 1 ! count += 1 } ! assert_equal(10,count) ! ! index = "A" ! count = 0 ! ("A".."J").each {|x| assert_equal(index, x) ! index.succ! ! count += 1 } ! assert_equal(10,count) ! ! end ! ! def test_end ! assert_equal(10, (1..10).end) ! assert_equal(11, (1...11).end) ! assert_equal("z", ("a".."z").end) ! assert_equal("A", ("a"..."A").end) ! end ! ! def test_eql? ! generic_test_EQUAL(:eql?) ! end ! ! def test_exclude_end? ! assert_equal(true, (1...10).exclude_end?) ! assert_equal(false,(1..10).exclude_end?) ! assert_equal(true, ("A"..."Z").exclude_end?) ! assert_equal(false,("A".."Z").exclude_end?) end def test_first ! assert_equal(1, (1..10).first) ! assert_equal("a", ("a".."z").first) ! assert_equal(1, (1...10).first) ! assert_equal("a", ("a"..."z").first) end def test_hash ! assert_equal((5..9).hash, (5..9).hash) ! assert_equal((51..111).hash, (51..111).hash) ! ! assert_equal((5...9).hash, (5...9).hash) ! assert_equal((51...111).hash, (51...111).hash) ! ! # these comparisons doesn't have to be false, it just seems a good ! # idea that a small "delta" should give a real "delta" in the hash ! # ! assert_not_equal((5..9).hash, (5...9).hash) ! ! assert_not_equal((5..9).hash, (5..8).hash) ! assert_not_equal((5..9).hash, (5..10).hash) ! assert_not_equal((5..9).hash, (4..9).hash) ! assert_not_equal((5..9).hash, (6..9).hash) ! end ! ! def test_include? ! is = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] ! xs = is.map {|x| 0.5 + x} ! iss = ["aj", "ak", "al", "am", "an" ,"ao" "ap"] ! xss = ["ajjj", "akkk", "alll", "ammm", "annn" ,"aooo" "appp"] ! ! # as discrete range ! assert_equal([4, 5, 6, 7 ], is.select {|i| (4..7).include?(i) }) ! assert_equal([4, 5, 6], is.select {|i| (4...7).include?(i) }) ! ! assert_equal(["ak","al","am"], iss.select {|i| ("ak".."am").include?(i) }) ! assert_equal(["ak","al"], iss.select {|i| ("ak"..."am").include?(i) }) ! # as continuous range ! assert_equal([4.5, 5.5, 6.5], xs.select {|x| (4..7).include?(x) }) ! assert_equal([4.5, 5.5, 6.5], xs.select {|x| (4...7).include?(x) }) ! assert_equal(["akkk","alll"], xss.select {|i| ("ak".."am").include?(i) }) ! assert_equal(["akkk","alll"], xss.select {|i| ("ak"..."am").include?(i) }) ! end ! def test_last ! assert_equal(10, (1..10).last) ! assert_equal(11, (1...11).last) ! assert_equal("z", ("a".."z").last) ! assert_equal("A", ("a"..."A").last) end ! Version.less_than("1.7") do ! def test_length ! assert_equal(10, (1..10).length) ! assert_equal(10, (1...11).length) ! assert_equal(1000, (1..1000).length) ! assert_equal(26, ("A".."Z").length) ! end end ! def test_member? ! is = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] ! xs = is.map {|x| 0.5 + x} ! iss = ["aj", "ak", "al", "am", "an" ,"ao" "ap"] ! xss = ["ajjj", "akkk", "alll", "ammm", "annn" ,"aooo" "appp"] ! ! # as discrete range ! assert_equal([4, 5, 6, 7 ], is.select {|i| (4..7).member?(i) }) ! assert_equal([4, 5, 6], is.select {|i| (4...7).member?(i) }) ! ! assert_equal(["ak","al","am"], iss.select {|i| ("ak".."am").member?(i) }) ! assert_equal(["ak","al"], iss.select {|i| ("ak"..."am").member?(i) }) ! ! Version.less_or_equal("1.8.1") do ! # does NOT work as continuous range (c.f. include?) ! assert_equal([], xs.select {|x| (4..7).member?(x) }) ! assert_equal([], xs.select {|x| (4...7).member?(x) }) ! ! assert_equal([], xss.select {|i| ("ak".."am").member?(i) }) ! assert_equal([], xss.select {|i| ("ak"..."am").member?(i) }) ! end ! Version.greater_than("1.8.1") do ! # as continuous range ! assert_equal([4.5, 5.5, 6.5], xs.select {|x| (4..7).member?(x) }) ! assert_equal([4.5, 5.5, 6.5], xs.select {|x| (4...7).member?(x) }) ! ! assert_equal(["akkk","alll"], xss.select {|i| ("ak".."am").member?(i) }) ! assert_equal(["akkk","alll"], xss.select {|i| ("ak"..."am").member?(i) }) ! end end ! Version.less_than("1.7") do ! def test_size ! assert_equal(10, (1..10).size) ! assert_equal(10, (1...11).size) ! assert_equal(1000, (1..1000).size) ! assert_equal(26, ("A".."Z").size) ! end end ! def _step_tester(acc_facit, range, *step_args) ! acc = [] ! res = range.step(*step_args) {|x| acc << x } ! assert_equal(acc_facit, acc) ! assert_same(range, res) end def test_step # n=1 default in step(n) ! _step_tester([5,6,7,8,9], 5..9) ! _step_tester([5,6,7,8], 5...9) # explicit n=1 ! _step_tester([5,6,7,8,9], 5..9, 1) ! _step_tester([5,6,7,8], 5...9, 1) # n=2 ! _step_tester([5,7,9], 5..9, 2) ! _step_tester([5,7], 5...9, 2) # n=3 ! _step_tester([5,8], 5..9, 3) ! _step_tester([5,8], 5...9, 3) # n=4 ! _step_tester([5,9], 5..9, 4) ! _step_tester([5], 5...9, 4) end def test_to_s ! assert_equal("1..10",(1..10).to_s) end end --- 200,282 ---- end ! def test_exclude_end_eh ! assert_equal(true, Range.new(1, 10, true).exclude_end?) ! assert_equal(false,Range.new(1, 10).exclude_end?) ! assert_equal(true, Range.new("A", "Z", true).exclude_end?) ! assert_equal(false,Range.new("A", "Z").exclude_end?) end def test_first ! assert_equal(1, Range.new(1, 10).first) ! assert_equal("a", Range.new("a", "z").first) ! assert_equal(1, Range.new(1, 10, true).first) ! assert_equal("a", Range.new("a", "z", true).first) end def test_hash ! assert_equal(Range.new(5, 9).hash, Range.new(5, 9).hash) ! assert_equal(Range.new("A", "Z").hash, Range.new("A", "Z").hash) ! assert_equal(Range.new(5, 9, true).hash, Range.new(5, 9, true).hash) ! assert_equal(Range.new("A", "Z", true).hash, Range.new("A", "Z", true).hash) ! assert_not_equal(Range.new(5, 9).hash, Range.new(5, 9, true).hash) ! assert_not_equal(Range.new("A", "Z").hash, Range.new("A", "Z", true).hash) ! assert_not_equal(Range.new(5, 9).hash, Range.new(5, 8).hash) ! assert_not_equal(Range.new("A", "Z").hash, Range.new("a", "Z", true).hash) end ! def test_include_eh ! util_member(:include?) end ! def test_end ! util_test_end(:end) end ! def test_last ! util_test_end(:last) end ! def test_member_eh ! util_member(:member?) end def test_step # n=1 default in step(n) ! util_step_tester([5,6,7,8,9], Range.new(5, 9)) ! util_step_tester([5,6,7,8], Range.new(5, 9, true)) # explicit n=1 ! util_step_tester([5,6,7,8,9], Range.new(5, 9), 1) ! util_step_tester([5,6,7,8], Range.new(5, 9, true), 1) # n=2 ! util_step_tester([5,7,9], Range.new(5, 9), 2) ! util_step_tester([5,7], Range.new(5, 9, true), 2) # n=3 ! util_step_tester([5,8], Range.new(5, 9), 3) ! util_step_tester([5,8], Range.new(5, 9, true), 3) # n=4 ! util_step_tester([5,9], Range.new(5, 9), 4) ! util_step_tester([5], Range.new(5, 9, true), 4) end def test_to_s ! assert_equal('1..10', Range.new(1, 10).to_s) ! assert_equal('1...10', Range.new(1, 10, true).to_s) ! assert_equal('a..z', Range.new('a', 'z').to_s) ! assert_equal('a...z', Range.new('a', 'z', true).to_s) end + def test_inspect + assert_equal('1..10', Range.new(1, 10).inspect) + assert_equal('1...10', Range.new(1, 10, true).inspect) + assert_equal('"a".."z"', Range.new('a', 'z').inspect) + assert_equal('"a"..."z"', Range.new('a', 'z', true).inspect) + end end