File: test_rgfa.rb

package info (click to toggle)
ruby-rgfa 1.3.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 824 kB
  • sloc: ruby: 5,649; makefile: 9
file content (101 lines) | stat: -rw-r--r-- 2,621 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
require "rgfa.rb"
require "test/unit"
require "tempfile"

class TestRGFA < Test::Unit::TestCase

  def test_initialize
    assert_nothing_raised { RGFA.new }
    gfa = RGFA.new
    assert_equal(RGFA, gfa.class)
  end

  def test_segment_names
    gfa = RGFA.new
    assert_equal([], gfa.segment_names)
    gfa << "S\t1\t*"
    gfa << "S\t2\t*"
    assert_equal([:"1", :"2"], gfa.segment_names)
    gfa.delete_segment("1")
    assert_equal([:"2"], gfa.segment_names)
  end

  def test_path_names
    gfa = RGFA.new
    assert_equal([], gfa.path_names)
    gfa << "P\t3\t1+,4-\t*"
    assert_equal([:"3"], gfa.path_names)
    gfa.delete_path("3")
    assert_equal([], gfa.path_names)
  end

  def test_validate!
    gfa = RGFA.new
    gfa << "S\t1\t*"
    assert_nothing_raised { gfa.validate! }
    gfa << "L\t1\t+\t2\t-\t*"
    assert_raise(RGFA::LineMissingError) { gfa.validate! }
    gfa << "S\t2\t*"
    assert_nothing_raised { gfa.validate! }
    gfa << "P\t3\t1+,4-\t*"
    assert_raise(RGFA::LineMissingError) { gfa.validate! }
    gfa << "S\t4\t*"
    assert_raise(RGFA::LineMissingError) { gfa.validate! }
    gfa << "L\t4\t+\t1\t-\t*"
    assert_nothing_raised { gfa.validate! }
  end

  def test_to_s
    lines = ["H\tVN:Z:1.0","S\t1\t*","S\t2\t*","S\t3\t*",
     "L\t1\t+\t2\t-\t*","C\t1\t+\t3\t-\t12\t*","P\t4\t1+,2-\t*"]
    gfa = RGFA.new
    lines.each {|l| gfa << l}
    assert_equal(lines.join("\n")+"\n", gfa.to_s)
  end

  def test_to_rgfa
    gfa = RGFA.new
    gfa2 = gfa.to_rgfa
    assert(gfa2)
    assert_equal(RGFA, gfa2.class)
  end

  def test_from_file
    filename = "test/testdata/example1.gfa"
    gfa = RGFA.from_file(filename)
    assert(gfa)
    assert_equal(IO.read(filename), gfa.to_s)
  end

  def test_to_file
    filename = "test/testdata/example1.gfa"
    gfa = RGFA.from_file(filename)
    tmp = Tempfile.new("example1")
    gfa.to_file(tmp.path)
    tmp.rewind
    assert_equal(IO.read(filename), IO.read(tmp))
  end

  def test_string_to_rgfa
    lines = ["H\tVN:Z:1.0","S\t1\t*","S\t2\t*","S\t3\t*",
     "L\t1\t+\t2\t-\t*","C\t1\t+\t3\t-\t12\t*","P\t4\t1+,2-\t*"]
    gfa1 = RGFA.new
    lines.each {|l| gfa1 << l}
    gfa2 = lines.join("\n").to_rgfa
    assert(gfa2)
    assert_equal(RGFA, gfa2.class)
    assert_equal(gfa1.to_s, gfa2.to_s)
  end

  def test_array_to_rgfa
    lines = ["H\tVN:Z:1.0","S\t1\t*","S\t2\t*","S\t3\t*",
     "L\t1\t+\t2\t-\t*","C\t1\t+\t3\t-\t12\t*","P\t4\t1+,2-\t*"]
    gfa1 = RGFA.new
    lines.each {|l| gfa1 << l}
    gfa2 = lines.to_rgfa
    assert(gfa2)
    assert_equal(RGFA, gfa2.class)
    assert_equal(gfa1.to_s, gfa2.to_s)
  end

end