flex_array 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,30 +3,57 @@ require 'minitest/autorun'
3
3
 
4
4
  class FlexArrayTransposeTester < MiniTest::Unit::TestCase
5
5
  $do_this_only_one_time = "" unless defined? $do_this_only_one_time
6
-
6
+
7
7
  def initialize(*all)
8
8
  if $do_this_only_one_time != __FILE__
9
9
  puts
10
- puts "Running test file: #{File.split(__FILE__)[1]}"
10
+ puts "Running test file: #{File.split(__FILE__)[1]}"
11
11
  $do_this_only_one_time = __FILE__
12
12
  end
13
-
13
+
14
14
  super(*all)
15
15
  end
16
16
 
17
- def test_the_transpose_method
17
+ def test_the_transpose_em_method
18
18
  f = FlexArray.new([3,3]) { |i| i[0]*3 + i[1] }
19
19
  a = [0,1,2,
20
20
  3,4,5,
21
21
  6,7,8]
22
22
  assert_equal(a, f[:all, :all])
23
23
  assert_equal(a, f[:all])
24
-
25
- f.transpose(0,1)
24
+
25
+ f.transpose!(0,1)
26
26
  a = [0,3,6,
27
27
  1,4,7,
28
28
  2,5,8]
29
29
  assert_equal(a, f[:all, :all])
30
30
  assert_equal(a, f[:all])
31
31
  end
32
+
33
+ def test_that_transpose_em_rejects_bad_args
34
+ f = FlexArray.new([3,3]) { |i| i[0]*3 + i[1] }
35
+
36
+ assert_raises(ArgumentError) { f.transpose!(0,2) }
37
+ assert_raises(ArgumentError) { f.transpose!(-1,0) }
38
+ end
39
+
40
+ def test_the_transpose_method
41
+ f = FlexArray.new([3,3]) { |i| i[0]*3 + i[1] }
42
+ a = [0,1,2,
43
+ 3,4,5,
44
+ 6,7,8]
45
+ assert_equal(a, f[:all, :all])
46
+ assert_equal(a, f[:all])
47
+
48
+ g = f.transpose(0,1)
49
+ b = [0,3,6,
50
+ 1,4,7,
51
+ 2,5,8]
52
+
53
+ assert_equal(a, f[:all, :all])
54
+ assert_equal(a, f[:all])
55
+
56
+ assert_equal(b, g[:all, :all])
57
+ assert_equal(b, g[:all])
58
+ end
32
59
  end
@@ -1,4 +1,4 @@
1
- require_relative '../lib/flex_array/integer'
1
+ require_relative '../lib/flex_array'
2
2
  require 'minitest/autorun'
3
3
 
4
4
  class IntegerTester < MiniTest::Unit::TestCase
data/tests/object_test.rb CHANGED
@@ -1,23 +1,23 @@
1
- require_relative '../lib/flex_array/object'
1
+ require_relative '../lib/flex_array'
2
2
  require 'minitest/autorun'
3
3
 
4
4
  class ObjectTester < MiniTest::Unit::TestCase
5
5
  $do_this_only_one_time = "" unless defined? $do_this_only_one_time
6
-
6
+
7
7
  def initialize(*all)
8
8
  if $do_this_only_one_time != __FILE__
9
9
  puts
10
- puts "Running test file: #{File.split(__FILE__)[1]}"
10
+ puts "Running test file: #{File.split(__FILE__)[1]}"
11
11
  $do_this_only_one_time = __FILE__
12
12
  end
13
-
13
+
14
14
  super(*all)
15
15
  end
16
-
16
+
17
17
  def test_that_to_spec_component_fails
18
18
  obj = Object.new
19
19
  assert_raises(ArgumentError) { obj.to_spec_component(42) }
20
-
20
+
21
21
  #Test other invalid objects as well...
22
22
  assert_raises(ArgumentError) { (89.0).to_spec_component(42) }
23
23
  assert_raises(ArgumentError) { 'Hello'.to_spec_component(42) }
@@ -34,5 +34,5 @@ class ObjectTester < MiniTest::Unit::TestCase
34
34
  assert_raises(IndexError) { ('all').to_index_range(lc) }
35
35
  assert_raises(IndexError) { (98.9).to_index_range(lc) }
36
36
  end
37
-
37
+
38
38
  end
data/tests/range_test.rb CHANGED
@@ -1,16 +1,16 @@
1
- require_relative '../lib/flex_array/range'
1
+ require_relative '../lib/flex_array'
2
2
  require 'minitest/autorun'
3
3
 
4
4
  class RangeTester < MiniTest::Unit::TestCase
5
5
  $do_this_only_one_time = "" unless defined? $do_this_only_one_time
6
-
6
+
7
7
  def initialize(*all)
8
8
  if $do_this_only_one_time != __FILE__
9
9
  puts
10
- puts "Running test file: #{File.split(__FILE__)[1]}"
10
+ puts "Running test file: #{File.split(__FILE__)[1]}"
11
11
  $do_this_only_one_time = __FILE__
12
12
  end
13
-
13
+
14
14
  super(*all)
15
15
  end
16
16
 
@@ -18,7 +18,7 @@ class RangeTester < MiniTest::Unit::TestCase
18
18
  lc = (0...10).to_spec_component(3)
19
19
  assert_equal(0...10, lc.range)
20
20
  assert_equal(3, lc.stride)
21
-
21
+
22
22
  lc = (0...0).to_spec_component(3)
23
23
  assert_equal(0...0, lc.range)
24
24
  assert_equal(3, lc.stride)
@@ -28,12 +28,13 @@ class RangeTester < MiniTest::Unit::TestCase
28
28
  assert_raises(ArgumentError) { (8...0).to_spec_component(3) }
29
29
  assert_raises(ArgumentError) { ('a'..'b').to_spec_component(3) }
30
30
  end
31
-
31
+
32
32
  def test_the_to_index_range_method
33
33
  lc = SpecComponent.new(0...10, 1)
34
- assert_equal(1...3, (1...3).to_index_range(lc))
34
+ assert_equal(1..2, (1...3).to_index_range(lc))
35
35
  assert_equal(8..9, (-2..-1).to_index_range(lc))
36
-
36
+ assert_equal(2..8, (2..-2).to_index_range(lc))
37
+
37
38
  assert_raises(IndexError) { (1...11).to_index_range(lc) }
38
39
  assert_raises(IndexError) { (1..10).to_index_range(lc) }
39
40
  assert_raises(IndexError) { (-2..2).to_index_range(lc) }
@@ -0,0 +1,26 @@
1
+ require_relative '../lib/flex_array'
2
+ require 'minitest/autorun'
3
+
4
+ class SpecArrayTester < MiniTest::Unit::TestCase
5
+ $do_this_only_one_time = "" unless defined? $do_this_only_one_time
6
+
7
+ def initialize(*all)
8
+ if $do_this_only_one_time != __FILE__
9
+ puts
10
+ puts "Running test file: #{File.split(__FILE__)[1]}"
11
+ $do_this_only_one_time = __FILE__
12
+ end
13
+
14
+ super(*all)
15
+ end
16
+
17
+ def test_that_it_builds_specs
18
+ spec = SpecArray.new([0...10, 0...8])
19
+ assert(2, spec.spec_dimensions)
20
+ assert(0...10, spec[0].range)
21
+ assert(8, spec[0].stride)
22
+ assert(0...8, spec[1].range)
23
+ assert(1, spec[1].stride)
24
+ assert(80, spec.spec_count)
25
+ end
26
+ end
@@ -1,19 +1,19 @@
1
- require_relative '../lib/flex_array/spec_component'
1
+ require_relative '../lib/flex_array'
2
2
  require 'minitest/autorun'
3
3
 
4
4
  class SpecComponentTester < MiniTest::Unit::TestCase
5
5
  $do_this_only_one_time = "" unless defined? $do_this_only_one_time
6
-
6
+
7
7
  def initialize(*all)
8
8
  if $do_this_only_one_time != __FILE__
9
9
  puts
10
- puts "Running test file: #{File.split(__FILE__)[1]}"
10
+ puts "Running test file: #{File.split(__FILE__)[1]}"
11
11
  $do_this_only_one_time = __FILE__
12
12
  end
13
-
13
+
14
14
  super(*all)
15
15
  end
16
-
16
+
17
17
  def setup
18
18
  @lc = SpecComponent.new(1..5, 10)
19
19
  end
@@ -21,7 +21,7 @@ class SpecComponentTester < MiniTest::Unit::TestCase
21
21
  def test_the_range
22
22
  assert_equal(1..5, @lc.range)
23
23
  end
24
-
24
+
25
25
  def test_the_stride
26
26
  assert_equal(10, @lc.stride)
27
27
  end
@@ -29,24 +29,24 @@ class SpecComponentTester < MiniTest::Unit::TestCase
29
29
  def test_the_equality_operator
30
30
  a = SpecComponent.new(1..5, 1)
31
31
  b = SpecComponent.new(1..6, 10)
32
-
32
+
33
33
  assert(@lc == a)
34
34
  refute(@lc == b)
35
35
  refute(a == b)
36
-
36
+
37
37
  #Make sure our == operator plays well with arrays.
38
38
  assert([@lc] == [a])
39
39
  refute([@lc] == [b])
40
40
  refute([a] == [b])
41
41
  end
42
-
42
+
43
43
  def test_the_threequal_operator
44
44
  refute(@lc === 0)
45
45
  assert(@lc === 1)
46
46
  assert(@lc === 5)
47
47
  refute(@lc === 6)
48
48
  end
49
-
49
+
50
50
  def test_out_min
51
51
  assert_equal(1, @lc.min)
52
52
  end
@@ -57,7 +57,7 @@ class SpecComponentTester < MiniTest::Unit::TestCase
57
57
 
58
58
  def test_out_span
59
59
  assert_equal(5, @lc.span)
60
-
60
+
61
61
  @lc = SpecComponent.new(0...0, 10)
62
62
  assert_equal(0, @lc.span)
63
63
  end
@@ -66,23 +66,26 @@ class SpecComponentTester < MiniTest::Unit::TestCase
66
66
  i = (1..5).each
67
67
  @lc.each {|v| assert_equal(i.next, v)}
68
68
  end
69
-
69
+
70
70
  def test_out_index_step
71
71
  assert_equal(0, @lc.index_step(1))
72
72
  assert_equal(40, @lc.index_step(5))
73
-
73
+
74
74
  @lc = SpecComponent.new(0...0, 10)
75
75
  assert_raises(TypeError) { @lc.index_step(1) }
76
76
  end
77
-
77
+
78
78
  def test_the_enlarge_method
79
79
  assert_equal(5, @lc.span)
80
80
  @lc.enlarge(5)
81
81
  assert_equal(10, @lc.span)
82
-
82
+
83
83
  @lc = SpecComponent.new(0...0, 10)
84
84
  assert_equal(0, @lc.span)
85
+ assert(@lc.range.none?)
85
86
  @lc.enlarge(5)
87
+ assert_equal(0...5, @lc.range)
86
88
  assert_equal(5, @lc.span)
89
+ refute(@lc.range.none?)
87
90
  end
88
- end
91
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flex_array
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Camilleri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-23 00:00:00.000000000 Z
11
+ date: 2014-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -77,6 +77,7 @@ files:
77
77
  - lib/flex_array/array.rb
78
78
  - lib/flex_array/flex_array_append.rb
79
79
  - lib/flex_array/flex_array_each.rb
80
+ - lib/flex_array/flex_array_forever.rb
80
81
  - lib/flex_array/flex_array_index.rb
81
82
  - lib/flex_array/flex_array_new.rb
82
83
  - lib/flex_array/flex_array_process.rb
@@ -86,6 +87,7 @@ files:
86
87
  - lib/flex_array/integer.rb
87
88
  - lib/flex_array/object.rb
88
89
  - lib/flex_array/range.rb
90
+ - lib/flex_array/spec_array.rb
89
91
  - lib/flex_array/spec_component.rb
90
92
  - tests/array_test.rb
91
93
  - tests/flex_array_append_test.rb
@@ -99,6 +101,7 @@ files:
99
101
  - tests/integer_test.rb
100
102
  - tests/object_test.rb
101
103
  - tests/range_test.rb
104
+ - tests/spec_array_test.rb
102
105
  - tests/spec_component_test.rb
103
106
  - rakefile.rb
104
107
  - license.txt
@@ -141,4 +144,5 @@ test_files:
141
144
  - tests/integer_test.rb
142
145
  - tests/object_test.rb
143
146
  - tests/range_test.rb
147
+ - tests/spec_array_test.rb
144
148
  - tests/spec_component_test.rb