File: test_stackable.rb

package info (click to toggle)
ruby-facets 2.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 9,824 kB
  • sloc: ruby: 25,483; xml: 90; makefile: 20
file content (94 lines) | stat: -rw-r--r-- 2,230 bytes parent folder | download
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Test for facets/string/stackable

require 'facets/string/stackable.rb'

require 'test/unit'

class TestStringAccess < Test::Unit::TestCase

  def test_pop_01
    s =  "012345"
    assert_raises( ArgumentError ) { s.pop(1) }
  end

  def test_pop_02
    s =  "012345"
    assert_equal( "5", s.pop )
    assert_equal( "01234", s )
    assert_equal( "4", s.pop )
    assert_equal( "0123", s )
    assert_equal( "3", s.pop )
    assert_equal( "012", s )
    assert_equal( "2", s.pop )
    assert_equal( "01", s )
    assert_equal( "1", s.pop )
    assert_equal( "0", s )
    assert_equal( "0", s.pop )
    assert_equal( "", s )
    assert_equal( "", s.pop )
    assert_equal( "", s )
  end

  def test_push_01
    s = ""
    #assert_raises( ArgumentError ) { s.push }
    assert_raises( ArgumentError ) { s.push(1,2) }
  end

  def test_push_02
    s = ""
    assert_equal( "0", s.push("0") )
    assert_equal( "01", s.push("1") )
    assert_equal( "012", s.push("2") )
    assert_equal( "0123", s.push("3") )
    assert_equal( "01234", s.push("4") )
    assert_equal( "012345", s.push("5") )
  end

  def test_poke_01
    a = ""
    assert_raises( ArgumentError ) { a.poke(1,2) }
  end

  def test_poke_02
    s = ""
    assert_equal( "0", s.poke("0") )
    assert_equal( "10", s.poke("1") )
    assert_equal( "210", s.poke("2") )
    assert_equal( "3210", s.poke("3") )
    assert_equal( "43210", s.poke("4") )
    assert_equal( "543210", s.poke("5") )
  end

  def test_shift_01
    s = "012345"
    assert_raises( ArgumentError ) { s.shift(1) }
  end

  def test_shift_02
    s = "012345"
    assert_equal( "12345", s.shift )
    assert_equal( "2345", s.shift )
    assert_equal( "345", s.shift )
    assert_equal( "45", s.shift )
    assert_equal( "5", s.shift )
    assert_equal( "", s.shift )
    assert_equal( "", s.shift )
  end

  def test_unshift_01
    s = ""
    assert_raises( ArgumentError ) { s.unshift(1,2) }
  end

  def test_unshift_02
    s = ""
    assert_equal( "0", s.unshift("0") )
    assert_equal( "10", s.unshift("1") )
    assert_equal( "210", s.unshift("2") )
    assert_equal( "3210", s.unshift("3") )
    assert_equal( "43210", s.unshift("4") )
    assert_equal( "543210", s.unshift("5") )
  end

end