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

  # Runs gemma and returns true if successful
  def gemma(opts)
    system("./bin/gemma #{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 line == :max
        cols = lines.max_by {|a| a[colnum].to_f}
      else
        cols = lines[line]
      end
      # assert_equal value,cols[colnum]
      assert_in_delta value.to_f,cols[colnum].to_f, 0.001
    end
  end
end