mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-08 06:39:28 +02:00
87 lines
2.8 KiB
Go
87 lines
2.8 KiB
Go
/*
|
|
Copyright © 2024 Philipp Wolfer <phw@uploadedlobster.com>
|
|
|
|
Scotty is free software: you can redistribute it and/or modify it under the
|
|
terms of the GNU General Public License as published by the Free Software
|
|
Foundation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
Scotty is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
Scotty. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package similarity_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"go.uploadedlobster.com/mbtypes"
|
|
"go.uploadedlobster.com/scotty/internal/models"
|
|
"go.uploadedlobster.com/scotty/internal/similarity"
|
|
)
|
|
|
|
func ExampleSimilarity() {
|
|
s := similarity.Similarity("bar1", "bär1")
|
|
fmt.Println(s)
|
|
// Output: 0.75
|
|
}
|
|
|
|
func TestSimilarity(t *testing.T) {
|
|
assert := assert.New(t)
|
|
assert.Equal(1.0, similarity.Similarity("", ""))
|
|
assert.Equal(0.0, similarity.Similarity("foo", ""))
|
|
assert.Equal(0.0, similarity.Similarity("foo", "bar"))
|
|
assert.Equal(0.5, similarity.Similarity("foobar", "bar"))
|
|
assert.Equal(1.0, similarity.Similarity("foo", "foo"))
|
|
assert.Equal(0.6, similarity.Similarity("Forever After", "Forever Failure"))
|
|
}
|
|
|
|
func ExampleNormalizeTitle() {
|
|
s := similarity.NormalizeTitle(" Forever \tFailure (video edit) ")
|
|
fmt.Println(s)
|
|
// Output: forever failure
|
|
}
|
|
|
|
func TestNormalizeTitle(t *testing.T) {
|
|
assert := assert.New(t)
|
|
assert.Equal("forever failure", similarity.NormalizeTitle("Forever Failure"))
|
|
assert.Equal("foo", similarity.NormalizeTitle(" \tfoo\t \t"))
|
|
assert.Equal("wasted years", similarity.NormalizeTitle("Wasted Years - 2015 Remaster"))
|
|
assert.Equal("london calling", similarity.NormalizeTitle("London Calling - Remastered"))
|
|
assert.Equal("london calling", similarity.NormalizeTitle("London Calling (Remastered)"))
|
|
}
|
|
|
|
func ExampleCompareTracks() {
|
|
t1 := models.Track{
|
|
ArtistNames: []string{"Paradise Lost"},
|
|
TrackName: "Forever After",
|
|
}
|
|
t2 := models.Track{
|
|
ArtistNames: []string{"Paradise Lost"},
|
|
TrackName: "Forever Failure (radio edit)",
|
|
ReleaseName: "Draconian Times",
|
|
}
|
|
sim := similarity.CompareTracks(t1, t2)
|
|
fmt.Println(sim)
|
|
// Output: 0.8333333333333334
|
|
}
|
|
|
|
func TestCompareTracksSameMBID(t *testing.T) {
|
|
t1 := models.Track{
|
|
ArtistNames: []string{"Paradise Lost"},
|
|
TrackName: "Forever After",
|
|
RecordingMBID: mbtypes.MBID("2886d15c-09b0-43c6-af56-932f70dde164"),
|
|
}
|
|
t2 := models.Track{
|
|
ArtistNames: []string{"Paradise Lost"},
|
|
TrackName: "Forever Failure (radio edit)",
|
|
ReleaseName: "Draconian Times",
|
|
RecordingMBID: mbtypes.MBID("2886d15c-09b0-43c6-af56-932f70dde164"),
|
|
}
|
|
assert.Equal(t, 1.0, similarity.CompareTracks(t1, t2))
|
|
}
|