sarah 0.0.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,52 @@
1
+ require 'minitest/autorun'
2
+ require 'sarah'
3
+
4
+ class TestSarah_12 < MiniTest::Unit::TestCase
5
+
6
+ def test_has_key
7
+ s = Sarah[1, 2, 5 => 3, 6 => 4, :vii => 5, 'eight' => 6]
8
+
9
+ assert_equal true, s.has_key?(0), 'has key 0'
10
+ assert_equal false, s.has_key?(2), 'has key 2'
11
+ assert_equal true, s.has_key?(5), 'has key 5'
12
+ assert_equal false, s.has_key?(7), 'has key 7'
13
+ assert_equal true, s.has_key?(:vii), 'has key :vii'
14
+ assert_equal true, s.has_key?('eight'), "has key 'eight'"
15
+ end
16
+
17
+ def test_has_value
18
+ s = Sarah[1, 2, 5 => 3, 6 => 4, :vii => 5, 'eight' => 6]
19
+
20
+ assert_equal false, s.has_value?(0), 'has value 0'
21
+ assert_equal true, s.has_value?(1), 'has value 1'
22
+ assert_equal true, s.has_value?(3), 'has value 3'
23
+ assert_equal true, s.has_value?(5), 'has value 5'
24
+ assert_equal false, s.has_value?(7), 'has value 7'
25
+ end
26
+
27
+ def test_index
28
+ s = Sarah[1, 2, 3, 3, 5 => 1, 6 => 2, :vii => 3, 'eight' => 4]
29
+
30
+ assert_equal 1, s.index(2), 'index 2'
31
+ assert_equal 2, s.index(3), 'index 3'
32
+ assert_equal(2, s.index { |v| v == 3 }, 'index { v == 3 }')
33
+ assert_equal nil, s.index(4), 'index 4'
34
+ assert_equal nil, s.index(5), 'index 5'
35
+ assert_equal 5, s.rindex(1), 'rindex 1'
36
+ assert_equal 3, s.rindex(3), 'rindex 3'
37
+ assert_equal(3, s.rindex { |v| v == 3 }, 'rindex { v == 3 }')
38
+ end
39
+
40
+ def test_key
41
+ s = Sarah[1, 2, 3, 3, 5 => 1, 6 => 2, :vii => 4, 'eight' => 5]
42
+
43
+ assert_equal 0, s.key(1), 'key 1'
44
+ assert_equal 1, s.key(2), 'key 2'
45
+ assert_equal 2, s.key(3), 'key 3'
46
+ assert_equal :vii, s.key(4), 'key 4'
47
+ assert_equal 'eight', s.key(5), 'key 5'
48
+ end
49
+
50
+ end
51
+
52
+ # END
@@ -0,0 +1,155 @@
1
+ require 'minitest/autorun'
2
+ require 'sarah'
3
+
4
+ class TestSarah_13 < MiniTest::Unit::TestCase
5
+
6
+ def test_assoc
7
+ s = Sarah[ [ :one, 'one', 1 ], [ 'two', 'two', 2 ],
8
+ 'three' => [ 'three', 3 ] ]
9
+
10
+ assert_equal [ :one, 'one', 1 ], s.assoc(:one), 'assoc ary :one'
11
+ assert_equal [ 'two', 'two', 2 ], s.assoc('two'), 'assoc ary two'
12
+ assert_equal [ 'three', 'three', 3 ], s.assoc('three'),
13
+ 'assoc hsh three'
14
+ end
15
+
16
+ def test_collect
17
+ s0 = Sarah[ 1, 2 => 2, '4' => 4 ]
18
+
19
+ s1 = Sarah.new(s0)
20
+ assert_equal({ 0 => 1, 2 => 2, '4' => 4 }, s1.to_h,
21
+ 'collect verify copy')
22
+
23
+ s1 = Sarah.new(s0).collect!(:seq) { |v| v * 2 }
24
+ assert_equal({ 0 => 2, 2 => 2, '4' => 4 }, s1.to_h, 'collect! :seq')
25
+
26
+ s1 = Sarah.new(s0).collect!(:spr) { |v| v * 2 }
27
+ assert_equal({ 0 => 1, 2 => 4, '4' => 4 }, s1.to_h, 'collect! :spr')
28
+
29
+ s1 = Sarah.new(s0).collect!(:ary) { |v| v * 2 }
30
+ assert_equal({ 0 => 2, 2 => 4, '4' => 4 }, s1.to_h, 'collect! :ary')
31
+
32
+ s1 = Sarah.new(s0).collect!(:rnd) { |v| v * 2 }
33
+ assert_equal({ 0 => 1, 2 => 2, '4' => 8 }, s1.to_h, 'collect! :rnd')
34
+
35
+ s1 = Sarah.new(s0).collect!(:all) { |v| v * 2 }
36
+ assert_equal({ 0 => 2, 2 => 4, '4' => 8 }, s1.to_h, 'collect! :all')
37
+
38
+ s1 = Sarah.new(s0).collect! { |v| v * 2 }
39
+ assert_equal({ 0 => 2, 2 => 4, '4' => 8 }, s1.to_h, 'collect!')
40
+ end
41
+
42
+ def test_compact
43
+ s0 = Sarah[ nil, 1, nil, 2, 10 => nil, 12 => 12, 14 => nil, 16 => 16,
44
+ :a => nil, :b => ?b, :c => nil, :d => ?d ]
45
+
46
+ s1 = Sarah.new(s0).compact!(:ary)
47
+ assert_equal [ 1, 2, 12, 16, { :a => nil, :b => ?b,
48
+ :c => nil, :d => ?d } ], s1.to_a, 'compact! :ary'
49
+
50
+ s1 = Sarah.new(s0).compact!(:rnd)
51
+ assert_equal [ nil, 1, nil, 2, { 10 => nil, 12 => 12, 14 => nil,
52
+ 16 => 16, :b => ?b, :d => ?d } ], s1.to_a, 'compact! :rnd'
53
+
54
+ s1 = Sarah.new(s0).compact!(:all)
55
+ assert_equal [ 1, 2, 12, 16, { :b => ?b, :d => ?d } ],
56
+ s1.to_a, 'compact! :all'
57
+
58
+ s1 = Sarah.new(s0).compact!
59
+ assert_equal [ 1, 2, 12, 16, { :b => ?b, :d => ?d } ],
60
+ s1.to_a, 'compact!'
61
+ end
62
+
63
+ def test_empty
64
+ s = Sarah[0, 1, :key => 'value']
65
+
66
+ assert_equal false, s.empty?, 'not empty'
67
+ assert_equal true, s.empty?(:spr), 'empty :spr'
68
+ assert_equal false, s.empty?(:seq), 'not empty :seq'
69
+ s.unset_at 0
70
+ assert_equal true, s.empty?(:seq), 'empty :seq'
71
+ assert_equal false, s.empty?(:spr), 'not empty :spr'
72
+ s.unset_at 1
73
+ assert_equal true, s.empty?(:ary), 'empty :ary'
74
+ s.unset_at :key
75
+ assert_equal true, s.empty?, 'empty'
76
+ end
77
+
78
+ def test_first
79
+ s = Sarah[0, 1, 3 => 4, 5 => 6, :key => 'value']
80
+
81
+ assert_equal 0, s.first, 'first is 0'
82
+ assert_equal [0], s.first(1), 'first 1 is [0]'
83
+ assert_equal [0, 1], s.first(2), 'first 2 is [0, 1]'
84
+ assert_equal [0, 1, 4, 6], s.first(4), 'first 4'
85
+ assert_equal [0, 1, 4, 6], s.first(5), 'first 5'
86
+ end
87
+
88
+ def test_last
89
+ s = Sarah[0, 1, 3 => 4, 5 => 6, :key => 'value']
90
+
91
+ assert_equal 6, s.last, 'last is 6'
92
+ assert_equal [6], s.last(1), 'last 1 is [6]'
93
+ assert_equal [4, 6], s.last(2), 'last 2 is [4, 6]'
94
+ assert_equal [0, 1, 4, 6], s.last(4), 'last 4'
95
+ assert_equal [0, 1, 4, 6], s.last(5), 'last 5'
96
+ end
97
+
98
+ def test_replace
99
+ s1 = Sarah[1, 3 => 3, :v => 5]
100
+ s2 = Sarah[2, 4 => 4, :vi => 6]
101
+ s1.replace s2
102
+
103
+ assert_equal s2, s1, 's1.replace s2'
104
+ end
105
+
106
+ def test_reverse
107
+ s = Sarah[1, 2, 3, 4 => 4, 6 => 5, 8 => 6]
108
+ s.reverse!
109
+ assert_equal [6, 5, 4, 3, 2, 1], s.values, 'reverse'
110
+ end
111
+
112
+ def test_rotate
113
+ s = Sarah[1, 2, 3, 4, 5, 9 => 6]
114
+ s.rotate! 2
115
+ assert_equal [3, 4, 5, 6, 1, 2], s.values, 'rotate 2'
116
+ s.rotate! -4
117
+ assert_equal [5, 6, 1, 2, 3, 4], s.values, 'rotate -4'
118
+ end
119
+
120
+ def test_shuffle_sort
121
+ s = Sarah[1, 2, 3, 4, 5, 9 => 6]
122
+ 10.times do
123
+ s.shuffle!
124
+ break if s.values != [1, 2, 3, 4, 5, 6]
125
+ end
126
+
127
+ if s.values == [1, 2, 3, 4, 5, 6]
128
+ assert false, 'failed to shuffle in 10 tries!!'
129
+ else
130
+ assert_equal [1, 2, 3, 4, 5, 6], s.values.sort, 'shuffle'
131
+ end
132
+
133
+ assert_equal [1, 2, 3, 4, 5, 6], s.sort, 'sort'
134
+ s.sort!
135
+ assert_equal [1, 2, 3, 4, 5, 6], s.values, 'sort!'
136
+ end
137
+
138
+ def test_uniq
139
+ s = Sarah[3, 1, 4, 1, 5, 9, 2, 6, 5, 3]
140
+ assert_equal [3, 1, 4, 5, 9, 2, 6], s.uniq, 'uniq'
141
+ assert_equal [3, 1, 4, 1, 5, 9, 2, 6, 5, 3], s.values, 'unchanged'
142
+ s.uniq!
143
+ assert_equal [3, 1, 4, 5, 9, 2, 6], s.values, 'uniq!'
144
+ end
145
+
146
+ def test_zip
147
+ s = Sarah[3, 1, 4, 1, 5]
148
+ a = [9, 2, 6, 5, 3]
149
+ assert_equal [[3, 9], [1, 2], [4, 6], [1, 5], [5, 3]],
150
+ s.zip(a), 'zip'
151
+ end
152
+
153
+ end
154
+
155
+ # END
@@ -0,0 +1,55 @@
1
+ require 'minitest/autorun'
2
+ require 'sarah'
3
+
4
+ class TestSarah_14 < MiniTest::Unit::TestCase
5
+
6
+ def test_slice
7
+ s = Sarah[1, 2, 3, 4, 5, 10 => 6, 15 => 7, 20 => 8]
8
+
9
+ assert_equal 2, s.slice(1), 'slice 1'
10
+ assert_equal 6, s.slice(10), 'slice 10'
11
+ assert_equal({ 1 => 2 }, s.slice(1, 1).to_h, 'slice 1, 1')
12
+ assert_equal({ 1 => 2, 2 => 3 }, s.slice(1, 2).to_h, 'slice 1, 2')
13
+ assert_equal({ 4 => 5, 10 => 6 }, s.slice(4, 2).to_h, 'slice 4, 2')
14
+ assert_equal [5, 6, 7, 8], s.slice(4, 5).values, 'slice 4, 5'
15
+ assert_equal({ 15 => 7 }, s.slice(-6, 1).to_h, 'slice -6, 1')
16
+ assert_equal({ 20 => 8 }, s.slice(-3, 1).to_h, 'slice -3, 1')
17
+
18
+ assert_equal({ 4 => 5, 10 => 6, 15 => 7 }, s.slice(4..15).to_h,
19
+ 'slice 4..15')
20
+ assert_equal({ 4 => 5, 10 => 6 }, s.slice(4...15).to_h,
21
+ 'slice 4...15')
22
+ end
23
+
24
+ def test_slice_bang
25
+ s0 = Sarah[1, 2, 3, 4, 5, 10 => 6, 15 => 7, 20 => 8]
26
+
27
+ s = Sarah.new s0
28
+ assert_equal([3, 4], s.slice!(2, 2).values, 'slice! 2, 2')
29
+ assert_equal({ 0 => 1, 1 => 2, 2 => 5, 8 => 6, 13 => 7,
30
+ 18 => 8 }, s.to_h, 'after slice! 2, 2')
31
+
32
+ s = Sarah.new s0
33
+ s.slice! 4..10
34
+ assert_equal({ 0 => 1, 1 => 2, 2 => 3, 3 => 4, 13 => 7, 18 => 8},
35
+ s.to_h, 'after slice! 4..10')
36
+ end
37
+
38
+ def test_slice_nma
39
+ s0 = Sarah.new [1, 2, 3, 4, 5, 10 => 6, 15 => 7, 20 => 8],
40
+ :negative_mode => :actual
41
+
42
+ s = Sarah.new s0
43
+ s.slice!(2, 2)
44
+ assert_equal({ 0 => 1, 1 => 2, 4 => 5, 10 => 6, 15 => 7,
45
+ 20 => 8 }, s.to_h, 'after NMA slice! 2, 2')
46
+
47
+ s = Sarah.new s0
48
+ s.slice! 4..10
49
+ assert_equal({ 0 => 1, 1 => 2, 2 => 3, 3 => 4, 15 => 7, 20 => 8},
50
+ s.to_h, 'after NMA slice! 4..10')
51
+ end
52
+
53
+ end
54
+
55
+ # END
metadata CHANGED
@@ -3,10 +3,10 @@ name: sarah
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
+ - 2
6
7
  - 0
7
8
  - 0
8
- - 4
9
- version: 0.0.4
9
+ version: 2.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brian Katzung
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2013-07-28 00:00:00 -05:00
17
+ date: 2014-03-31 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -29,14 +29,37 @@ extra_rdoc_files: []
29
29
 
30
30
  files:
31
31
  - lib/sarah.rb
32
+ - lib/doc/js/full_list.js
33
+ - lib/doc/js/app.js
34
+ - lib/doc/js/jquery.js
35
+ - lib/doc/file_list.html
36
+ - lib/doc/css/full_list.css
37
+ - lib/doc/css/style.css
38
+ - lib/doc/css/common.css
39
+ - lib/doc/class_list.html
40
+ - lib/doc/_index.html
41
+ - lib/doc/top-level-namespace.html
42
+ - lib/doc/method_list.html
43
+ - lib/doc/index.html
44
+ - lib/doc/frames.html
32
45
  - sarah.gemspec
33
46
  - HISTORY.txt
34
47
  - .yardopts
48
+ - test/09delete_unset.rb
35
49
  - test/02new.rb
36
50
  - test/00class.rb
51
+ - test/08set_ops.rb
52
+ - test/10count_size.rb
53
+ - test/13misc.rb
54
+ - test/05class2.rb
55
+ - test/06instance2.rb
37
56
  - test/04stack.rb
57
+ - test/14slice.rb
38
58
  - test/01instance.rb
59
+ - test/12search.rb
60
+ - test/07inst_attr.rb
39
61
  - test/03set_get.rb
62
+ - test/11each.rb
40
63
  has_rdoc: true
41
64
  homepage: http://rubygems.org/gems/sarah
42
65
  licenses:
@@ -70,8 +93,18 @@ signing_key:
70
93
  specification_version: 3
71
94
  summary: Sequential array/random-access hash
72
95
  test_files:
96
+ - test/09delete_unset.rb
73
97
  - test/02new.rb
74
98
  - test/00class.rb
99
+ - test/08set_ops.rb
100
+ - test/10count_size.rb
101
+ - test/13misc.rb
102
+ - test/05class2.rb
103
+ - test/06instance2.rb
75
104
  - test/04stack.rb
105
+ - test/14slice.rb
76
106
  - test/01instance.rb
107
+ - test/12search.rb
108
+ - test/07inst_attr.rb
77
109
  - test/03set_get.rb
110
+ - test/11each.rb