rbbt-util 3.2.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,136 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
2
- require 'rbbt/util/bed'
3
- require 'rbbt/util/tmpfile'
4
-
5
- class TestBed < Test::Unit::TestCase
6
- def load_data(data)
7
- Log.debug("Data:\n#{Open.read(data)}")
8
- tsv = TSV.new(data, :list, :sep=>":", :cast => proc{|e| e =~ /(\s*)(_*)/; ($1.length..($1.length + $2.length - 1))})
9
- tsv.add_field "Start" do |key, values|
10
- values["Range"].first
11
- end
12
- tsv.add_field "End" do |key, values|
13
- values["Range"].last
14
- end
15
-
16
- tsv
17
- end
18
-
19
- def test_point
20
- data =<<-EOF
21
- #ID Pos
22
- a 1
23
- b 10
24
- c 20
25
- d 12
26
- e 26
27
- f 11
28
- g 25
29
- EOF
30
-
31
- TmpFile.with_file(data) do |f|
32
- bed = Bed.new TSV.new(f, :list, :sep=>" "), :key => "Pos" , :value => "ID"
33
-
34
- assert_equal %w(), bed[0].sort
35
- assert_equal %w(b), bed[10].sort
36
- assert_equal %w(a b c d f), bed[(0..20)].sort
37
- end
38
- end
39
-
40
- def test_range
41
- data =<<-EOF
42
- #ID:Range
43
- #:012345678901234567890
44
- a: ______
45
- b: ______
46
- c: _______
47
- d: ____
48
- e: ______
49
- f: ___
50
- g: ____
51
- EOF
52
-
53
- TmpFile.with_file(data) do |f|
54
- bed = Bed.new load_data(f), :range => ["Start" , "End"], :value => "ID"
55
-
56
- assert_equal %w(), bed[0].sort
57
- assert_equal %w(b), bed[1].sort
58
- assert_equal %w(), bed[20].sort
59
- assert_equal %w(), bed[(20..100)].sort
60
- assert_equal %w(a b d), bed[3].sort
61
- assert_equal %w(a b c d e), bed[(3..4)].sort
62
- end
63
- end
64
-
65
- def test_format
66
- entry = Bed::Entry.new "Hola", 0, 10, nil
67
- format = Bed::FixWidthTable.format(entry,1, 100)
68
- assert_equal entry, Bed::FixWidthTable.unformat(format, 100)
69
- end
70
-
71
- def test_table
72
- TmpFile.with_file do |f|
73
- table = Bed::FixWidthTable.new(f, 100, false)
74
- table.add Bed::Entry.new("Entry1", 0, 10, nil), 0
75
- table.add Bed::Entry.new("Entry2", 10, 20, nil), 10
76
- table.add Bed::Entry.new("Entry3", 10, 20, nil), 10
77
-
78
- table.read
79
-
80
- assert_equal "Entry1", table[0].value
81
- assert_equal "Entry2", table[1].value
82
- assert_equal "Entry3", table[2].value
83
- end
84
-
85
- end
86
-
87
- def test_range_point
88
- data =<<-EOF
89
- #ID Pos
90
- a 1
91
- b 10
92
- c 20
93
- d 12
94
- e 26
95
- f 11
96
- g 25
97
- EOF
98
-
99
- TmpFile.with_file(data) do |f|
100
- bed = Bed.new TSV.new(f,:list, :sep=>" "), :key => "Pos" , :value => "ID", :persistence => true
101
-
102
- bed = Bed.new TSV.new(f,:list, :sep=>" "), :key => "Pos" , :value => "ID", :persistence => true
103
-
104
- assert_equal %w(), bed[0].sort
105
- assert_equal %w(a b c d f), bed[(0..20)].sort
106
- assert_equal %w(b), bed[10].sort
107
- end
108
- end
109
-
110
- def test_range_persistence
111
- data =<<-EOF
112
- #ID:Range
113
- #:012345678901234567890
114
- a: ______
115
- b: ______
116
- c: _______
117
- d: ____
118
- e: ______
119
- f: ___
120
- g: ____
121
- EOF
122
-
123
- TmpFile.with_file(data) do |f|
124
- bed = Bed.new load_data(f), :range => ["Start" , "End"], :value => "ID", :persistence => true
125
-
126
- bed = Bed.new load_data(f), :range => ["Start" , "End"], :value => "ID", :persistence => true
127
-
128
- assert_equal %w(), bed[0].sort
129
- assert_equal %w(b), bed[1].sort
130
- assert_equal %w(), bed[20].sort
131
- assert_equal %w(), bed[(20..100)].sort
132
- assert_equal %w(a b d), bed[3].sort
133
- assert_equal %w(a b c d e), bed[(3..4)].sort
134
- end
135
- end
136
- end