kaspad/domain/consensus/model/externalapi/hash_clone_equal_test.go
Svarog 05941a76e7
Make DomainHash and TransactionID read-only structs (#1282)
* Increase size of reachability cache

* Change DomainHash to struct with unexported hashArray

* Fixing compilation errors stemming from new DomainHash structure

* Remove obsolete Read/WriteElement methods in appmessage

* Fix all tests

* Fix all tests

* Add comments

* A few renamings

* go mod tidy
2020-12-24 16:15:23 +02:00

80 lines
2.3 KiB
Go

package externalapi
import (
"testing"
)
type testHashToCompare struct {
hash *DomainHash
expectedResult bool
}
type testHashStruct struct {
baseHash *DomainHash
hashesToCompareTo []testHashToCompare
}
func initTestDomainHashForEqual() []*testHashStruct {
tests := []*testHashStruct{
{
baseHash: nil,
hashesToCompareTo: []testHashToCompare{
{
hash: nil,
expectedResult: true,
}, {
hash: NewDomainHashFromByteArray(&[DomainHashSize]byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}),
expectedResult: false,
},
},
}, {
baseHash: NewDomainHashFromByteArray(&[DomainHashSize]byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}),
hashesToCompareTo: []testHashToCompare{
{
hash: nil,
expectedResult: false,
}, {
hash: NewDomainHashFromByteArray(&[DomainHashSize]byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}),
expectedResult: false,
}, {
hash: NewDomainHashFromByteArray(&[DomainHashSize]byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}),
expectedResult: true,
},
},
},
}
return tests
}
func TestDomainHash_Equal(t *testing.T) {
hashTests := initTestDomainHashForEqual()
for i, test := range hashTests {
for j, subTest := range test.hashesToCompareTo {
result1 := test.baseHash.Equal(subTest.hash)
if result1 != subTest.expectedResult {
t.Fatalf("Test #%d:%d: Expected %t but got %t", i, j, subTest.expectedResult, result1)
}
result2 := subTest.hash.Equal(test.baseHash)
if result2 != subTest.expectedResult {
t.Fatalf("Test #%d:%d: Expected %t but got %t", i, j, subTest.expectedResult, result2)
}
}
}
}