Skip to content

Commit

Permalink
got test coverage to 100% and change variable names. Think I may have…
Browse files Browse the repository at this point in the history
… found bug?
  • Loading branch information
TimothyStiles committed Nov 6, 2023
1 parent c4e705a commit 67546f7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
16 changes: 8 additions & 8 deletions mash/mash.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ func (mash *Mash) Similarity(other *Mash) float64 {
return 0
}

i, j := 0, 0
for i < smallerSketch.SketchSize && j < largerSketch.SketchSize {
if smallerSketch.Sketches[i] == largerSketch.Sketches[j] {
smallSketchIndex, largeSketchIndex := 0, 0
for smallSketchIndex < smallerSketch.SketchSize && largeSketchIndex < largerSketch.SketchSize {
if smallerSketch.Sketches[smallSketchIndex] == largerSketch.Sketches[largeSketchIndex] {
sameHashes++
i++
j++
} else if smallerSketch.Sketches[i] < largerSketch.Sketches[j] {
i++
smallSketchIndex++
largeSketchIndex++
} else if smallerSketch.Sketches[smallSketchIndex] < largerSketch.Sketches[largeSketchIndex] {
smallSketchIndex++
} else {
j++
largeSketchIndex++
}
}

Expand Down
22 changes: 22 additions & 0 deletions mash/mash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ func TestMash(t *testing.T) {
if distance != 1 {
t.Errorf("Expected distance to be 1, got %f", distance)
}

fingerprint1 = mash.New(17, 10)
fingerprint1.Sketch("ATGCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGA")

fingerprint2 = mash.New(17, 5)
fingerprint2.Sketch("ATCGATCGATCGATCGATCGATCGATCGATCGATCGAATGCGATCGATCGATCGATCGATCG")

distance = fingerprint1.Distance(fingerprint2)
if !(distance > 0.19 && distance < 0.21) {
t.Errorf("Expected distance to be 0.19999999999999996, got %f", distance)
}

fingerprint1 = mash.New(17, 10)
fingerprint1.Sketch("ATCGATCGATCGATCGATCGATCGATCGATCGATCGAATGCGATCGATCGATCGATCGATCG")

fingerprint2 = mash.New(17, 5)
fingerprint2.Sketch("ATGCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGA")

distance = fingerprint1.Distance(fingerprint2) // TODO: this shouldn't return 0 and should be same as above?
if distance != 0 {
t.Errorf("Expected distance to be 0, got %f", distance)
}
}

func BenchmarkMashDistancee(b *testing.B) {
Expand Down

0 comments on commit 67546f7

Please sign in to comment.