github.com/zhongdalu/gf@v1.0.0/g/crypto/gcrc32/gcrc32_test.go (about)

     1  // Copyright 2019 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/zhongdalu/gf.
     6  
     7  // go test *.go -bench=".*"
     8  
     9  package gcrc32_test
    10  
    11  import (
    12  	"testing"
    13  
    14  	"github.com/zhongdalu/gf/g/crypto/gcrc32"
    15  	"github.com/zhongdalu/gf/g/crypto/gmd5"
    16  	"github.com/zhongdalu/gf/g/test/gtest"
    17  )
    18  
    19  func TestEncryptString(t *testing.T) {
    20  	gtest.Case(t, func() {
    21  		s := "pibigstar"
    22  		result := 693191136
    23  		encrypt1 := gcrc32.EncryptString(s)
    24  		encrypt2 := gcrc32.EncryptBytes([]byte(s))
    25  		gtest.AssertEQ(int(encrypt1), result)
    26  		gtest.AssertEQ(int(encrypt2), result)
    27  	})
    28  }
    29  
    30  func TestEncrypt(t *testing.T) {
    31  	gtest.Case(t, func() {
    32  		s := "pibigstar"
    33  		result := 693191136
    34  		encrypt1 := gcrc32.Encrypt(s)
    35  		encrypt2 := gcrc32.Encrypt([]byte(s))
    36  		gtest.AssertEQ(int(encrypt1), result)
    37  		gtest.AssertEQ(int(encrypt2), result)
    38  
    39  		strmd5, _ := gmd5.Encrypt(s)
    40  		test1 := gcrc32.Encrypt(strmd5)
    41  		test2 := gcrc32.Encrypt([]byte(strmd5))
    42  		gtest.AssertEQ(test2, test1)
    43  	})
    44  }