github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/pkg/hash/position_inertia_test.go (about)

     1  // Copyright 2020 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package hash
    15  
    16  import (
    17  	"testing"
    18  
    19  	. "github.com/pingcap/check"
    20  )
    21  
    22  func Test(t *testing.T) {
    23  	TestingT(t)
    24  }
    25  
    26  var _ = Suite(&testPositionInertia{})
    27  
    28  type testPositionInertia struct{}
    29  
    30  func (s *testPositionInertia) TestPositionInertia(c *C) {
    31  	hash := NewPositionInertia()
    32  	hash.Write([]byte("hello"), []byte("hash"))
    33  	hash.Write([]byte("hello"), []byte("pingcap"))
    34  	hash.Write([]byte("hello"), []byte("ticdc"))
    35  	hash.Write([]byte("hello"), []byte("tools"))
    36  	c.Assert(hash.Sum32(), Equals, uint32(0x914505a7))
    37  
    38  	hash.Reset()
    39  	hash.Write([]byte("hello"), []byte("pingcap"))
    40  	hash.Write([]byte("hello"), []byte("hash"))
    41  	hash.Write([]byte("hello"), []byte("tools"))
    42  	hash.Write([]byte("hello"), []byte("ticdc"))
    43  	c.Assert(hash.Sum32(), Equals, uint32(0x914505a7))
    44  
    45  	hash.Reset()
    46  	hash.Write([]byte("hello"), []byte("ticdc"))
    47  	hash.Write([]byte("hello"), []byte("hash"))
    48  	hash.Write([]byte("hello"), []byte("tools"))
    49  	hash.Write([]byte("hello"), []byte("pingcap"))
    50  	c.Assert(hash.Sum32(), Equals, uint32(0x914505a7))
    51  
    52  	hash.Reset()
    53  	hash.Write([]byte("ticdc"), []byte("hello"))
    54  	hash.Write([]byte("hello"), []byte("hash"))
    55  	hash.Write([]byte("hello"), []byte("tools"))
    56  	hash.Write([]byte("hello"), []byte("pingcap"))
    57  	c.Assert(hash.Sum32(), Equals, uint32(0xf21b4f40))
    58  
    59  	hash.Reset()
    60  	hash.Write([]byte("ticdc"), []byte("hello"))
    61  	hash.Write([]byte("hello"), []byte("hash"))
    62  	hash.Write([]byte("tools"), []byte("hello"))
    63  	hash.Write([]byte("hello"), []byte("pingcap"))
    64  	c.Assert(hash.Sum32(), Equals, uint32(0x7cd6194a))
    65  }