File: listtest.rb

package info (click to toggle)
ruby-rjb 1.5.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 704 kB
  • sloc: ansic: 3,859; ruby: 2,604; java: 247; makefile: 35; sh: 3
file content (56 lines) | stat: -rw-r--r-- 1,047 bytes parent folder | download | duplicates (4)
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
#!/usr/local/env ruby -Ku
# encoding: utf-8
=begin
  Copyright(c) 2012 arton
=end

begin
  require 'rjb/list'
rescue LoadError 
  require 'rubygems' 
  require 'rjb/list'
end
require 'test/unit'
require 'fileutils'

class ListTest < Test::Unit::TestCase
  include Rjb
  def test_create
    ja = import('java.util.ArrayList')
    a = ja.new
    a.add(1)
    a.add(2)
    a.add(3)
    n = 1
    a.each do |x|
      assert_equal n, x.intValue
      n += 1
    end
    assert_equal 4, n
  end
  def test_returned_proxy
    ja = import('java.util.Arrays')
    a = ja.as_list([1, 2, 3])
    n = 1
    a.each do |x|
      assert_equal n, x.intValue
      n += 1
    end
    assert_equal 4, n
  end
  def test_iterator
    ja = import('java.util.Arrays')
    it = ja.as_list([1, 2, 3]).iterator
    n = 1
    it.each do |x|
      assert_equal n, x.intValue
      n += 1
    end
    assert_equal 4, n
  end
  def test_enumerable
    ja = import('java.util.Arrays')
    assert_equal 55, ja.as_list((1..10).to_a).inject(0) {|r, e| r + e.intValue}
  end
end