PageRenderTime 44ms CodeModel.GetById 22ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. #!/usr/bin/env ruby
  2. #
  3. # Put script description here.
  4. #
  5. #
  6. #
  7. #
  8. #
  9. require 'swig_assert'
  10. require 'li_std_set'
  11. include Li_std_set
  12. swig_assert_each_line(<<'EOF', binding)
  13. s = Set_string.new
  14. s.push("a")
  15. s.push("b")
  16. s << "c"
  17. sum = ''
  18. s.each { |x| sum << x }
  19. sum == 'abc'
  20. b = s.begin # only if swig iterators are on
  21. e = s.end
  22. sum = ''
  23. while b != e; sum << b.value; b.next; end
  24. sum == 'abc'
  25. b = s.rbegin # only if swig iterators are on
  26. e = s.rend
  27. sum = ''
  28. while b != e; sum << b.value; b.next; end
  29. sum == 'cba'
  30. si = Set_int.new
  31. si << 1
  32. si.push(2)
  33. si.push(3)
  34. i = s.begin()
  35. i.next()
  36. s.erase(i)
  37. s.to_s == 'ac'
  38. b = s.begin
  39. e = s.end
  40. e - b == 2
  41. m = b + 1
  42. m.value == 'c'
  43. s = LanguageSet.new
  44. s.insert([1,2])
  45. s.insert(1)
  46. s.insert("hello")
  47. s.to_a == [1,[1,2],'hello'] # sort order: s.sort {|a,b| a.hash <=> b.hash}
  48. EOF