From 90ffbe36dae3233dc0afccb57d2dfe10c08b9218 Mon Sep 17 00:00:00 2001 From: Eric Au Date: Tue, 16 Jul 2024 06:35:01 -0400 Subject: [PATCH] docs+test: added package godoc with a few small tests --- interval/lift/lift.go | 1 + interval/lift/lift_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/interval/lift/lift.go b/interval/lift/lift.go index 6a9c14717..06f46f27d 100644 --- a/interval/lift/lift.go +++ b/interval/lift/lift.go @@ -1,3 +1,4 @@ +// Package lift provides an interface and utilities for working with genomic regions and offer flexibility to modify their coordinates. package lift import ( diff --git a/interval/lift/lift_test.go b/interval/lift/lift_test.go index 48e331816..fbe9ace8c 100644 --- a/interval/lift/lift_test.go +++ b/interval/lift/lift_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/vertgenlab/gonomics/bed" + "github.com/vertgenlab/gonomics/interval" ) var ReadingTests = []struct { @@ -22,3 +23,29 @@ func TestReading(t *testing.T) { } } } + +func TestIntervalSliceToLift(t *testing.T) { + // Create intervals where some implement Lift, others don't + intervals := []interval.Interval{ + bed.Bed{Chrom: "chr1", ChromStart: 1, ChromEnd: 30}, + bed.Bed{Chrom: "chr2", ChromStart: 300, ChromEnd: 400}, + } + lifts := IntervalSliceToLift(intervals) + expected := []Lift{ + bed.Bed{Chrom: "chr1", ChromStart: 1, ChromEnd: 30}, + bed.Bed{Chrom: "chr2", ChromStart: 300, ChromEnd: 400}, + } + if !allAreEqual(lifts, expected) { + t.Errorf("Error: IntervalSliceToLift(intervals, expected) do not equal.\n") + } +} + +func TestMatchOverlapLen(t *testing.T) { + var one bed.Bed = bed.Bed{Chrom: "chr1", ChromStart: 5, ChromEnd: 15} + var two bed.Bed = bed.Bed{Chrom: "chr1", ChromStart: 11, ChromEnd: 14} + overlapSize := MatchOverlapLen(one.GetChromStart(), one.GetChromEnd(), two.GetChromStart(), two.GetChromEnd()) + expected := 3 + if overlapSize != expected { + t.Errorf("Error: MatchOverlapLen(%d, %d, %d, %d) %d != %d\n", one.GetChromStart(), one.GetChromEnd(), two.GetChromStart(), two.GetChromEnd(), overlapSize, expected) + } +}