Fix for JRUBY-2882. Handle error messages related to constructors better
[jruby.git] / bench / shootout / lists.ruby
blobfc2aa0597361e6175da142a4ae13035ddb0811d4
1 #!/usr/bin/ruby
2 # -*- mode: ruby -*-
3 # $Id: lists.ruby,v 1.3 2005-06-10 16:59:56 igouy-guest Exp $
4 # http://www.bagley.org/~doug/shootout/
6 NUM = Integer(ARGV.shift || 1)
8 SIZE = 10000
10 def test_lists()
11 # create a list of integers (Li1) from 1 to SIZE
12 li1 = (1..SIZE).to_a
13 # copy the list to li2 (not by individual items)
14 li2 = li1.dup
15 # remove each individual item from left side of li2 and
16 # append to right side of li3 (preserving order)
17 li3 = Array.new
18 while (not li2.empty?)
19 li3.push(li2.shift)
20 end
21 # li2 must now be empty
22 # remove each individual item from right side of li3 and
23 # append to right side of li2 (reversing list)
24 while (not li3.empty?)
25 li2.push(li3.pop)
26 end
27 # li3 must now be empty
28 # reverse li1 in place
29 li1.reverse!
30 # check that first item is now SIZE
31 if li1[0] != SIZE then
32 p "not SIZE"
33 return(0)
34 end
35 # compare li1 and li2 for equality
36 if li1 != li2 then
37 return(0)
38 end
39 # return the length of the list
40 return(li1.length)
41 end
43 for iter in 1 .. NUM
44 result = test_lists()
45 end
46 print result, "\n"