github.com/dbyio/heappermutations@v0.0.0-20210813121318-0ce1fc3634c2/heappermutations_test.go (about)

     1  // Copyright (c) 2021 Nicolas Perraud <np bitbox io>
     2  // Thanks: @yberman
     3  
     4  package heappermutations_test
     5  
     6  import (
     7  	"fmt"
     8  	"github.com/dbyio/heappermutations"
     9  	"testing"
    10  )
    11  
    12  func ExampleInts() {
    13  	s := []int{1, 2, 3}
    14  	perms := heappermutations.Ints(s)
    15  	fmt.Println(perms)
    16  	//Output: [[1 2 3] [2 1 3] [3 1 2] [1 3 2] [2 3 1] [3 2 1]]
    17  }
    18  
    19  func TestStrings(t *testing.T) {
    20  	s := []string{"abc", "def", "ghi", "jkl"}
    21  	perms := heappermutations.Strings(s)
    22  	if len(perms) != 24 { // factorial(len(s)) == 24
    23  		t.Error("Expected 24")
    24  	}
    25  }
    26  
    27  func BenchmarkInts(b *testing.B) {
    28  	s := []int{}
    29  	for i := 0; i < 10; i++ {
    30  		s = append(s, i)
    31  	}
    32  	b.ResetTimer()
    33  	heappermutations.Ints(s)
    34  }