| 1 | package irelate |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "fmt" |
| 6 | "testing" |
| 7 | |
| 8 | . "github.com/brentp/irelate/interfaces" |
| 9 | "github.com/brentp/irelate/parsers" |
| 10 | ) |
| 11 | |
| 12 | func TestInterval(t *testing.T) { |
| 13 | a := parsers.NewInterval("chr1", 1234, 5678, bytes.Split([]byte("chr1\t1234\t5678"), []byte("\t")), 0, nil) |
| 14 | if a.Chrom() != "chr1" { |
| 15 | t.Error("expected \"chr1\", got", a.Chrom()) |
| 16 | } |
| 17 | if a.Start() != 1234 { |
| 18 | t.Error("expected start = 1234, got", a.Start()) |
| 19 | } |
| 20 | if a.End() != 5678 { |
| 21 | t.Error("expected start = 5678, got", a.End()) |
| 22 | } |
| 23 | |
| 24 | s := fmt.Sprintf("%v", a) |
| 25 | if len(s) == 0 { |
| 26 | t.Error("bad String") |
| 27 | } |
| 28 | |
| 29 | } |
| 30 | |
| 31 | func TestIntervalSource(t *testing.T) { |
| 32 | var a Relatable |
| 33 | a = parsers.NewInterval("chr1", 1234, 5678, bytes.Split([]byte("chr1\t1234\t5678"), []byte("\t")), 0, nil) |
| 34 | a.SetSource(222) |
| 35 | |
| 36 | if a.Source() != 222 { |
| 37 | t.Error("expected 222, got", a.Source()) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | func TestIntervalLine(t *testing.T) { |
| 42 | s := []byte("chr1\t1235\t4567\tasdf") |
| 43 | i, _ := parsers.IntervalFromBedLine(s) |
| 44 | if i.Start() != uint32(1235) { |
| 45 | t.Error("expected start of 1235") |
| 46 | } |
| 47 | } |