github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/p/demo/stack/stack_test.gno (about)

     1  package stack
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestStack(t *testing.T) {
     8  	s := New() // Empty stack
     9  
    10  	if s.Len() != 0 {
    11  		t.Errorf("s.Len(): expected 0; got %d", s.Len())
    12  	}
    13  
    14  	s.Push(1)
    15  
    16  	if s.Len() != 1 {
    17  		t.Errorf("s.Len(): expected 1; got %d", s.Len())
    18  	}
    19  
    20  	if top := s.Top(); top.(int) != 1 {
    21  		t.Errorf("s.Top(): expected 1; got %v", top.(int))
    22  	}
    23  
    24  	if elem := s.Pop(); elem.(int) != 1 {
    25  		t.Errorf("s.Pop(): expected 1; got %v", elem.(int))
    26  	}
    27  	if s.Len() != 0 {
    28  		t.Errorf("s.Len(): expected 0; got %d", s.Len())
    29  	}
    30  }