bioinform 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bioinform/data_models/pcm.rb +12 -0
- data/lib/bioinform/data_models/pm.rb +38 -54
- data/lib/bioinform/data_models/pwm.rb +7 -7
- data/lib/bioinform/data_models.rb +2 -0
- data/lib/bioinform/parsers/parser.rb +40 -0
- data/lib/bioinform/{data_models/parsers → parsers}/string_fantom_parser.rb +1 -2
- data/lib/bioinform/{data_models/parsers → parsers}/string_parser.rb +7 -7
- data/lib/bioinform/parsers.rb +3 -0
- data/lib/bioinform/support/partial_sums.rb +2 -0
- data/lib/bioinform/version.rb +1 -1
- data/lib/bioinform.rb +0 -1
- data/spec/data_models/pcm_spec.rb +27 -0
- data/spec/data_models/pm_spec.rb +62 -144
- data/spec/data_models/pwm_spec.rb +3 -7
- data/spec/parsers/parser_spec.rb +58 -0
- data/spec/parsers/string_fantom_parser_spec.rb +28 -0
- data/spec/parsers/string_parser_spec.rb +46 -0
- data/spec/spec_helper.rb +13 -21
- data/spec/support/multiline_squish_spec.rb +12 -4
- data/spec/support/partial_sums_spec.rb +3 -0
- metadata +14 -18
- data/lib/bioinform/data_models/parser.rb +0 -38
- data/lib/bioinform/data_models/parsers/array_parser.rb +0 -17
- data/lib/bioinform/data_models/parsers/hash_parser.rb +0 -19
- data/lib/bioinform/data_models/parsers.rb +0 -6
- data/spec/data_models/parser_spec.rb +0 -46
- data/spec/data_models/parsers/array_parser_spec.rb +0 -53
- data/spec/data_models/parsers/hash_parser_spec.rb +0 -60
- data/spec/data_models/parsers/string_fantom_parser_spec.rb +0 -38
- data/spec/data_models/parsers/string_parser_spec.rb +0 -156
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'bioinform/support'
|
2
|
-
require 'bioinform/data_models/pm'
|
3
|
-
|
4
|
-
module Bioinform
|
5
|
-
class Parser
|
6
|
-
attr_reader :input
|
7
|
-
|
8
|
-
@subclasses ||= []
|
9
|
-
class << self
|
10
|
-
def subclasses
|
11
|
-
@subclasses
|
12
|
-
end
|
13
|
-
def inherited(subclass)
|
14
|
-
Parser.subclasses << subclass
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(input)
|
19
|
-
@input = input
|
20
|
-
end
|
21
|
-
|
22
|
-
def parse_core
|
23
|
-
raise NotImplemented
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
def parse
|
28
|
-
parse_core
|
29
|
-
end
|
30
|
-
|
31
|
-
def can_parse?
|
32
|
-
parse_core
|
33
|
-
true
|
34
|
-
rescue
|
35
|
-
false
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'bioinform/support'
|
2
|
-
require 'bioinform/data_models/parser'
|
3
|
-
|
4
|
-
module Bioinform
|
5
|
-
class ArrayParser < Parser
|
6
|
-
def parse_core
|
7
|
-
raise ArgumentError unless input.is_a?(Array) && input.all?(&:is_a?.(Array)) && input.same_by?(&:length) && (input.size == 4 || input.sample.size == 4)
|
8
|
-
if input.all?{|line| line.size == 4}
|
9
|
-
{matrix: input}
|
10
|
-
elsif input.size == 4
|
11
|
-
{matrix: input.transpose}
|
12
|
-
else
|
13
|
-
raise ArgumentError
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'bioinform/support'
|
2
|
-
require 'bioinform/data_models/parser'
|
3
|
-
|
4
|
-
module Bioinform
|
5
|
-
class HashParser < Parser
|
6
|
-
def parse_core
|
7
|
-
case input
|
8
|
-
when Hash
|
9
|
-
raise ArgumentError unless input.with_indifferent_access.has_all_keys?(:A, :C, :G, :T) && input.with_indifferent_access.values_at(:A,:C,:G,:T).same_by?(&:length)
|
10
|
-
{ matrix: input.with_indifferent_access.values_at(:A,:C,:G,:T).transpose }
|
11
|
-
when Array
|
12
|
-
raise ArgumentError unless input.all?(&:is_a?.(Hash)) && input.all?{|position| position.size == 4}
|
13
|
-
{ matrix: input.map(&:with_indifferent_access).map(&:values_at.(:A,:C,:G,:T)) }
|
14
|
-
else
|
15
|
-
raise ArgumentError
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,6 +0,0 @@
|
|
1
|
-
# Parsers should be included after PM class defined - in order it could catch definitions of new classes
|
2
|
-
|
3
|
-
require 'bioinform/data_models/parsers/array_parser'
|
4
|
-
require 'bioinform/data_models/parsers/hash_parser'
|
5
|
-
require 'bioinform/data_models/parsers/string_parser'
|
6
|
-
require 'bioinform/data_models/parsers/string_fantom_parser'
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'bioinform/data_models/parser'
|
3
|
-
|
4
|
-
module Bioinform
|
5
|
-
describe Parser do
|
6
|
-
include Parser::Helpers
|
7
|
-
|
8
|
-
before :each do
|
9
|
-
parser_stub :ParserBad, false, { matrix: [[0,0,0,0],[1,1,1,1]], name: 'Bad' }
|
10
|
-
parser_stub :ParserGood, true, { matrix: [[1,1,1,1],[1,1,1,1]], name: 'Good' }
|
11
|
-
end
|
12
|
-
after :each do
|
13
|
-
parser_subclasses_cleanup
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'when subklass created' do
|
17
|
-
it 'Parser.subclasses should contain all subclasses' do
|
18
|
-
Parser.subclasses.should include ParserBad
|
19
|
-
Parser.subclasses.should include ParserGood
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe '#initialize' do
|
24
|
-
it 'should save argument `input`'do
|
25
|
-
parser = ParserGood.new('my stub input')
|
26
|
-
parser.input.should == 'my stub input'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '#parse' do
|
31
|
-
it 'should raise an error unless reimplemented' do
|
32
|
-
parser = Parser.new('my stub input')
|
33
|
-
expect{ parser.parse }.to raise_error
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'in a subclass' do
|
37
|
-
it '!!! USELESS TEST - see TODO and make LINT for subclasses!!! should return hash with key `matrix`' do
|
38
|
-
parser = ParserGood.new('my stub input')
|
39
|
-
parse_result = parser.parse
|
40
|
-
parse_result.should be_kind_of Hash
|
41
|
-
parse_result.should have_key :matrix
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'bioinform/data_models/parsers/array_parser'
|
3
|
-
|
4
|
-
module Bioinform
|
5
|
-
describe ArrayParser do
|
6
|
-
before :each do
|
7
|
-
@matrix = [[1,4,7,10], [2,5,8,11], [3,6,9,12]]
|
8
|
-
|
9
|
-
@valid_input = [[1,4,7,10], [2,5,8,11], [3,6,9,12]]
|
10
|
-
@valid_input_transposed = [[1,2,3], [4,5,6], [7,8,9], [10,11,12]]
|
11
|
-
|
12
|
-
@invalid_array_of_hashes = [{A: 1, C: 4, G: 7, T: 10}, {A: 2, C: 5, G: 8, T: 11}, {A: 3, C: 6, G: 9, T: 12}]
|
13
|
-
@invalid_input_hash = {A: [1,2,3], C: [4,5,6], G: [7,8,9], T: [10,11,12]}
|
14
|
-
|
15
|
-
@invalid_input_array_different_size = [[1,4,7,10], [2,5,8,11], [3,6]]
|
16
|
-
@invalid_input_array_transposed_different_size = [[1,2,3],[4,5,6],[7,8,9],[10]]
|
17
|
-
|
18
|
-
@invalid_not_hash_string = "1 2 3\n4 5 6\n7 8 9\n10 11 12"
|
19
|
-
@invalid_not_hash_string_transposed = "1 2 3 4\n5 6 7 8\n9 10 11 12"
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#can_parse?' do
|
23
|
-
it 'should be true for a valid array' do
|
24
|
-
ArrayParser.new(@valid_input).can_parse?.should be_true
|
25
|
-
ArrayParser.new(@valid_input_transposed).can_parse?.should be_true
|
26
|
-
end
|
27
|
-
it 'should be false for invalid input' do
|
28
|
-
ArrayParser.new(@invalid_array_of_hashes).can_parse?.should be_false
|
29
|
-
ArrayParser.new(@invalid_input_hash).can_parse?.should be_false
|
30
|
-
|
31
|
-
ArrayParser.new(@invalid_input_array_different_size).can_parse?.should be_false
|
32
|
-
ArrayParser.new(@invalid_input_array_transposed_different_size).can_parse?.should be_false
|
33
|
-
|
34
|
-
ArrayParser.new(@invalid_not_hash_string).can_parse?.should be_false
|
35
|
-
ArrayParser.new(@invalid_not_hash_string_transposed).can_parse?.should be_false
|
36
|
-
end
|
37
|
-
end
|
38
|
-
describe '#parse' do
|
39
|
-
it 'should raise an ArgumentError for invalid input' do
|
40
|
-
expect{ ArrayParser.new(@invalid_array_of_hashes).parse }.to raise_error ArgumentError
|
41
|
-
expect{ ArrayParser.new(@invalid_input_hash).parse }.to raise_error ArgumentError
|
42
|
-
expect{ ArrayParser.new(@invalid_input_array_different_size).parse }.to raise_error ArgumentError
|
43
|
-
expect{ ArrayParser.new(@invalid_input_array_transposed_different_size).parse }.to raise_error ArgumentError
|
44
|
-
expect{ ArrayParser.new(@invalid_not_hash_string).parse }.to raise_error ArgumentError
|
45
|
-
expect{ ArrayParser.new(@invalid_not_hash_string_transposed).parse }.to raise_error ArgumentError
|
46
|
-
end
|
47
|
-
it 'should return hash with `matrix` key for valid input' do
|
48
|
-
ArrayParser.new(@valid_input).parse.should == {matrix: @matrix}
|
49
|
-
ArrayParser.new(@valid_input_transposed).parse.should == {matrix: @matrix}
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'bioinform/data_models/parsers/hash_parser'
|
3
|
-
|
4
|
-
module Bioinform
|
5
|
-
describe HashParser do
|
6
|
-
before :each do
|
7
|
-
@matrix = [[1,4,7,10], [2,5,8,11], [3,6,9,12]]
|
8
|
-
|
9
|
-
@valid_input_symbolic_keys = {A: [1,2,3], C: [4,5,6], G: [7,8,9], T: [10,11,12]}
|
10
|
-
@valid_input_string_keys = {'A' => [1,2,3], 'C' => [4,5,6], 'G' => [7,8,9], 'T' => [10,11,12]}
|
11
|
-
@valid_array_of_hashes = [{A: 1, C: 4, G: 7, T: 10}, {A: 2, C: 5, G: 8, T: 11}, {A: 3, C: 6, G: 9, T: 12}]
|
12
|
-
|
13
|
-
@invalid_array_of_hashes_missing_keys = [{A: 1, C: 4, G: 7, T: 10}, {C: 5, T: 11}, {A: 3, C: 6, G: 9, T: 12}]
|
14
|
-
|
15
|
-
@invalid_input_different_length = {A: [1,2,3], C: [4,5,6], G: [7,8,9], T: [10]}
|
16
|
-
@invalid_input_not_all_keys = {A: [1,2,3], C: [4,5,6], G: [7,8,9]}
|
17
|
-
|
18
|
-
@invalid_not_hash_array = [[1,2,3], [4,5,6], [7,8,9], [10,11,12]]
|
19
|
-
@invalid_not_hash_array_transposed = [[1,4,7,10], [2,5,8,11], [3,6,9,12]]
|
20
|
-
|
21
|
-
@invalid_not_hash_string = "1 2 3\n4 5 6\n7 8 9\n10 11 12"
|
22
|
-
@invalid_not_hash_string_transposed = "1 2 3 4\n5 6 7 8\n9 10 11 12"
|
23
|
-
end
|
24
|
-
describe '#can_parse?' do
|
25
|
-
it 'should be true for a valid hash or array of hashes' do
|
26
|
-
HashParser.new(@valid_input_symbolic_keys).can_parse?.should be_true
|
27
|
-
HashParser.new(@valid_input_string_keys).can_parse?.should be_true
|
28
|
-
HashParser.new(@valid_array_of_hashes).can_parse?.should be_true
|
29
|
-
end
|
30
|
-
it 'should be false for invalid input' do
|
31
|
-
HashParser.new(@invalid_array_of_hashes_missing_keys).can_parse?.should be_false
|
32
|
-
HashParser.new(@invalid_input_different_length).can_parse?.should be_false
|
33
|
-
HashParser.new(@invalid_input_not_all_keys).can_parse?.should be_false
|
34
|
-
|
35
|
-
HashParser.new(@invalid_not_hash_array).can_parse?.should be_false
|
36
|
-
HashParser.new(@invalid_not_hash_array_transposed).can_parse?.should be_false
|
37
|
-
|
38
|
-
HashParser.new(@invalid_not_hash_string).can_parse?.should be_false
|
39
|
-
HashParser.new(@invalid_not_hash_string_transposed).can_parse?.should be_false
|
40
|
-
end
|
41
|
-
end
|
42
|
-
describe '#parse' do
|
43
|
-
it 'should raise an ArgumentError for invalid input' do
|
44
|
-
expect{ HashParser.new(@invalid_input_different_length).parse }.to raise_error ArgumentError
|
45
|
-
expect{ HashParser.new(@invalid_input_not_all_keys).parse }.to raise_error ArgumentError
|
46
|
-
|
47
|
-
expect{ HashParser.new(@invalid_not_hash_array).parse }.to raise_error ArgumentError
|
48
|
-
expect{ HashParser.new(@invalid_not_hash_array_transposed).parse }.to raise_error ArgumentError
|
49
|
-
|
50
|
-
expect{ HashParser.new(@invalid_not_hash_string).parse }.to raise_error ArgumentError
|
51
|
-
expect{ HashParser.new(@invalid_not_hash_string_transposed).parse }.to raise_error ArgumentError
|
52
|
-
end
|
53
|
-
it 'should return hash with `matrix` key for valid input' do
|
54
|
-
HashParser.new(@valid_input_symbolic_keys).parse.should == {matrix: @matrix}
|
55
|
-
HashParser.new(@valid_input_string_keys).parse.should == {matrix: @matrix}
|
56
|
-
HashParser.new(@valid_array_of_hashes).parse.should == {matrix: @matrix}
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'bioinform/data_models/parsers/string_fantom_parser'
|
3
|
-
|
4
|
-
module Bioinform
|
5
|
-
describe StringFantomParser do
|
6
|
-
before :each do
|
7
|
-
@matrix = [[0.0, 1878368.0, 0.0, 0.0],
|
8
|
-
[0.0, 0.0, 0.0, 1878368.0],
|
9
|
-
[469592.0, 469592.0, 469592.0, 469592.0],
|
10
|
-
[0.0, 1878368.0, 0.0, 0.0],
|
11
|
-
[1878368.0, 0.0, 0.0, 0.0],
|
12
|
-
[0.0, 0.0, 1878368.0, 0.0]]
|
13
|
-
|
14
|
-
@good_input = <<-EOS
|
15
|
-
NA motif_CTNCAG
|
16
|
-
P0 A C G T
|
17
|
-
P1 0 1878368 0 0
|
18
|
-
P2 0 0 0 1878368
|
19
|
-
P3 469592 469592 469592 469592
|
20
|
-
P4 0 1878368 0 0
|
21
|
-
P5 1878368 0 0 0
|
22
|
-
P6 0 0 1878368 0
|
23
|
-
EOS
|
24
|
-
end
|
25
|
-
|
26
|
-
describe '#can_parse?' do
|
27
|
-
it 'should parse particular kind of string' do
|
28
|
-
StringFantomParser.new(@good_input).can_parse?.should be_true
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#parse' do
|
33
|
-
it 'should parse particular kind of string' do
|
34
|
-
StringFantomParser.new(@good_input).parse.should == { matrix: @matrix, name: 'motif_CTNCAG'}
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,156 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'bioinform/data_models/parsers/string_parser'
|
3
|
-
|
4
|
-
module Bioinform
|
5
|
-
describe StringParser do
|
6
|
-
before :each do
|
7
|
-
@matrix = [[1.23, 4.56, 7.8, 9.0],[9.0, -8.7, 6.54, -3210.0]]
|
8
|
-
|
9
|
-
@input_with_name = <<-EOS
|
10
|
-
Testmatrix
|
11
|
-
1.23 4.56 7.8 9.0
|
12
|
-
9 -8.7 6.54 -3210
|
13
|
-
EOS
|
14
|
-
|
15
|
-
@input_with_name_with_introduction_sign = <<-EOS
|
16
|
-
> Testmatrix
|
17
|
-
1.23 4.56 7.8 9.0
|
18
|
-
9 -8.7 6.54 -3210
|
19
|
-
EOS
|
20
|
-
|
21
|
-
@input_with_name_with_special_characters = <<-EOS
|
22
|
-
Testmatrix_first:subname+sub-subname
|
23
|
-
1.23 4.56 7.8 9.0
|
24
|
-
9 -8.7 6.54 -3210
|
25
|
-
EOS
|
26
|
-
|
27
|
-
@input_with_tabs_and_multiple_spaces = <<-EOS
|
28
|
-
> \tTestmatrix
|
29
|
-
1.23 \t 4.56 7.8\t\t 9.0
|
30
|
-
9 -8.7 6.54 -3210
|
31
|
-
EOS
|
32
|
-
|
33
|
-
@input_with_windows_crlf = <<-EOS
|
34
|
-
> Testmatrix\r
|
35
|
-
1.23 4.56 7.8 9.0
|
36
|
-
9 -8.7 6.54 -3210\r
|
37
|
-
EOS
|
38
|
-
|
39
|
-
@input_with_leading_and_finishing_spaces_and_newlines = <<-EOS
|
40
|
-
\n\n
|
41
|
-
\t1.23 4.56 7.8 9.0
|
42
|
-
9 -8.7 6.54 -3210
|
43
|
-
\t\r\n\t\n
|
44
|
-
EOS
|
45
|
-
|
46
|
-
@input_without_name = <<-EOS
|
47
|
-
1.23 4.56 7.8 9.0
|
48
|
-
9 -8.7 6.54 -3210
|
49
|
-
EOS
|
50
|
-
|
51
|
-
@input_with_exponent = <<-EOS
|
52
|
-
1.23 4.56 7.8 9.0
|
53
|
-
9 -8.7 6.54 -3.210e3
|
54
|
-
EOS
|
55
|
-
|
56
|
-
@input_with_plus_exponent = <<-EOS
|
57
|
-
1.23 4.56 7.8 9.0
|
58
|
-
9 -8.7 6.54 -3.210e+3
|
59
|
-
EOS
|
60
|
-
|
61
|
-
@input_with_minus_exponent = <<-EOS
|
62
|
-
1.23 4.56 7.8 9.0
|
63
|
-
9 -87e-1 6.54 -3210
|
64
|
-
EOS
|
65
|
-
|
66
|
-
@input_with_upcase_exponent = <<-EOS
|
67
|
-
1.23 4.56 7.8 9.0
|
68
|
-
9 -8.7 6.54 -3.210E3
|
69
|
-
EOS
|
70
|
-
|
71
|
-
@input_with_manydigit_exponent = <<-EOS
|
72
|
-
1.23 4.56 7.8 9.0
|
73
|
-
9 -8.7 6.54 -0.0000003210e10
|
74
|
-
EOS
|
75
|
-
|
76
|
-
@input_transposed = <<-EOS
|
77
|
-
1.23 9
|
78
|
-
4.56 -8.7
|
79
|
-
7.8 6.54
|
80
|
-
9.0 -3210
|
81
|
-
EOS
|
82
|
-
|
83
|
-
|
84
|
-
@bad_input_not_numeric = <<-EOS
|
85
|
-
1.23 4.56 aaa 9.0
|
86
|
-
9 -8.7 6.54 -3210
|
87
|
-
EOS
|
88
|
-
|
89
|
-
@bad_input_different_row_size = <<-EOS
|
90
|
-
1.23 4.56 7.8 9
|
91
|
-
9 -8.7 6.54
|
92
|
-
EOS
|
93
|
-
|
94
|
-
@bad_input_not_4_rows_and_cols = <<-EOS
|
95
|
-
1.23 4.56 7.8
|
96
|
-
9 -8.7 6.54
|
97
|
-
10 2 10
|
98
|
-
4 5 6
|
99
|
-
1 1 1
|
100
|
-
EOS
|
101
|
-
|
102
|
-
@bad_input_with_empty_exponent = <<-EOS
|
103
|
-
1.23 4.56 7.8 9.0
|
104
|
-
9e -8.7 6.54 3210
|
105
|
-
EOS
|
106
|
-
end
|
107
|
-
|
108
|
-
describe '#can_parse?' do
|
109
|
-
it 'should return true for valid input string' do
|
110
|
-
StringParser.new(@input_with_name).can_parse?.should be_true
|
111
|
-
StringParser.new(@input_with_name_with_introduction_sign).can_parse?.should be_true
|
112
|
-
StringParser.new(@input_with_name_with_special_characters).can_parse?.should be_true
|
113
|
-
StringParser.new(@input_with_tabs_and_multiple_spaces).can_parse?.should be_true
|
114
|
-
StringParser.new(@input_with_windows_crlf).can_parse?.should be_true
|
115
|
-
StringParser.new(@input_with_leading_and_finishing_spaces_and_newlines).can_parse?.should be_true
|
116
|
-
StringParser.new(@input_without_name).can_parse?.should be_true
|
117
|
-
StringParser.new(@input_transposed).can_parse?.should be_true
|
118
|
-
StringParser.new(@input_with_exponent).can_parse?.should be_true
|
119
|
-
StringParser.new(@input_with_plus_exponent).can_parse?.should be_true
|
120
|
-
StringParser.new(@input_with_minus_exponent).can_parse?.should be_true
|
121
|
-
StringParser.new(@input_with_upcase_exponent).can_parse?.should be_true
|
122
|
-
StringParser.new(@input_with_manydigit_exponent).can_parse?.should be_true
|
123
|
-
|
124
|
-
end
|
125
|
-
it 'should return false for invalid input string' do
|
126
|
-
StringParser.new(@bad_input_not_numeric).can_parse?.should be_false
|
127
|
-
StringParser.new(@bad_input_different_row_size).can_parse?.should be_false
|
128
|
-
StringParser.new(@bad_input_not_4_rows_and_cols).can_parse?.should be_false
|
129
|
-
StringParser.new(@bad_input_with_empty_exponent).can_parse?.should be_false
|
130
|
-
end
|
131
|
-
end
|
132
|
-
describe '#parse' do
|
133
|
-
it 'should return a hash with matrix and possibly name keys for valid input string' do
|
134
|
-
StringParser.new(@input_with_name).parse.should == {matrix: @matrix, name: 'Testmatrix'}
|
135
|
-
StringParser.new(@input_with_name_with_introduction_sign).parse.should == {matrix: @matrix, name: 'Testmatrix'}
|
136
|
-
StringParser.new(@input_with_name_with_special_characters).parse.should == {matrix: @matrix, name: 'Testmatrix_first:subname+sub-subname'}
|
137
|
-
StringParser.new(@input_with_tabs_and_multiple_spaces).parse.should == {matrix: @matrix, name: 'Testmatrix'}
|
138
|
-
StringParser.new(@input_with_windows_crlf).parse.should == {matrix: @matrix, name: 'Testmatrix'}
|
139
|
-
StringParser.new(@input_with_leading_and_finishing_spaces_and_newlines).parse.should == {matrix: @matrix}
|
140
|
-
StringParser.new(@input_without_name).parse.should == {matrix: @matrix}
|
141
|
-
StringParser.new(@input_transposed).parse.should == {matrix: @matrix}
|
142
|
-
StringParser.new(@input_with_exponent).parse.should == {matrix: @matrix}
|
143
|
-
StringParser.new(@input_with_plus_exponent).parse.should == {matrix: @matrix}
|
144
|
-
StringParser.new(@input_with_minus_exponent).parse.should == {matrix: @matrix}
|
145
|
-
StringParser.new(@input_with_upcase_exponent).parse.should == {matrix: @matrix}
|
146
|
-
StringParser.new(@input_with_manydigit_exponent).parse.should == {matrix: @matrix}
|
147
|
-
end
|
148
|
-
it 'should raise an error for invalid input string' do
|
149
|
-
expect{ StringParser.new(@bad_input_not_numeric).parse }.to raise_error ArgumentError
|
150
|
-
expect{ StringParser.new(@bad_input_different_row_size).parse }.to raise_error ArgumentError
|
151
|
-
expect{ StringParser.new(@bad_input_not_4_rows_and_cols).parse }.to raise_error ArgumentError
|
152
|
-
expect{ StringParser.new(@bad_input_with_empty_exponent).parse }.to raise_error ArgumentError
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|