golang.org/x/exp@v0.0.0-20240506185415-9bf2ced13842/trace/order_test.go (about)

     1  // Copyright 2023 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  // Code generated by "gen.bash" from internal/trace/v2; DO NOT EDIT.
     6  
     7  //go:build go1.21
     8  
     9  package trace
    10  
    11  import "testing"
    12  
    13  func TestQueue(t *testing.T) {
    14  	var q queue[int]
    15  	check := func(name string, exp []int) {
    16  		for _, v := range exp {
    17  			q.push(v)
    18  		}
    19  		for i, want := range exp {
    20  			if got, ok := q.pop(); !ok {
    21  				t.Fatalf("check %q: expected to be able to pop after %d pops", name, i+1)
    22  			} else if got != want {
    23  				t.Fatalf("check %q: expected value %d after on pop %d, got %d", name, want, i+1, got)
    24  			}
    25  		}
    26  		if _, ok := q.pop(); ok {
    27  			t.Fatalf("check %q: did not expect to be able to pop more values", name)
    28  		}
    29  		if _, ok := q.pop(); ok {
    30  			t.Fatalf("check %q: did not expect to be able to pop more values a second time", name)
    31  		}
    32  	}
    33  	check("one element", []int{4})
    34  	check("two elements", []int{64, 12})
    35  	check("six elements", []int{55, 16423, 2352, 644, 12874, 9372})
    36  	check("one element again", []int{7})
    37  	check("two elements again", []int{77, 6336})
    38  }