diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-07-28 13:39:30 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-07-28 21:40:40 +0000 |
commit | 53557530093938e19c21f6b02a482939ac6e634b (patch) | |
tree | 18d51aa04629aaad621399e997306118b36a5952 /test/typeparam/sliceimp.dir | |
parent | 473e493d18c277d69e40a4930af045d474ff2be4 (diff) | |
download | go-53557530093938e19c21f6b02a482939ac6e634b.tar.gz go-53557530093938e19c21f6b02a482939ac6e634b.zip |
[dev.typeparams] test/typeparam: gofmt -w
We don't usually reformat the test directory, but all of the files in
test/typeparam are syntactically valid. I suspect the misformattings
here are because developers aren't re-installing gofmt with
-tags=typeparams, not intentionally exercising non-standard
formatting.
Change-Id: I3767d480434c19225568f3c7d656dc8589197183
Reviewed-on: https://go-review.googlesource.com/c/go/+/338093
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'test/typeparam/sliceimp.dir')
-rw-r--r-- | test/typeparam/sliceimp.dir/a.go | 26 | ||||
-rw-r--r-- | test/typeparam/sliceimp.dir/main.go | 64 |
2 files changed, 45 insertions, 45 deletions
diff --git a/test/typeparam/sliceimp.dir/a.go b/test/typeparam/sliceimp.dir/a.go index 61b1b17a98..da12e9f9fc 100644 --- a/test/typeparam/sliceimp.dir/a.go +++ b/test/typeparam/sliceimp.dir/a.go @@ -5,26 +5,26 @@ package a type Ordered interface { - ~int | ~int8 | ~int16 | ~int32 | ~int64 | - ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | - ~float32 | ~float64 | - ~string + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | + ~float32 | ~float64 | + ~string } // Max returns the maximum of two values of some ordered type. func Max[T Ordered](a, b T) T { - if a > b { - return a - } - return b + if a > b { + return a + } + return b } // Min returns the minimum of two values of some ordered type. func Min[T Ordered](a, b T) T { - if a < b { - return a - } - return b + if a < b { + return a + } + return b } // Equal reports whether two slices are equal: the same length and all @@ -121,7 +121,7 @@ func Append[T any](s []T, t ...T) []T { if tot <= cap(s) { s = s[:tot] } else { - news := make([]T, tot, tot + tot/2) + news := make([]T, tot, tot+tot/2) Copy(news, s) s = news } diff --git a/test/typeparam/sliceimp.dir/main.go b/test/typeparam/sliceimp.dir/main.go index 2d4d3b2831..0f79e10018 100644 --- a/test/typeparam/sliceimp.dir/main.go +++ b/test/typeparam/sliceimp.dir/main.go @@ -12,42 +12,42 @@ import ( ) type Integer interface { - ~int | ~int8 | ~int16 | ~int32 | ~int64 | - ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr } func TestEqual() { - s1 := []int{1, 2, 3} - if !a.Equal(s1, s1) { - panic(fmt.Sprintf("a.Equal(%v, %v) = false, want true", s1, s1)) - } - s2 := []int{1, 2, 3} - if !a.Equal(s1, s2) { - panic(fmt.Sprintf("a.Equal(%v, %v) = false, want true", s1, s2)) - } - s2 = append(s2, 4) - if a.Equal(s1, s2) { - panic(fmt.Sprintf("a.Equal(%v, %v) = true, want false", s1, s2)) - } - - s3 := []float64{1, 2, math.NaN()} - if !a.Equal(s3, s3) { - panic(fmt.Sprintf("a.Equal(%v, %v) = false, want true", s3, s3)) - } - - if a.Equal(s1, nil) { - panic(fmt.Sprintf("a.Equal(%v, nil) = true, want false", s1)) - } - if a.Equal(nil, s1) { - panic(fmt.Sprintf("a.Equal(nil, %v) = true, want false", s1)) - } - if !a.Equal(s1[:0], nil) { - panic(fmt.Sprintf("a.Equal(%v, nil = false, want true", s1[:0])) - } + s1 := []int{1, 2, 3} + if !a.Equal(s1, s1) { + panic(fmt.Sprintf("a.Equal(%v, %v) = false, want true", s1, s1)) + } + s2 := []int{1, 2, 3} + if !a.Equal(s1, s2) { + panic(fmt.Sprintf("a.Equal(%v, %v) = false, want true", s1, s2)) + } + s2 = append(s2, 4) + if a.Equal(s1, s2) { + panic(fmt.Sprintf("a.Equal(%v, %v) = true, want false", s1, s2)) + } + + s3 := []float64{1, 2, math.NaN()} + if !a.Equal(s3, s3) { + panic(fmt.Sprintf("a.Equal(%v, %v) = false, want true", s3, s3)) + } + + if a.Equal(s1, nil) { + panic(fmt.Sprintf("a.Equal(%v, nil) = true, want false", s1)) + } + if a.Equal(nil, s1) { + panic(fmt.Sprintf("a.Equal(nil, %v) = true, want false", s1)) + } + if !a.Equal(s1[:0], nil) { + panic(fmt.Sprintf("a.Equal(%v, nil = false, want true", s1[:0])) + } } func offByOne[Elem Integer](a, b Elem) bool { - return a == b + 1 || a == b - 1 + return a == b+1 || a == b-1 } func TestEqualFn() { @@ -92,12 +92,12 @@ func TestMap() { func TestReduce() { s1 := []int{1, 2, 3} - r := a.Reduce(s1, 0, func(f float64, i int) float64 { return float64(i) * 2.5 + f }) + r := a.Reduce(s1, 0, func(f float64, i int) float64 { return float64(i)*2.5 + f }) if want := 15.0; r != want { panic(fmt.Sprintf("a.Reduce(%v, 0, ...) = %v, want %v", s1, r, want)) } - if got := a.Reduce(nil, 0, func(i, j int) int { return i + j}); got != 0 { + if got := a.Reduce(nil, 0, func(i, j int) int { return i + j }); got != 0 { panic(fmt.Sprintf("a.Reduce(nil, 0, add) = %v, want 0", got)) } } |