github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/trie/node_test.go (about)

     1  // This file is part of the go-sberex library. The go-sberex library is 
     2  // free software: you can redistribute it and/or modify it under the terms 
     3  // of the GNU Lesser General Public License as published by the Free 
     4  // Software Foundation, either version 3 of the License, or (at your option)
     5  // any later version.
     6  //
     7  // The go-sberex library is distributed in the hope that it will be useful, 
     8  // but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 
    10  // General Public License <http://www.gnu.org/licenses/> for more details.
    11  
    12  package trie
    13  
    14  import "testing"
    15  
    16  func TestCanUnload(t *testing.T) {
    17  	tests := []struct {
    18  		flag                 nodeFlag
    19  		cachegen, cachelimit uint16
    20  		want                 bool
    21  	}{
    22  		{
    23  			flag: nodeFlag{dirty: true, gen: 0},
    24  			want: false,
    25  		},
    26  		{
    27  			flag:     nodeFlag{dirty: false, gen: 0},
    28  			cachegen: 0, cachelimit: 0,
    29  			want: true,
    30  		},
    31  		{
    32  			flag:     nodeFlag{dirty: false, gen: 65534},
    33  			cachegen: 65535, cachelimit: 1,
    34  			want: true,
    35  		},
    36  		{
    37  			flag:     nodeFlag{dirty: false, gen: 65534},
    38  			cachegen: 0, cachelimit: 1,
    39  			want: true,
    40  		},
    41  		{
    42  			flag:     nodeFlag{dirty: false, gen: 1},
    43  			cachegen: 65535, cachelimit: 1,
    44  			want: true,
    45  		},
    46  	}
    47  
    48  	for _, test := range tests {
    49  		if got := test.flag.canUnload(test.cachegen, test.cachelimit); got != test.want {
    50  			t.Errorf("%+v\n   got %t, want %t", test, got, test.want)
    51  		}
    52  	}
    53  }