github.com/tiagovtristao/plz@v13.4.0+incompatible/src/fs/sort_test.go (about) 1 package fs 2 3 import ( 4 "math/rand" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestSortPathsBasic(t *testing.T) { 11 assert.Equal(t, []string{ 12 "src/fs", 13 "src/fs/test_data/data.txt", 14 "src/fs/hash.go", 15 "src/fs/sort.go", 16 }, SortPaths([]string{ 17 "src/fs/sort.go", 18 "src/fs/hash.go", 19 "src/fs", 20 "src/fs/test_data/data.txt", 21 })) 22 } 23 24 func TestSortPathsBasic2(t *testing.T) { 25 assert.Equal(t, []string{ 26 "common/python/aws/s3.py", 27 "common/python/aws/ses.py", 28 "common/python/async_unblock.py", 29 "common/python/boto.py", 30 }, SortPaths([]string{ 31 "common/python/aws/ses.py", 32 "common/python/aws/s3.py", 33 "common/python/async_unblock.py", 34 "common/python/boto.py", 35 })) 36 } 37 38 func TestSortPaths2(t *testing.T) { 39 for i := 0; i < 100; i++ { 40 assert.Equal(t, []string{ 41 "common/js/Analytics/AppAnalytics.web.js", 42 "common/protos/categories.py", 43 "common/protos/categories_proto.js", 44 "common/python/resources.py", 45 "common/python/so_import.py", 46 "enterprise_platform/proto/users_model_pb_light.js", 47 "infrastructure/dependency_visualiser/JsonFormatter.js", 48 }, SortPaths(shuffle([]string{ 49 "common/python/so_import.py", 50 "common/protos/categories.py", 51 "common/protos/categories_proto.js", 52 "common/python/resources.py", 53 "infrastructure/dependency_visualiser/JsonFormatter.js", 54 "enterprise_platform/proto/users_model_pb_light.js", 55 "common/js/Analytics/AppAnalytics.web.js", 56 }))) 57 } 58 } 59 60 func shuffle(s []string) []string { 61 for i := len(s); i > 0; i-- { 62 j := rand.Intn(i) 63 s[i-1], s[j] = s[j], s[i-1] 64 } 65 return s 66 }