Skip to content

Commit

Permalink
fix style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
qindazhu committed Apr 24, 2020
1 parent 0078010 commit 34e9088
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
2 changes: 1 addition & 1 deletion k2/csrc/fsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace k2 {

using Label = int32_t;
using StateId = int32_t;
using StateId = std::size_t;
using Weight = float;

enum {
Expand Down
27 changes: 10 additions & 17 deletions k2/csrc/properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,34 @@

// See ../../LICENSE for clarification regarding multiple authors

#include "k2/csrc/properties.h"

#include <unordered_set>

#include "k2/csrc/properties.h"
#include "k2/csrc/fsa.h"

namespace k2 {

bool IsTopSorted(const Fsa &fsa) {
for (auto &arc : fsa.arcs) {
if (arc.dest_state < arc.src_state) {
return false;
}
for (const auto &arc : fsa.arcs) {
if (arc.dest_state < arc.src_state) return false;
}
return true;
}

bool HasSelfLoops(const Fsa &fsa) {
for (auto &arc : fsa.arcs) {
if (arc.dest_state == arc.src_state) {
return true;
}
for (const auto &arc : fsa.arcs) {
if (arc.dest_state == arc.src_state) return true;
}
return false;
}

bool IsDeterministic(const Fsa &fsa) {
std::unordered_set<Label> labels;
StateId state = 0;
for (auto &arc : fsa.arcs) {
for (const auto &arc : fsa.arcs) {
if (arc.src_state == state) {
if (labels.find(arc.label) != labels.end()) {
return false;
}
if (labels.find(arc.label) != labels.end()) return false;
labels.insert(arc.label);
} else {
state = arc.src_state;
Expand All @@ -49,10 +44,8 @@ bool IsDeterministic(const Fsa &fsa) {
}

bool IsEpsilonFree(const Fsa &fsa) {
for (auto &arc : fsa.arcs) {
if (arc.label == kEpsilon) {
return false;
}
for (const auto &arc : fsa.arcs) {
if (arc.label == kEpsilon) return false;
}
return true;
}
Expand Down
26 changes: 13 additions & 13 deletions k2/csrc/properties_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ TEST(Properties, IsTopSorted) {
EXPECT_TRUE(sorted);
}

TEST(Properties, HasNotSelfLoops) {
TEST(Properties, HasNoSelfLoops) {
std::vector<Arc> arcs = {{0, 1, 0}, {0, 2, 0}, {1, 2, 0}, };
std::vector<Range> leaving_arcs = {{0, 2}, {2, 3}, };
Fsa fsa;
fsa.leaving_arcs = leaving_arcs;
fsa.arcs = arcs;
bool hasSelfLoops = HasSelfLoops(fsa);
EXPECT_FALSE(hasSelfLoops);
bool has_self_loops = HasSelfLoops(fsa);
EXPECT_FALSE(has_self_loops);
}

TEST(Properties, HasSelfLoops) {
Expand All @@ -55,8 +55,8 @@ TEST(Properties, HasSelfLoops) {
Fsa fsa;
fsa.leaving_arcs = leaving_arcs;
fsa.arcs = arcs;
bool hasSelfLoops = HasSelfLoops(fsa);
EXPECT_TRUE(hasSelfLoops);
bool has_self_loops = HasSelfLoops(fsa);
EXPECT_TRUE(has_self_loops);
}

TEST(Properties, IsNotDeterministic) {
Expand All @@ -65,8 +65,8 @@ TEST(Properties, IsNotDeterministic) {
Fsa fsa;
fsa.leaving_arcs = leaving_arcs;
fsa.arcs = arcs;
bool isDeterministic = IsDeterministic(fsa);
EXPECT_FALSE(isDeterministic);
bool is_deterministic = IsDeterministic(fsa);
EXPECT_FALSE(is_deterministic);
}

TEST(Properties, IsDeterministic) {
Expand All @@ -75,8 +75,8 @@ TEST(Properties, IsDeterministic) {
Fsa fsa;
fsa.leaving_arcs = leaving_arcs;
fsa.arcs = arcs;
bool isDeterministic = IsDeterministic(fsa);
EXPECT_TRUE(isDeterministic);
bool is_deterministic = IsDeterministic(fsa);
EXPECT_TRUE(is_deterministic);
}

TEST(Properties, IsNotEpsilonFree) {
Expand All @@ -85,8 +85,8 @@ TEST(Properties, IsNotEpsilonFree) {
Fsa fsa;
fsa.leaving_arcs = leaving_arcs;
fsa.arcs = arcs;
bool isEpsilonFree = IsEpsilonFree(fsa);
EXPECT_FALSE(isEpsilonFree);
bool is_epsilon_free = IsEpsilonFree(fsa);
EXPECT_FALSE(is_epsilon_free);
}

TEST(Properties, IsEpsilonFree) {
Expand All @@ -95,6 +95,6 @@ TEST(Properties, IsEpsilonFree) {
Fsa fsa;
fsa.leaving_arcs = leaving_arcs;
fsa.arcs = arcs;
bool isEpsilonFree = IsEpsilonFree(fsa);
EXPECT_TRUE(isEpsilonFree);
bool is_epsilon_free = IsEpsilonFree(fsa);
EXPECT_TRUE(is_epsilon_free);
}

0 comments on commit 34e9088

Please sign in to comment.