aboutsummaryrefslogtreecommitdiff
path: root/test/lib/test-helpers.rb
blob: a409626fbaaa36fe514404f8443fed0e9e6b0be7 (about) (plain)
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
module TestHelpers

  # Runs gemma and returns true if successful
  def gemma(opts)
    assert system("./bin/gemma -debug -check #{opts}")
  end

  def read(fn, line=0)
    count = 0
    File.open(fn, "r:utf-8").each_line { |ln|
      return ln.chomp.split("\t") if count == line
      count += 1
    }
  end

  def expect(fn, list)
    lines = File.read(fn).split("\n")
    lines = lines.map { |l| l.split("\t") } # avoid this for large files
    list.each do | l |
      line,colnum,value = l
      if colnum.is_a? String
        colnum = lines[0].index(colnum)
      end
      cols =
        if line == :max
          lines.max_by {|a| a[colnum].to_f}
        else
          lines[line]
        end
      # assert_equal value,cols[colnum]
      assert_in_delta value.to_f,cols[colnum].to_f, 0.001
    end
  end
end