Skip to content

Commit

Permalink
Testing graphviz
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Oct 29, 2015
1 parent 61bf59c commit e0663ee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
7 changes: 1 addition & 6 deletions wookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,14 @@ func (p *Part) CoincideLength(part *Part) int {
maxLength = rightLen
}

for i := maxLength; i >= 0; i-- {
for i := maxLength; i > 0; i-- {
if idx := strings.Index(p.Line[:i], part.Line[rightLen-i:]); idx != -1 {
return i
}
}
return -1
}

func (p *Part) CoincideWith(part *Part, minLength int) bool {
return p.CoincideLength(part) >= minLength
}

func (w *Wookie) Compute() bool {

minLength := len(w.Lines[0])
Expand All @@ -87,7 +83,6 @@ func (w *Wookie) Compute() bool {
}
coincideLength := otherPart.CoincideLength(part)
if coincideLength > 0 {
//if otherPart.CoincideWith(part, length) {
part.Rights[coincideLength] = append(part.Rights[coincideLength], otherPart)
}
}
Expand Down
27 changes: 27 additions & 0 deletions wookie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,30 @@ TTGTATTTCATTTGATTTTCCCCCGCCCCTCCC`, "\n")
So(wookie.Compute(), ShouldBeFalse)
})
}

func TestWookie_Graphviz(t *testing.T) {
Convey("Testing Wookie.Graphviz()", t, func() {
input := strings.Split(`abcd|efgh|cdef|ghij|bcde`, "|")
wookie := NewWookie(input)
So(wookie.Compute(), ShouldBeTrue)
expected := `digraph G {
start->abcd;
ghij->end;
abcd->bcde[ color=red, label=idx1_len3 ];
bcde->cdef[ color=red, label=idx2_len3 ];
cdef->efgh[ color=red, label=idx3_len2 ];
efgh->ghij[ color=red, label=idx4_len2 ];
abcd->cdef[ label=len2 ];
abcd [ color=blue ];
bcde [ color=blue ];
cdef [ color=blue ];
efgh [ color=blue ];
end [ shape=Msquare ];
ghij [ color=blue ];
start [ shape=Mdiamond ];
}
`
So(wookie.Graphviz(), ShouldEqual, expected)
})
}

0 comments on commit e0663ee

Please sign in to comment.