Fix test cases
This commit is contained in:
		@@ -564,15 +564,8 @@ func (ps PackageInfoList) UniqByName() (distincted PackageInfoList) {
 | 
			
		||||
	for _, p := range ps {
 | 
			
		||||
		set[p.Name] = p
 | 
			
		||||
	}
 | 
			
		||||
	//sort by key
 | 
			
		||||
	keys := []string{}
 | 
			
		||||
	for key := range set {
 | 
			
		||||
		keys = append(keys, key)
 | 
			
		||||
	}
 | 
			
		||||
	//TODO remove
 | 
			
		||||
	//  sort.Strings(keys)
 | 
			
		||||
	for _, key := range keys {
 | 
			
		||||
		distincted = append(distincted, set[key])
 | 
			
		||||
	for _, v := range set {
 | 
			
		||||
		distincted = append(distincted, v)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -19,6 +19,7 @@ package models
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"reflect"
 | 
			
		||||
	"sort"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/k0kubun/pp"
 | 
			
		||||
@@ -51,8 +52,14 @@ func TestPackageInfoListUniqByName(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	actual := test.in.UniqByName()
 | 
			
		||||
	sort.Slice(actual, func(i, j int) bool {
 | 
			
		||||
		return actual[i].Name < actual[j].Name
 | 
			
		||||
	})
 | 
			
		||||
	sort.Slice(test.out, func(i, j int) bool {
 | 
			
		||||
		return test.out[i].Name < test.out[j].Name
 | 
			
		||||
	})
 | 
			
		||||
	for i, ePack := range test.out {
 | 
			
		||||
		if actual[i].Name == ePack.Name {
 | 
			
		||||
		if actual[i].Name != ePack.Name {
 | 
			
		||||
			t.Errorf("expected %#v, actual %#v", ePack.Name, actual[i].Name)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user