-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash_test.go
160 lines (109 loc) · 3.17 KB
/
hash_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Copyright (c) 2024 Six After, Inc
//
// This source code is licensed under the Apache 2.0 License found in the
// LICENSE file in the root directory of this source tree.
package graph
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIdentityFunctionForStrings(t *testing.T) {
t.Parallel()
as := assert.New(t)
input := "testVertex"
expectedHash := "testVertex"
hash := StringHash(input)
as.Equal(expectedHash, hash, "StringHash should return the same string as the hash")
}
func TestDifferentStringsReturnDifferentHashes(t *testing.T) {
t.Parallel()
as := assert.New(t)
input1 := "vertex1"
input2 := "vertex2"
hash1 := StringHash(input1)
hash2 := StringHash(input2)
as.NotEqual(hash1, hash2, "Different strings should return different hashes")
}
func TestEmptyStringHash(t *testing.T) {
t.Parallel()
as := assert.New(t)
input := ""
expectedHash := ""
hash := StringHash(input)
as.Equal(expectedHash, hash, "StringHash of an empty string should return an empty string")
}
func TestIdentityFunctionForIntegers(t *testing.T) {
t.Parallel()
as := assert.New(t)
input := 42
expectedHash := 42
hash := IntHash(input)
as.Equal(expectedHash, hash, "IntHash should return the same integer as the hash")
}
func TestDifferentIntegersReturnDifferentHashes(t *testing.T) {
t.Parallel()
as := assert.New(t)
input1 := 1
input2 := 2
hash1 := IntHash(input1)
hash2 := IntHash(input2)
as.NotEqual(hash1, hash2, "Different integers should return different hashes")
}
func TestZeroHash(t *testing.T) {
t.Parallel()
as := assert.New(t)
input := 0
expectedHash := 0
hash := IntHash(input)
as.Equal(expectedHash, hash, "IntHash of zero should return zero")
}
func TestIdentityFunctionForFloat64(t *testing.T) {
t.Parallel()
as := assert.New(t)
input := 42.0
expectedHash := 42.0
hash := Float64Hash(input)
as.Equal(expectedHash, hash, "Float64Hash should return the same float as the hash")
}
func TestDifferentFloat64ReturnDifferentHashes(t *testing.T) {
t.Parallel()
as := assert.New(t)
input1 := 1.0
input2 := 2.0
hash1 := Float64Hash(input1)
hash2 := Float64Hash(input2)
as.NotEqual(hash1, hash2, "Different floats should return different hashes")
}
func TestZeroFloat64Hash(t *testing.T) {
t.Parallel()
as := assert.New(t)
input := 0.0
expectedHash := 0.0
hash := Float64Hash(input)
as.Equal(expectedHash, hash, "Float64Hash of zero should return zero")
}
func TestIdentityFunctionForFloat32(t *testing.T) {
t.Parallel()
as := assert.New(t)
input := float32(42.0)
expectedHash := float32(42.0)
hash := Float32Hash(input)
as.Equal(expectedHash, hash, "Float32Hash should return the same float as the hash")
}
func TestDifferentFloat32ReturnDifferentHashes(t *testing.T) {
t.Parallel()
as := assert.New(t)
input1 := float32(1.0)
input2 := float32(2.0)
hash1 := Float32Hash(input1)
hash2 := Float32Hash(input2)
as.NotEqual(hash1, hash2, "Different floats should return different hashes")
}
func TestZeroFloat32Hash(t *testing.T) {
t.Parallel()
as := assert.New(t)
input := float32(0.0)
expectedHash := float32(0.0)
hash := Float32Hash(input)
as.Equal(expectedHash, hash, "Float32Hash of zero should return zero")
}