spreet 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,24 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
+ require "digest/sha2"
3
4
 
4
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
5
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
7
  require 'spreet'
7
8
 
8
9
  class Test::Unit::TestCase
10
+
11
+ def assert_checksums(expected, actual, message=nil)
12
+ checksums = []
13
+ assert File.exist?(expected)
14
+ File.open(expected, "rb") do |f|
15
+ checksums << Digest::SHA256.hexdigest(f.read)
16
+ end
17
+ assert File.exist?(actual)
18
+ File.open(actual, "rb") do |f|
19
+ checksums << Digest::SHA256.hexdigest(f.read)
20
+ end
21
+ assert_equal checksums[0], checksums[1], message
22
+ end
23
+
9
24
  end
Binary file
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ require 'helper'
3
+
4
+ class TestBigArray < Test::Unit::TestCase
5
+
6
+ def test_big_hash
7
+ assert_nothing_raised do
8
+ BigArray.new("MyBigArray", 2, 8)
9
+ end
10
+ array = nil
11
+ assert_nothing_raised do
12
+ array = BigArray::MyBigArray.new
13
+ end
14
+ assert_nothing_raised do
15
+ array[0] = 123
16
+ end
17
+ assert_equal(123, array[0])
18
+ assert_nothing_raised do
19
+ array[2**32 - 1] = "Test"
20
+ end
21
+ assert_equal("Test", array[2**32 - 1])
22
+ end
23
+
24
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ require 'helper'
3
+
4
+ class TestCoordinates < Test::Unit::TestCase
5
+
6
+ def test_importations
7
+ assert_equal Spreet::Coordinates.new(0,0), Spreet::Coordinates.new("A1")
8
+ assert_equal Spreet::Coordinates.new(0,0), Spreet::Coordinates.new("0-0")
9
+ assert_equal Spreet::Coordinates.new(1,1), Spreet::Coordinates.new("B2")
10
+ assert_equal Spreet::Coordinates.new(2,2), Spreet::Coordinates.new(:x=>2, :y=>2)
11
+ assert_equal Spreet::Coordinates.new(3,3), Spreet::Coordinates.new(3,3)
12
+ assert_equal Spreet::Coordinates.new(3,3), Spreet::Coordinates.new([3,3])
13
+ assert_equal Spreet::Coordinates.new(4,4), Spreet::Coordinates.new(Spreet::Coordinates.new(4,4).to_i)
14
+ assert_equal Spreet::Coordinates.new(5,5), Spreet::Coordinates.new(Spreet::Coordinates.new(5,5))
15
+ end
16
+
17
+ def test_exportations
18
+ assert_equal("D25", Spreet::Coordinates.new(3,24).to_s)
19
+ assert_equal([3, 24], Spreet::Coordinates.new(3,24).to_a)
20
+ assert_equal({:x=>3, :y=>24}, Spreet::Coordinates.new(3,24).to_hash)
21
+ assert_equal(24, Spreet::Coordinates.new(0,24).to_i)
22
+ assert_equal((3 << Spreet::Coordinates::X_BIT_SHIFT)+24, Spreet::Coordinates.new(3,24).to_i)
23
+ end
24
+
25
+ def test_sorting
26
+ assert Spreet::Coordinates.new(0,0) <=> Spreet::Coordinates.new(0,1)
27
+ assert Spreet::Coordinates.new(0,1) <=> Spreet::Coordinates.new(1,0)
28
+ assert Spreet::Coordinates.new(1,0) <=> Spreet::Coordinates.new(1,1)
29
+ end
30
+
31
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+ require 'helper'
3
+
4
+ class TestCSV < Test::Unit::TestCase
5
+
6
+ def test_read_and_write
7
+ doc = nil
8
+ assert_nothing_raised do
9
+ doc = Spreet::Document.read("test/samples/pascal.csv")
10
+ end
11
+
12
+ sheet = doc.sheets[0]
13
+ sheet.each_row do |row|
14
+ for cell in row
15
+ if cell.text.to_i == 0
16
+ cell.clear!
17
+ end
18
+ end
19
+ end
20
+
21
+ doc.write("test/samples/cleaned-pascal.csv")
22
+
23
+ doc.write("test/samples/cleaned-pascal.xcsv")
24
+ doc.write("test/samples/cleaned-pascal-excel.csv", :format=>:xcsv)
25
+
26
+ assert_checksums "test/samples/cleaned-pascal.xcsv", "test/samples/cleaned-pascal-excel.csv"
27
+
28
+ assert_nothing_raised do
29
+ doc = Spreet::Document.read("test/samples/cleaned-pascal.csv")
30
+ end
31
+
32
+ assert_nothing_raised do
33
+ doc = Spreet::Document.read("test/samples/cleaned-pascal.xcsv")
34
+ end
35
+
36
+ FileUtils.rm_f("test/samples/cleaned-pascal*")
37
+ end
38
+
39
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ require 'helper'
3
+
4
+ class TestDuration < Test::Unit::TestCase
5
+
6
+ # Test syntax like defined for xsd:duration
7
+ def test_importations
8
+ # Valid values include PT1004199059S, PT130S, PT2M10S, P1DT2S, -P1Y, or P1Y2M3DT5H20M30.123S.
9
+ for value in ["PT1004199059S", "PT130S", "PT2M10S", "P1DT2S", "-P1Y", "P1Y2M3DT5H20M30.123S"]
10
+ duration = nil
11
+ assert_nothing_raised do
12
+ duration = Duration.new(value)
13
+ end
14
+ assert_equal value, duration.to_s(:maximum)
15
+ end
16
+
17
+ # The following values are invalid: 1Y (leading P is missing), P1S (T separator is missing), P-1Y (all parts must be positive), P1M2Y (parts order is significant and Y must precede M), or P1Y-1M (all parts must be positive).
18
+ for value in ["1Y", "P1S", "P-1Y", "P1M2Y", "P1Y-1M"]
19
+ assert_raise(ArgumentError) do
20
+ Duration.new(value)
21
+ end
22
+ end
23
+
24
+ duration = Duration.new("P5Y250M1D")
25
+ assert_not_nil duration
26
+ end
27
+
28
+ def test_normalization
29
+ duration = Duration.new("PT1004199059S")
30
+ assert_equal duration.to_i, duration.normalize(:right).to_i
31
+ assert_equal duration.to_i, duration.normalize(:seconds).to_i
32
+ end
33
+
34
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ require 'helper'
3
+
4
+ class TestOpenDocument < Test::Unit::TestCase
5
+
6
+ def test_read_and_write
7
+ doc = nil
8
+ assert_nothing_raised do
9
+ doc = Spreet::Document.read("test/samples/pascal.ods")
10
+ end
11
+
12
+ assert_nothing_raised do
13
+ doc.write("test/samples/rewrited-pascal.ods")
14
+ end
15
+ end
16
+
17
+ end
@@ -1,25 +1,10 @@
1
1
  # encoding: utf-8
2
2
  require 'helper'
3
+ require "digest/sha2"
3
4
 
4
5
  class TestSpreet < Test::Unit::TestCase
5
6
 
6
- def test_coordinates
7
- assert_equal Spreet::Coordinates.new(0,0), Spreet::Coordinates.new("A1")
8
- assert_equal Spreet::Coordinates.new(0,0), Spreet::Coordinates.new("0-0")
9
- assert_equal Spreet::Coordinates.new(1,1), Spreet::Coordinates.new("B2")
10
- assert_equal Spreet::Coordinates.new(2,2), Spreet::Coordinates.new(:x=>2, :y=>2)
11
- assert_equal Spreet::Coordinates.new(3,3), Spreet::Coordinates.new(3,3)
12
- assert_equal Spreet::Coordinates.new(3,3), Spreet::Coordinates.new([3,3])
13
- assert_equal Spreet::Coordinates.new(4,4), Spreet::Coordinates.new(Spreet::Coordinates.new(4,4).to_i)
14
- assert_equal Spreet::Coordinates.new(5,5), Spreet::Coordinates.new(Spreet::Coordinates.new(5,5))
15
- assert_equal("D25", Spreet::Coordinates.new(3,24).to_s)
16
- assert_equal([3, 24], Spreet::Coordinates.new(3,24).to_a)
17
- assert_equal({:x=>3, :y=>24}, Spreet::Coordinates.new(3,24).to_hash)
18
- assert Spreet::Coordinates.new(0,0) <=> Spreet::Coordinates.new(0,1)
19
- assert Spreet::Coordinates.new(0,1) <=> Spreet::Coordinates.new(1,0)
20
- end
21
-
22
- def test_spreet_version
7
+ def test_version
23
8
  assert_not_nil Spreet::VERSION
24
9
  assert_not_nil Spreet::VERSION::MAJOR
25
10
  assert_not_nil Spreet::VERSION::MINOR
@@ -34,10 +19,35 @@ class TestSpreet < Test::Unit::TestCase
34
19
 
35
20
  spreet = Spreet::Document.new
36
21
  assert_not_nil spreet
22
+ assert_equal 0, spreet.sheets.count
37
23
  sheet = spreet.sheets.add
38
24
  assert_not_nil sheet
25
+ assert_equal 1, spreet.sheets.count
39
26
  assert_not_nil spreet.sheets.add("Feuille 2")
27
+ assert_equal 2, spreet.sheets.count
40
28
  assert_not_nil spreet.sheets.add("ソフト 3")
29
+ assert_equal 3, spreet.sheets.count
30
+ assert_not_nil spreet.sheets.add("Feuille 4")
31
+ assert_equal 4, spreet.sheets.count
32
+ spreet.sheets.remove("Feuille 2")
33
+ assert_equal 3, spreet.sheets.count
34
+ assert_equal "Sheet 1", spreet.sheets[0].name
35
+ assert_equal "ソフト 3", spreet.sheets[1].name
36
+ assert_equal "Feuille 4", spreet.sheets[2].name
37
+ spreet.sheets[2].name = "Feuille 2"
38
+ spreet.sheets.move("Feuille 2", -1)
39
+ assert_equal 1, spreet.sheets.index("Feuille 2")
40
+ spreet.sheets.move("Feuille 2", -10)
41
+ assert_equal 0, spreet.sheets.index("Feuille 2")
42
+ spreet.sheets.move("Feuille 2", +10)
43
+ assert_equal 2, spreet.sheets.index("Feuille 2")
44
+ spreet.sheets.move_at("Feuille 2", 1)
45
+ assert_equal 1, spreet.sheets.index("Feuille 2")
46
+ assert_equal "Sheet 1", spreet.sheets[0].name
47
+ assert_equal "Feuille 2", spreet.sheets[1].name
48
+ assert_equal "ソフト 3", spreet.sheets[2].name
49
+ spreet.sheets.add "Empty sheet"
50
+ assert_equal 4, spreet.sheets.count
41
51
 
42
52
  assert_equal Spreet::Sheet, spreet.sheets[1].class
43
53
  assert_equal "Feuille 2", spreet.sheets[1].name
@@ -53,38 +63,50 @@ class TestSpreet < Test::Unit::TestCase
53
63
  assert_not_nil sheet["C30"]
54
64
 
55
65
  sheet["F20"] = Date.today
66
+ sheet["F20"].annotation = "Date.today"
56
67
 
57
68
  spreet.write("test/samples/cleaned-nothing.ods")
69
+
70
+ spreet2 = Spreet::Document.read("test/samples/cleaned-nothing.ods")
71
+
72
+ spreet2.write("test/samples/cleaned-nothing2.ods")
73
+
74
+ # Assert equality of file size ?
75
+ assert_checksums "test/samples/cleaned-nothing.ods", "test/samples/cleaned-nothing2.ods", "SHA256 sums differs between the copy and the original. Check if the reader is a good 'mirror' of the writer..."
58
76
  end
77
+
59
78
 
79
+ def test_pascal
80
+ size = 50
81
+ doc = Spreet::Document.new
82
+ sheet = doc.sheets.add("Pascal Tree")
83
+ sheet[0,0] = 1
84
+ start = Time.now
85
+ for y in 1..(size-1)
86
+ sheet[0,y] = 1
87
+ for x in 1..(size-1)
88
+ sheet[x,y] = sheet[x,y-1].value.to_i + sheet[x-1,y-1].value.to_i
89
+ sheet[x,y].clear! if sheet[x,y].value.zero?
90
+ end
91
+ end
92
+ stop = Time.now
93
+ sheet["B1"] = "Computed in #{stop-start} seconds"
94
+
95
+ assert_equal size-1, sheet.bound.x
96
+ assert_equal size-1, sheet.bound.y
60
97
 
61
- def test_handlers
62
- doc = nil
63
98
  assert_nothing_raised do
64
- doc = Spreet::Document.read("test/samples/pascal.csv")
99
+ doc.write("test/samples/pascal-tree-#{size}.ods")
65
100
  end
66
-
67
- sheet = doc.sheets[0]
68
- sheet.each_row do |row|
69
- for cell in row
70
- if cell.text.to_i == 0
71
- cell.clear!
72
- end
73
- end
101
+ assert_nothing_raised do
102
+ doc.write("test/samples/pascal-tree-#{size}.csv")
74
103
  end
75
-
76
- doc.write("test/samples/cleaned-pascal.csv", :format=>:xcsv)
77
- doc.write("test/samples/cleaned-pascal.ods")
78
-
79
104
  assert_nothing_raised do
80
- doc = Spreet::Document.read("test/samples/cleaned-pascal.csv", :format=>:xcsv)
105
+ doc.write("test/samples/pascal-tree-#{size}.xcsv")
81
106
  end
82
-
83
- FileUtils.rm_f("test/samples/cleaned-pascal.csv")
84
107
  end
85
108
 
86
109
 
87
-
88
110
 
89
111
  end
90
112
 
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: !binary |-
5
+ MC4wLjM=
5
6
  prerelease:
6
7
  platform: ruby
7
8
  authors:
@@ -9,11 +10,11 @@ authors:
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2011-11-02 00:00:00.000000000Z
13
+ date: 2012-09-05 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: fastercsv
16
- requirement: &11047920 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
20
  - - ! '>='
@@ -21,10 +22,15 @@ dependencies:
21
22
  version: '0'
22
23
  type: :runtime
23
24
  prerelease: false
24
- version_requirements: *11047920
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
25
31
  - !ruby/object:Gem::Dependency
26
32
  name: libxml-ruby
27
- requirement: &11047140 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
28
34
  none: false
29
35
  requirements:
30
36
  - - ! '>='
@@ -32,18 +38,44 @@ dependencies:
32
38
  version: '0'
33
39
  type: :runtime
34
40
  prerelease: false
35
- version_requirements: *11047140
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: rubyzip
38
- requirement: &11046580 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.4
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
39
58
  none: false
40
59
  requirements:
41
60
  - - ! '>='
42
61
  - !ruby/object:Gem::Version
43
62
  version: 0.9.4
63
+ - !ruby/object:Gem::Dependency
64
+ name: money
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: 4.0.0
44
71
  type: :runtime
45
72
  prerelease: false
46
- version_requirements: *11046580
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 4.0.0
47
79
  description: Spr[eadsh]eet handler for CSV(RW), Excel CSV(RW) and ODS(W). The goal
48
80
  is to read and write in many open formats.
49
81
  email: brice.texier@ekylibre.org
@@ -56,12 +88,22 @@ files:
56
88
  - MIT-LICENSE
57
89
  - README.rdoc
58
90
  - VERSION
91
+ - lib/big_array.rb
92
+ - lib/duration.rb
59
93
  - lib/spreet.rb
94
+ - lib/spreet/coordinates.rb
60
95
  - lib/spreet/handlers.rb
61
96
  - lib/spreet/handlers/csv.rb
62
97
  - lib/spreet/handlers/open_document.rb
98
+ - lib/time.rb
63
99
  - test/helper.rb
64
100
  - test/samples/pascal.csv
101
+ - test/samples/pascal.ods
102
+ - test/test_big_array.rb
103
+ - test/test_coordinates.rb
104
+ - test/test_csv.rb
105
+ - test/test_duration.rb
106
+ - test/test_open_document.rb
65
107
  - test/test_spreet.rb
66
108
  homepage: http://github.com/burisu/spreet
67
109
  licenses:
@@ -84,9 +126,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
126
  version: '0'
85
127
  requirements: []
86
128
  rubyforge_project:
87
- rubygems_version: 1.8.11
129
+ rubygems_version: 1.8.23
88
130
  signing_key:
89
131
  specification_version: 3
90
132
  summary: Spr[eadsh]eet handler
91
133
  test_files:
134
+ - test/test_big_array.rb
135
+ - test/test_coordinates.rb
136
+ - test/test_csv.rb
137
+ - test/test_duration.rb
138
+ - test/test_open_document.rb
92
139
  - test/test_spreet.rb