-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit test for model and digest (#2538)
Signed-off-by: MinH-09 <2107139596@qq.com>
- Loading branch information
Showing
3 changed files
with
205 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
/* | ||
* Copyright 2023 The Dragonfly Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_MakeGNNModelName(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
hostname string | ||
ip string | ||
clusterID uint64 | ||
expect func(t *testing.T, s string) | ||
}{ | ||
{ | ||
name: "make gnn model name", | ||
hostname: "foo", | ||
ip: "127.0.0.1", | ||
clusterID: uint64(1), | ||
expect: func(t *testing.T, s string) { | ||
assert := assert.New(t) | ||
assert.Equal(s, "127.0.0.1_foo_1_gnn") | ||
}, | ||
}, | ||
{ | ||
name: "hostname is empty", | ||
hostname: "", | ||
ip: "127.0.0.1", | ||
clusterID: uint64(1), | ||
expect: func(t *testing.T, s string) { | ||
assert := assert.New(t) | ||
assert.Equal(s, "127.0.0.1__1_gnn") | ||
}, | ||
}, | ||
{ | ||
name: "ip is empty", | ||
hostname: "foo", | ||
ip: "", | ||
clusterID: uint64(1), | ||
expect: func(t *testing.T, s string) { | ||
assert := assert.New(t) | ||
assert.Equal(s, "_foo_1_gnn") | ||
}, | ||
}, | ||
{ | ||
name: "hostname and ip are empty", | ||
hostname: "", | ||
ip: "", | ||
clusterID: uint64(1), | ||
expect: func(t *testing.T, s string) { | ||
assert := assert.New(t) | ||
assert.Equal(s, "__1_gnn") | ||
}, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
tc.expect(t, MakeGNNModelName(tc.hostname, tc.ip, tc.clusterID)) | ||
}) | ||
} | ||
} | ||
|
||
func Test_MakeMLPModelName(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
hostname string | ||
ip string | ||
clusterID uint64 | ||
expect func(t *testing.T, s string) | ||
}{ | ||
{ | ||
name: "make mlp model name", | ||
hostname: "foo", | ||
ip: "127.0.0.1", | ||
clusterID: uint64(1), | ||
expect: func(t *testing.T, s string) { | ||
assert := assert.New(t) | ||
assert.Equal(s, "127.0.0.1_foo_1_mlp") | ||
}, | ||
}, | ||
{ | ||
name: "hostname is empty", | ||
hostname: "", | ||
ip: "127.0.0.1", | ||
clusterID: uint64(1), | ||
expect: func(t *testing.T, s string) { | ||
assert := assert.New(t) | ||
assert.Equal(s, "127.0.0.1__1_mlp") | ||
}, | ||
}, | ||
{ | ||
name: "ip is empty", | ||
hostname: "foo", | ||
ip: "", | ||
clusterID: uint64(1), | ||
expect: func(t *testing.T, s string) { | ||
assert := assert.New(t) | ||
assert.Equal(s, "_foo_1_mlp") | ||
}, | ||
}, | ||
{ | ||
name: "hostname and ip are empty", | ||
hostname: "", | ||
ip: "", | ||
clusterID: uint64(1), | ||
expect: func(t *testing.T, s string) { | ||
assert := assert.New(t) | ||
assert.Equal(s, "__1_mlp") | ||
}, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
tc.expect(t, MakeMLPModelName(tc.hostname, tc.ip, tc.clusterID)) | ||
}) | ||
} | ||
} | ||
|
||
func Test_MakeObjectKeyOfModelFile(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
modelName string | ||
version int | ||
expect func(t *testing.T, s string) | ||
}{ | ||
{ | ||
name: "make objectKey of model file", | ||
modelName: "foo", | ||
version: 1, | ||
expect: func(t *testing.T, s string) { | ||
assert := assert.New(t) | ||
assert.Equal(s, "foo/1/model.graphdef") | ||
}, | ||
}, | ||
{ | ||
name: "modelName is empty", | ||
modelName: "", | ||
version: 1, | ||
expect: func(t *testing.T, s string) { | ||
assert := assert.New(t) | ||
assert.Equal(s, "/1/model.graphdef") | ||
}, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
tc.expect(t, MakeObjectKeyOfModelFile(tc.modelName, tc.version)) | ||
}) | ||
} | ||
} | ||
|
||
func Test_MakeObjectKeyOfModelConfigFile(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
modelName string | ||
version int | ||
expect func(t *testing.T, s string) | ||
}{ | ||
{ | ||
name: "make objectKey of model file", | ||
modelName: "foo", | ||
expect: func(t *testing.T, s string) { | ||
assert := assert.New(t) | ||
assert.Equal(s, "foo/config.pbtxt") | ||
}, | ||
}, | ||
{ | ||
name: "modelName is empty", | ||
modelName: "", | ||
expect: func(t *testing.T, s string) { | ||
assert := assert.New(t) | ||
assert.Equal(s, "/config.pbtxt") | ||
}, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
tc.expect(t, MakeObjectKeyOfModelConfigFile(tc.modelName)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters