Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package stringUtil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSimilarity(t *testing.T) {
|
||||
source := ""
|
||||
target := ""
|
||||
expectedDistance := 0
|
||||
expectedSimilarity := 0.0
|
||||
gotDistance, gotSimilarity := Similarity(source, target)
|
||||
if gotDistance != expectedDistance {
|
||||
t.Errorf("Expected to get %d, now got %d", expectedDistance, gotDistance)
|
||||
return
|
||||
}
|
||||
if gotSimilarity != expectedSimilarity {
|
||||
t.Errorf("Expected to get %f, now got %f", expectedSimilarity, gotSimilarity)
|
||||
return
|
||||
}
|
||||
|
||||
source = "Hello"
|
||||
target = ""
|
||||
expectedDistance = 5
|
||||
expectedSimilarity = 0.0
|
||||
gotDistance, gotSimilarity = Similarity(source, target)
|
||||
if gotDistance != expectedDistance {
|
||||
t.Errorf("Expected to get %d, now got %d", expectedDistance, gotDistance)
|
||||
return
|
||||
}
|
||||
if gotSimilarity != expectedSimilarity {
|
||||
t.Errorf("Expected to get %f, now got %f", expectedSimilarity, gotSimilarity)
|
||||
return
|
||||
}
|
||||
|
||||
source = ""
|
||||
target = "Hello"
|
||||
expectedDistance = 5
|
||||
expectedSimilarity = 0.0
|
||||
gotDistance, gotSimilarity = Similarity(source, target)
|
||||
if gotDistance != expectedDistance {
|
||||
t.Errorf("Expected to get %d, now got %d", expectedDistance, gotDistance)
|
||||
return
|
||||
}
|
||||
if gotSimilarity != expectedSimilarity {
|
||||
t.Errorf("Expected to get %f, now got %f", expectedSimilarity, gotSimilarity)
|
||||
return
|
||||
}
|
||||
|
||||
source = "Helo"
|
||||
target = "Hello"
|
||||
expectedDistance = 1
|
||||
expectedSimilarity = 4.0 / 5.0
|
||||
gotDistance, gotSimilarity = Similarity(source, target)
|
||||
if gotDistance != expectedDistance {
|
||||
t.Errorf("Expected to get %d, now got %d", expectedDistance, gotDistance)
|
||||
return
|
||||
}
|
||||
if gotSimilarity != expectedSimilarity {
|
||||
t.Errorf("Expected to get %f, now got %f", expectedSimilarity, gotSimilarity)
|
||||
return
|
||||
}
|
||||
|
||||
source = "kitten"
|
||||
target = "sitten"
|
||||
expectedDistance = 1
|
||||
expectedSimilarity = 5.0 / 6.0
|
||||
gotDistance, gotSimilarity = Similarity(source, target)
|
||||
if gotDistance != expectedDistance {
|
||||
t.Errorf("Expected to get %d, now got %d", expectedDistance, gotDistance)
|
||||
return
|
||||
}
|
||||
if gotSimilarity != expectedSimilarity {
|
||||
t.Errorf("Expected to get %f, now got %f", expectedSimilarity, gotSimilarity)
|
||||
return
|
||||
}
|
||||
|
||||
source = "Michael Jordan"
|
||||
target = "Michael Jordan"
|
||||
expectedDistance = 0
|
||||
expectedSimilarity = 1
|
||||
gotDistance, gotSimilarity = Similarity(source, target)
|
||||
if gotDistance != expectedDistance {
|
||||
t.Errorf("Expected to get %d, now got %d", expectedDistance, gotDistance)
|
||||
return
|
||||
}
|
||||
if gotSimilarity != expectedSimilarity {
|
||||
t.Errorf("Expected to get %f, now got %f", expectedSimilarity, gotSimilarity)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package securityUtil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSha1String(t *testing.T) {
|
||||
s := "hello world"
|
||||
result := Sha1String(s, true)
|
||||
if result != "2AAE6C35C94FCFB415DBE95F408B9CE91EE846ED" {
|
||||
t.Errorf("Sha1String(\"hello world\") failed.Got %s, expected %s", result, "2AAE6C35C94FCFB415DBE95F408B9CE91EE846ED")
|
||||
}
|
||||
|
||||
result = Sha1String(s, false)
|
||||
if result != "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed" {
|
||||
t.Errorf("Sha1String(\"hello world\") failed.Got %s, expected %s", result, "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSha1Bytes(t *testing.T) {
|
||||
s := "hello world"
|
||||
b := []byte(s)
|
||||
result := Sha1Bytes(b, true)
|
||||
if result != "2AAE6C35C94FCFB415DBE95F408B9CE91EE846ED" {
|
||||
t.Errorf("Sha1Bytes(\"hello world\") failed.Got %s, expected %s", result, "2AAE6C35C94FCFB415DBE95F408B9CE91EE846ED")
|
||||
}
|
||||
|
||||
result = Sha1Bytes(b, false)
|
||||
if result != "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed" {
|
||||
t.Errorf("Sha1Bytes(\"hello world\") failed.Got %s, expected %s", result, "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user