Source file test/typeparam/listimp.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  )
    11  
    12  func main() {
    13  	i3 := &a.List[int]{nil, 1}
    14  	i2 := &a.List[int]{i3, 3}
    15  	i1 := &a.List[int]{i2, 2}
    16  	if got, want := i1.Largest(), 3; got != want {
    17  		panic(fmt.Sprintf("got %d, want %d", got, want))
    18  	}
    19  
    20  	b3 := &a.List[byte]{nil, byte(1)}
    21  	b2 := &a.List[byte]{b3, byte(3)}
    22  	b1 := &a.List[byte]{b2, byte(2)}
    23  	if got, want := b1.Largest(), byte(3); got != want {
    24  		panic(fmt.Sprintf("got %d, want %d", got, want))
    25  	}
    26  
    27  	f3 := &a.List[float64]{nil, 13.5}
    28  	f2 := &a.List[float64]{f3, 1.2}
    29  	f1 := &a.List[float64]{f2, 4.5}
    30  	if got, want := f1.Largest(), 13.5; got != want {
    31  		panic(fmt.Sprintf("got %f, want %f", got, want))
    32  	}
    33  
    34  	s3 := &a.List[string]{nil, "dd"}
    35  	s2 := &a.List[string]{s3, "aa"}
    36  	s1 := &a.List[string]{s2, "bb"}
    37  	if got, want := s1.Largest(), "dd"; got != want {
    38  		panic(fmt.Sprintf("got %s, want %s", got, want))
    39  	}
    40  	j3 := &a.ListNum[int]{nil, 1}
    41  	j2 := &a.ListNum[int]{j3, 32}
    42  	j1 := &a.ListNum[int]{j2, 2}
    43  	if got, want := j1.ClippedLargest(), 2; got != want {
    44  		panic(fmt.Sprintf("got %d, want %d", got, want))
    45  	}
    46  	g3 := &a.ListNum[float64]{nil, 13.5}
    47  	g2 := &a.ListNum[float64]{g3, 1.2}
    48  	g1 := &a.ListNum[float64]{g2, 4.5}
    49  	if got, want := g1.ClippedLargest(), 4.5; got != want {
    50  		panic(fmt.Sprintf("got %f, want %f", got, want))
    51  	}
    52  }
    53  

View as plain text