mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-12-04 15:21:05 +01:00
47 lines
681 B
Go
47 lines
681 B
Go
package project
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
type testItem struct {
|
|
Name string
|
|
}
|
|
|
|
func isUnique(items []testItem) bool {
|
|
for i, item := range items {
|
|
for k, other := range items {
|
|
if i == k {
|
|
continue
|
|
}
|
|
|
|
if item.Name == other.Name {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func TestMakeUniqueNames(t *testing.T) {
|
|
items := []testItem{
|
|
{Name: "Project"},
|
|
{Name: "Solution"},
|
|
{Name: "Project"},
|
|
{Name: "Project"},
|
|
{Name: "Project"},
|
|
{Name: "Project"},
|
|
}
|
|
|
|
makeUniqueNames(items, func(item *testItem) string {
|
|
return item.Name
|
|
}, func(item *testItem, name string) {
|
|
item.Name = name
|
|
})
|
|
|
|
if !isUnique(items) {
|
|
t.Fatal("Not unique names")
|
|
}
|
|
}
|