Skip to content

Commit a84d5c9

Browse files
authored
improve coverage rate (antgroup#330)
- improve coverage on brute force - remove unused function - add parameter ToJson test Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
1 parent a50b341 commit a84d5c9

14 files changed

+286
-44
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
// Copyright 2024-present the vsag project
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#include "memory_block_io_parameter.h"
17+
18+
#include <catch2/catch_test_macros.hpp>
19+
20+
#include "parameter_test.h"
21+
22+
using namespace vsag;
23+
24+
TEST_CASE("memory_block_io_parameter", "[ut][memory_block_io]") {
25+
std::string param_str = "{}";
26+
auto param = std::make_shared<MemoryBlockIOParameter>();
27+
param->FromJson(param_str);
28+
ParameterTest::TestToJson(param);
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
// Copyright 2024-present the vsag project
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#include "memory_io_parameter.h"
17+
18+
#include <catch2/catch_test_macros.hpp>
19+
20+
#include "parameter_test.h"
21+
22+
using namespace vsag;
23+
24+
TEST_CASE("memory_io_parameter", "[ut][memory_io]") {
25+
std::string param_str = "{}";
26+
auto param = std::make_shared<MemoryIOParameter>();
27+
param->FromJson(param_str);
28+
ParameterTest::TestToJson(param);
29+
}

src/parameter_test.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
// Copyright 2024-present the vsag project
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#pragma once
17+
18+
#include <catch2/catch_test_macros.hpp>
19+
20+
#include "parameter.h"
21+
22+
namespace vsag {
23+
class ParameterTest {
24+
public:
25+
static void
26+
TestToJson(const ParamPtr& param) {
27+
auto json1 = param->ToJson();
28+
auto str1 = param->ToString();
29+
param->FromJson(json1);
30+
REQUIRE(param->ToString() == str1);
31+
}
32+
};
33+
} // namespace vsag
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
// Copyright 2024-present the vsag project
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#include "fp32_quantizer_parameter.h"
17+
18+
#include <catch2/catch_test_macros.hpp>
19+
20+
#include "parameter_test.h"
21+
22+
using namespace vsag;
23+
24+
TEST_CASE("fp32_quantizer_parameter", "[ut][fp32_quantizer_parameter]") {
25+
std::string param_str = "{}";
26+
auto param = std::make_shared<FP32QuantizerParameter>();
27+
param->FromJson(param_str);
28+
ParameterTest::TestToJson(param);
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
// Copyright 2024-present the vsag project
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#include "sq4_quantizer_parameter.h"
17+
18+
#include <catch2/catch_test_macros.hpp>
19+
20+
#include "parameter_test.h"
21+
22+
using namespace vsag;
23+
24+
TEST_CASE("sq4_quantizer_parameter", "[ut][sq4_quantizer_parameter]") {
25+
std::string param_str = "{}";
26+
auto param = std::make_shared<SQ4QuantizerParameter>();
27+
param->FromJson(param_str);
28+
ParameterTest::TestToJson(param);
29+
}

src/quantization/scalar_quantization/sq4_uniform_quantizer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ SQ4UniformQuantizer<metric>::ProcessQueryImpl(const DataType* query,
289289
computer.buf_ = reinterpret_cast<uint8_t*>(this->allocator_->Allocate(this->code_size_));
290290
this->EncodeOneImpl(query, computer.buf_);
291291
} catch (const std::bad_alloc& e) {
292-
computer.buf_ = nullptr;
293292
logger::error("bad alloc when init computer buf");
294293
throw std::bad_alloc();
295294
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
// Copyright 2024-present the vsag project
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#include "sq4_uniform_quantizer_parameter.h"
17+
18+
#include <catch2/catch_test_macros.hpp>
19+
20+
#include "parameter_test.h"
21+
22+
using namespace vsag;
23+
24+
TEST_CASE("sq4_uniform_quantizer_parameter", "[ut][sq4_uniform_quantizer_parameter]") {
25+
std::string param_str = "{}";
26+
auto param = std::make_shared<SQ4UniformQuantizerParameter>();
27+
param->FromJson(param_str);
28+
ParameterTest::TestToJson(param);
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
// Copyright 2024-present the vsag project
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#include "sq8_quantizer_parameter.h"
17+
18+
#include <catch2/catch_test_macros.hpp>
19+
20+
#include "parameter_test.h"
21+
22+
using namespace vsag;
23+
24+
TEST_CASE("sq8_quantizer_parameter", "[ut][sq8_quantizer_parameter]") {
25+
std::string param_str = "{}";
26+
auto param = std::make_shared<SQ8QuantizerParameter>();
27+
param->FromJson(param_str);
28+
ParameterTest::TestToJson(param);
29+
}

src/quantization/scalar_quantization/sq8_uniform_quantizer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ SQ8UniformQuantizer<metric>::ProcessQueryImpl(const DataType* query,
266266
computer.buf_ = reinterpret_cast<uint8_t*>(this->allocator_->Allocate(this->code_size_));
267267
this->EncodeOneImpl(query, computer.buf_);
268268
} catch (const std::bad_alloc& e) {
269-
computer.buf_ = nullptr;
270269
logger::error("bad alloc when init computer buf");
271270
throw std::bad_alloc();
272271
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
// Copyright 2024-present the vsag project
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#include "sq8_uniform_quantizer_parameter.h"
17+
18+
#include <catch2/catch_test_macros.hpp>
19+
20+
#include "parameter_test.h"
21+
22+
using namespace vsag;
23+
24+
TEST_CASE("sq8_uniform_quantizer_parameter", "[ut][sq8_uniform_quantizer_parameter]") {
25+
std::string param_str = "{}";
26+
auto param = std::make_shared<SQ8UniformQuantizerParameter>();
27+
param->FromJson(param_str);
28+
ParameterTest::TestToJson(param);
29+
}

0 commit comments

Comments
 (0)