Source file test/typeparam/mapimp.dir/main.go

     1  // Copyright 2021 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"./a"
     9  	"fmt"
    10  	"reflect"
    11  	"strconv"
    12  )
    13  
    14  func main() {
    15  	got := a.Mapper([]int{1, 2, 3}, strconv.Itoa)
    16  	want := []string{"1", "2", "3"}
    17  	if !reflect.DeepEqual(got, want) {
    18  		panic(fmt.Sprintf("got %s, want %s", got, want))
    19  	}
    20  
    21  	fgot := a.Mapper([]float64{2.5, 2.3, 3.5}, func(f float64) string {
    22  		return strconv.FormatFloat(f, 'f', -1, 64)
    23  	})
    24  	fwant := []string{"2.5", "2.3", "3.5"}
    25  	if !reflect.DeepEqual(fgot, fwant) {
    26  		panic(fmt.Sprintf("got %s, want %s", fgot, fwant))
    27  	}
    28  }
    29  

View as plain text