PageRenderTime 15ms CodeModel.GetById 1ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/ruby/li_std_set_runme.rb

#
Ruby | 63 lines | 40 code | 15 blank | 8 comment | 11 complexity | 7527b164c058e38fe16c1ca78686d599 MD5 | raw file
 1#!/usr/bin/env ruby
 2#
 3# Put script description here.
 4#
 5# 
 6# 
 7# 
 8#
 9
10require 'swig_assert'
11
12require 'li_std_set'
13include Li_std_set
14
15swig_assert_each_line(<<'EOF', binding)
16s = Set_string.new
17
18s.push("a")
19s.push("b")
20s << "c"
21
22sum = ''
23s.each { |x| sum << x }
24sum == 'abc'
25
26b = s.begin  # only if swig iterators are on
27e = s.end
28sum = ''
29while b != e; sum << b.value; b.next; end
30sum == 'abc'
31
32b = s.rbegin  # only if swig iterators are on
33e = s.rend
34sum = ''
35while b != e; sum << b.value; b.next; end
36sum == 'cba'
37
38
39si = Set_int.new
40si << 1
41si.push(2)
42si.push(3)
43
44i = s.begin()
45i.next()
46s.erase(i)
47s.to_s == 'ac'
48
49b = s.begin
50e = s.end
51e - b == 2
52
53m = b + 1
54m.value == 'c'
55
56s = LanguageSet.new
57s.insert([1,2])
58s.insert(1)
59s.insert("hello")
60s.to_a == [1,[1,2],'hello']  # sort order: s.sort {|a,b| a.hash <=> b.hash}
61
62EOF
63