Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions openfst/extensions/categorial/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ cc_test(
size = "large",
srcs = ["weight_test.cc"],
linkstatic = True,
shard_count = 3,
deps = [
":categorial-weight",
"//openfst/lib:weight",
Expand Down
47 changes: 27 additions & 20 deletions openfst/extensions/categorial/weight_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "openfst/lib/weight.h"

#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <ostream>
Expand All @@ -30,36 +31,42 @@
#include "openfst/extensions/categorial/categorial-weight.h"
#include "openfst/test/weight-tester.h"

ABSL_FLAG(int, seed, -1, "Random seed.");
ABSL_FLAG(int, repeat, 10000, "Number of test repetitions.");
ABSL_FLAG(uint64_t, seed, 403, "Random seed.");
ABSL_FLAG(int32_t, repeat, 10000, "Number of test repetitions.");

namespace fst {

template <>
struct WeightTestTraits<CategorialWeight<int>> {
static WeightGenerate<CategorialWeight<int>> Generator(uint64_t seed) {
return WeightGenerate<CategorialWeight<int>>();
}
static bool IoRequiresParens() { return false; }
};

template <>
struct WeightTestTraits<CategorialWeight<int, CategoryType::RIGHT>> {
static WeightGenerate<CategorialWeight<int, CategoryType::RIGHT>> Generator(
uint64_t seed) {
return WeightGenerate<CategorialWeight<int, CategoryType::RIGHT>>();
}
static bool IoRequiresParens() { return false; }
};

namespace {

TEST(CategorialWeight, LeftTest) {
WeightGenerate<CategorialWeight<int>> left_category_generate;
WeightTester<CategorialWeight<int>> left_category_tester(
left_category_generate);
left_category_tester.Test(absl::GetFlag(FLAGS_repeat));
std::cout << "PASS left categorial test" << std::endl;
}
using CategorialWeightTypes =
::testing::Types<CategorialWeight<int>,
CategorialWeight<int, CategoryType::RIGHT>>;

TEST(CategorialWeight, RightTest) {
WeightGenerate<CategorialWeight<int, CategoryType::RIGHT>>
right_category_generate;
WeightTester<CategorialWeight<int, CategoryType::RIGHT>>
right_category_tester(right_category_generate);
right_category_tester.Test(absl::GetFlag(FLAGS_repeat));
std::cout << "PASS right categorial test" << std::endl;
}
INSTANTIATE_TYPED_TEST_SUITE_P(Categorial, WeightTest, CategorialWeightTypes, );

} // namespace
} // namespace fst

int main(int argc, char **argv) {
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
int seed = absl::GetFlag(FLAGS_seed) >= 0 ? absl::GetFlag(FLAGS_seed)
: time(nullptr);
int seed = absl::GetFlag(FLAGS_seed);
std::srand(seed);
LOG(INFO) << "Seed = " << absl::GetFlag(FLAGS_seed);
return RUN_ALL_TESTS();
Expand Down
3 changes: 3 additions & 0 deletions openfst/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ cc_library(
hdrs = ["weight-tester.h"],
deps = [
"//openfst/lib:weight",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/log",
"@com_google_googletest//:gtest",
],
Expand Down Expand Up @@ -1463,6 +1464,7 @@ cc_test(
":test_main",
":weight_tester",
"//openfst/lib:weight",
"@com_google_absl//absl/flags:flag",
"@com_google_googletest//:gtest",
],
)
Expand Down Expand Up @@ -2359,6 +2361,7 @@ cc_test(
size = "large",
srcs = ["weight_test.cc"],
linkstatic = True,
shard_count = 4,
deps = [
":weight_tester",
"//openfst/lib:weight",
Expand Down
19 changes: 4 additions & 15 deletions openfst/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,10 @@ foreach(TEST_NAME ${TESTS})
)
endif()

# TODO: Make these use GUnit TEST() instead of a custom RunTest(),
# then use gtest_discover_tests.
if(TEST_NAME STREQUAL "weight_test")
add_test(
NAME ${TEST_NAME}
COMMAND ${TEST_NAME}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
)
else()
gtest_discover_tests(
${TEST_NAME}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
)
endif()

gtest_discover_tests(
${TEST_NAME}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
)
endforeach()

# algo_test variants
Expand Down
19 changes: 5 additions & 14 deletions openfst/test/power-weight_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/flags/flag.h"
#include "openfst/lib/float-weight.h"
#include "openfst/lib/sparse-power-weight.h"
#include "openfst/lib/weight.h"
#include "openfst/test/power-weight-util.h"
#include "openfst/test/weight-tester.h"

ABSL_FLAG(uint64_t, seed, 403, "random seed");
ABSL_FLAG(int32_t, repeat, 2000, "number of test repetitions");

namespace fst {
namespace {

Expand All @@ -40,20 +44,7 @@ using PowerWeightTypes =
testing::Types<SparsePowerWeight<TropicalWeight, int32_t>,
PowerWeight<TropicalWeight, 6>>;

template <typename PowerWeightT>
class GeneratePowerWeightTest : public testing::Test {
public:
using Weight = PowerWeightT;
};
TYPED_TEST_SUITE(GeneratePowerWeightTest, PowerWeightTypes);

TYPED_TEST(GeneratePowerWeightTest, WeightTester) {
using Weight = typename TestFixture::Weight;
using Generator = WeightGenerate<Weight>;
using WeightTester = WeightTester<Weight>;
WeightTester tester((Generator()));
tester.Test(2000 /* iterations */);
}
INSTANTIATE_TYPED_TEST_SUITE_P(Power, WeightTest, PowerWeightTypes, );

template <typename PowerWeightT>
class GetPowerWeightComponentTest : public testing::Test {
Expand Down
Loading
Loading