mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Adds some unit test
Former-commit-id: b1a59df1c87187a1538f30c447d42bbe96402419
This commit is contained in:
6
go.mod
6
go.mod
@ -1,6 +1,6 @@
|
||||
module git.metabarcoding.org/lecasofts/go/obitools
|
||||
|
||||
go 1.20
|
||||
go 1.21
|
||||
|
||||
require (
|
||||
github.com/DavidGamba/go-getoptions v0.28.0
|
||||
@ -13,6 +13,7 @@ require (
|
||||
github.com/rrethy/ahocorasick v1.0.0
|
||||
github.com/schollz/progressbar/v3 v3.13.1
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/tevino/abool/v2 v2.1.0
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
|
||||
gonum.org/v1/gonum v0.14.0
|
||||
@ -20,8 +21,11 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/kr/pretty v0.2.1 // indirect
|
||||
github.com/kr/text v0.1.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
|
15
go.work.sum
Normal file
15
go.work.sum
Normal file
@ -0,0 +1,15 @@
|
||||
git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3pc=
|
||||
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b/go.mod h1:1KcenG0jGWcpt8ov532z81sp/kMMUG485J2InIOyADM=
|
||||
github.com/go-fonts/liberation v0.3.0/go.mod h1:jdJ+cqF+F4SUL2V+qxBth8fvBpBDS7yloUL5Fi8GTGY=
|
||||
github.com/go-latex/latex v0.0.0-20230307184459-12ec69307ad9/go.mod h1:gWuR/CrFDDeVRFQwHPvsv9soJVB/iqymhuZQuJ3a9OM=
|
||||
github.com/go-pdf/fpdf v0.6.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M=
|
||||
github.com/goccmack/gocc v0.0.0-20230228185258-2292f9e40198/go.mod h1:DTh/Y2+NbnOVVoypCCQrovMPDKUGp4yZpSbWg5D0XIM=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||
golang.org/x/image v0.6.0/go.mod h1:MXLdDR43H7cDJq5GEGXEVeeNhPgi+YYEQ2pC1byI1x0=
|
||||
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
|
||||
gonum.org/v1/plot v0.10.1/go.mod h1:VZW5OlhkL1mysU9vaqNHnsy86inf6Ot+jB3r+BczCEo=
|
||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
@ -5,8 +5,16 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Returns a sub sequence start from position 'from' included,
|
||||
// to position 'to' excluded. Coordinates start at position 0.
|
||||
// Subsequence returns a subsequence of the BioSequence.
|
||||
//
|
||||
// Parameters:
|
||||
// - from: starting position of the subsequence.
|
||||
// - to: ending position of the subsequence.
|
||||
// - circular: indicates whether the subsequence should be circular.
|
||||
//
|
||||
// Return:
|
||||
// - *BioSequence: the subsequence of the BioSequence.
|
||||
// - error: an error if the subsequence parameters are invalid.
|
||||
func (sequence *BioSequence) Subsequence(from, to int, circular bool) (*BioSequence, error) {
|
||||
if from >= to && !circular {
|
||||
return nil, errors.New("from greater than to")
|
||||
|
48
pkg/obiseq/subseq_test.go
Normal file
48
pkg/obiseq/subseq_test.go
Normal file
@ -0,0 +1,48 @@
|
||||
package obiseq
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSubsequence(t *testing.T) {
|
||||
// Test case 1: Subsequence with valid parameters and non-circular
|
||||
seq := NewBioSequence("ID1", []byte("ATCG"), "")
|
||||
sub, err := seq.Subsequence(1, 3, false)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []byte("tc"), sub.Sequence())
|
||||
|
||||
seq = NewBioSequenceWithQualities("ID1", []byte("ATCG"), "", []byte{40, 30, 20, 10})
|
||||
sub, err = seq.Subsequence(1, 3, false)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []byte("tc"), sub.Sequence())
|
||||
assert.Equal(t, Quality([]byte{30, 20}), sub.Qualities())
|
||||
|
||||
// Test case 2: Subsequence with valid parameters and circular
|
||||
seq2 := NewBioSequence("ID1", []byte("ATCG"), "")
|
||||
sub2, err2 := seq2.Subsequence(3, 2, true)
|
||||
assert.NoError(t, err2)
|
||||
assert.Equal(t, []byte("gat"), sub2.Sequence())
|
||||
|
||||
seq = NewBioSequenceWithQualities("ID1", []byte("ATCG"), "", []byte{40, 30, 20, 10})
|
||||
sub, err = seq.Subsequence(3, 2, true)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []byte("gat"), sub.Sequence())
|
||||
assert.Equal(t, Quality([]byte{10, 40, 30}), sub.Qualities())
|
||||
|
||||
// Test case 3: Subsequence with from greater than to and non-circular
|
||||
seq3 := NewBioSequence("ID1", []byte("ATCG"), "")
|
||||
_, err3 := seq3.Subsequence(3, 1, false)
|
||||
assert.EqualError(t, err3, "from greater than to")
|
||||
|
||||
// Test case 4: Subsequence with from out of bounds
|
||||
seq4 := NewBioSequence("ID1", []byte("ATCG"), "")
|
||||
_, err4 := seq4.Subsequence(-1, 2, false)
|
||||
assert.EqualError(t, err4, "from out of bounds")
|
||||
|
||||
// Test case 5: Subsequence with to out of bounds
|
||||
seq5 := NewBioSequence("ID1", []byte("ATCG"), "")
|
||||
_, err5 := seq5.Subsequence(2, 5, false)
|
||||
assert.EqualError(t, err5, "to out of bounds")
|
||||
}
|
Reference in New Issue
Block a user