github.com/benoitkugler/goacve@v0.0.0-20201217100549-151ce6e55dc8/server/core/datamodel/sort_test.go (about)

     1  package datamodel
     2  
     3  import (
     4  	"fmt"
     5  	"sort"
     6  	"strconv"
     7  	"testing"
     8  	"time"
     9  
    10  	rd "github.com/benoitkugler/goACVE/server/core/rawdata"
    11  )
    12  
    13  func TestSorter(t *testing.T) {
    14  	base := GetBase(true)
    15  	data := base.RechercheRapidePersonnes(false, "*")
    16  
    17  	h := []rd.Header{
    18  		{Field: PersonneNom},
    19  		{Field: PersonnePrenom},
    20  		{Field: PersonneDateNaissance},
    21  	}
    22  
    23  	ti := time.Now()
    24  	Sort(data, h, 2, true)
    25  	fmt.Println(time.Since(ti))
    26  
    27  	ti = time.Now()
    28  	Sort(data, h, 1, true)
    29  	fmt.Println(time.Since(ti))
    30  
    31  }
    32  
    33  func TestName(t *testing.T) {
    34  	ints, ss := make([]int, 101), make([]string, 101)
    35  	for index := range ints {
    36  		s := fmt.Sprintf("%03d", index)
    37  		i, _ := strconv.Atoi(s)
    38  		ints[index] = i
    39  		ss[index] = s
    40  	}
    41  	otherSlice := ss[:]
    42  	fmt.Println(otherSlice)
    43  	sort.Slice(ss, func(i, j int) bool {
    44  		return ss[i] > ss[j]
    45  	})
    46  	//fmt.Println(ss)
    47  	fmt.Println(otherSlice[1:10])
    48  }
    49  
    50  func TestValueRange(t *testing.T) {
    51  	f := make([]func(), 3)
    52  	for i := range f {
    53  		i := i
    54  		// closure over value of i
    55  		f[i] = func() {
    56  			fmt.Println(i)
    57  		}
    58  	}
    59  	fmt.Println("ValueRange")
    60  	for _, f := range f {
    61  		f()
    62  	}
    63  }
    64  
    65  func TestString(t *testing.T) {
    66  	fmt.Printf("%10d", 5565)
    67  
    68  	fmt.Println(" 100" < "  10")
    69  }