github.com/datastax/go-cassandra-native-protocol@v0.0.0-20220706104457-5e8aad05cf90/crc/crc24_test.go (about) 1 // Copyright 2021 DataStax 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 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package crc 16 17 import ( 18 "fmt" 19 "testing" 20 ) 21 22 func TestChecksumKoopman(t *testing.T) { 23 tests := []struct { 24 data uint64 25 len int 26 want uint32 27 }{ 28 // zero data 29 {0, 0, 8867936}, 30 {0, 1, 59277}, 31 {0, 3, 8251255}, 32 {0, 5, 11185162}, 33 {0, 8, 9640737}, 34 // data = Long.MaxValue 35 {9223372036854775807, 0, 8867936}, 36 {9223372036854775807, 1, 1294145}, 37 {9223372036854775807, 3, 8029951}, 38 {9223372036854775807, 5, 9326200}, 39 {9223372036854775807, 8, 5032370}, 40 // random data 41 {131077, 3, 10131737}, 42 {17181442053, 5, 3672222}, 43 {34359607301, 5, 14445742}, 44 } 45 for _, tt := range tests { 46 t.Run(fmt.Sprintf("data %v len %v", tt.data, tt.len), func(t *testing.T) { 47 if got := ChecksumKoopman(tt.data, tt.len); got != tt.want { 48 t.Errorf("ChecksumKoopman() = %v, want %v", got, tt.want) 49 } 50 }) 51 } 52 }