github.com/emmansun/gmsm@v0.29.1/internal/alias/alias_test.go (about)

     1  package alias
     2  
     3  import "testing"
     4  
     5  var a, b [100]byte
     6  
     7  var aliasingTests = []struct {
     8  	x, y                       []byte
     9  	anyOverlap, inexactOverlap bool
    10  }{
    11  	{a[:], b[:], false, false},
    12  	{a[:], b[:0], false, false},
    13  	{a[:], b[:50], false, false},
    14  	{a[40:50], a[50:60], false, false},
    15  	{a[40:50], a[60:70], false, false},
    16  	{a[:51], a[50:], true, true},
    17  	{a[:], a[:], true, false},
    18  	{a[:50], a[:60], true, false},
    19  	{a[:], nil, false, false},
    20  	{nil, nil, false, false},
    21  	{a[:], a[:0], false, false},
    22  	{a[:10], a[:10:20], true, false},
    23  	{a[:10], a[5:10:20], true, true},
    24  }
    25  
    26  func testAliasing(t *testing.T, i int, x, y []byte, anyOverlap, inexactOverlap bool) {
    27  	any := AnyOverlap(x, y)
    28  	if any != anyOverlap {
    29  		t.Errorf("%d: wrong AnyOverlap result, expected %v, got %v", i, anyOverlap, any)
    30  	}
    31  	inexact := InexactOverlap(x, y)
    32  	if inexact != inexactOverlap {
    33  		t.Errorf("%d: wrong InexactOverlap result, expected %v, got %v", i, inexactOverlap, any)
    34  	}
    35  }
    36  
    37  func TestAliasing(t *testing.T) {
    38  	for i, tt := range aliasingTests {
    39  		testAliasing(t, i, tt.x, tt.y, tt.anyOverlap, tt.inexactOverlap)
    40  		testAliasing(t, i, tt.y, tt.x, tt.anyOverlap, tt.inexactOverlap)
    41  	}
    42  }