forked from TheAlgorithms/Go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheaps_test.go
More file actions
31 lines (28 loc) · 1.93 KB
/
Copy pathheaps_test.go
File metadata and controls
31 lines (28 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package permutation
import (
"reflect"
"sort"
"testing"
)
func TestHeaps(t *testing.T) {
t.Run("Should generate permutations for various size sets", func(t *testing.T) {
expectedValues := [][]string{
{"1"},
{"12", "21"},
{"123", "213", "321", "231", "312", "132"},
{"1234", "1243", "1324", "1342", "1423", "1432", "2134", "2143", "2314", "2341", "2413", "2431", "3124", "3142", "3214", "3241", "3412", "3421", "4123", "4132", "4213", "4231", "4312", "4321"},
{"12345", "12354", "12435", "12453", "12534", "12543", "13245", "13254", "13425", "13452", "13524", "13542", "14235", "14253", "14325", "14352", "14523", "14532", "15234", "15243", "15324", "15342", "15423", "15432", "21345", "21354", "21435", "21453", "21534", "21543", "23145", "23154", "23415", "23451", "23514", "23541", "24135", "24153", "24315", "24351", "24513", "24531", "25134", "25143", "25314", "25341", "25413", "25431", "31245", "31254", "31425", "31452", "31524", "31542", "32145", "32154", "32415", "32451", "32514", "32541", "34125", "34152", "34215", "34251", "34512", "34521", "35124", "35142", "35214", "35241", "35412", "35421", "41235", "41253", "41325", "41352", "41523", "41532", "42135", "42153", "42315", "42351", "42513", "42531", "43125", "43152", "43215", "43251", "43512", "43521", "45123", "45132", "45213", "45231", "45312", "45321", "51234", "51243", "51324", "51342", "51423", "51432", "52134", "52143", "52314", "52341", "52413", "52431", "53124", "53142", "53214", "53241", "53412", "53421", "54123", "54132", "54213", "54231", "54312", "54321"},
}
permutationsCh := make(chan []string)
var value []string
for i := 1; i <= 5; i++ {
go Heaps(permutationsCh, i)
value = <-permutationsCh
sort.Strings(value)
sort.Strings(expectedValues[i-1])
if !reflect.DeepEqual(value, expectedValues[i-1]) {
t.Errorf("Permutation set is incorrect for element size of %v. Expected (%v) and received (%v)", i, expectedValues[i-1], value)
}
}
})
}