souffle  2.0.2-371-g6315b36
Functions
profile_util_test.cpp File Reference
#include "tests/test.h"
#include "souffle/profile/CellInterface.h"
#include "souffle/profile/StringUtils.h"
#include <chrono>
#include <cmath>
#include <iosfwd>
#include <string>
#include <vector>
Include dependency graph for profile_util_test.cpp:

Go to the source code of this file.

Functions

 TEST (StringUtil, cleanJsonOutDouble)
 
 TEST (StringUtil, cleanJsonOutString)
 
 TEST (StringUtil, cleanString)
 
 TEST (StringUtil, formatMemory)
 
 TEST (StringUtil, formatNum)
 
 TEST (StringUtil, formatTime)
 
 TEST (StringUtil, split)
 
 TEST (StringUtil, trimWhitespace)
 

Function Documentation

◆ TEST() [1/8]

TEST ( StringUtil  ,
cleanJsonOutDouble   
)

Definition at line 137 of file profile_util_test.cpp.

137  {
138  EXPECT_EQ("NaN", Tools::cleanJsonOut(NAN));
139  EXPECT_EQ("1.234567e+02", Tools::cleanJsonOut(123.4567));
140 }

References souffle::profile::Tools::cleanJsonOut(), and EXPECT_EQ.

Here is the call graph for this function:

◆ TEST() [2/8]

TEST ( StringUtil  ,
cleanJsonOutString   
)

Definition at line 126 of file profile_util_test.cpp.

126  {
127  EXPECT_EQ("ab", Tools::cleanJsonOut("ab"));
128  EXPECT_EQ("abc", Tools::cleanJsonOut("abc"));
129 
130  EXPECT_EQ("ab", Tools::cleanJsonOut("\"ab\""));
131 
132  EXPECT_EQ("\\\\", Tools::cleanJsonOut("\\"));
133 
134  EXPECT_EQ("\\\"", Tools::cleanJsonOut("\""));
135 }

References souffle::profile::Tools::cleanJsonOut(), and EXPECT_EQ.

Here is the call graph for this function:

◆ TEST() [3/8]

TEST ( StringUtil  ,
cleanString   
)

Definition at line 121 of file profile_util_test.cpp.

121  {
122  EXPECT_EQ(" a b c", Tools::cleanString("\t\n\ta\nb\\nc"));
123  EXPECT_EQ(" a b c", Tools::cleanString("\"\t\n\ta\nb\\nc\""));
124 }

References souffle::profile::Tools::cleanString(), and EXPECT_EQ.

Here is the call graph for this function:

◆ TEST() [4/8]

TEST ( StringUtil  ,
formatMemory   
)

Definition at line 53 of file profile_util_test.cpp.

53  {
54  EXPECT_EQ("0kB", Tools::formatMemory(0));
55  EXPECT_EQ("1kB", Tools::formatMemory(1));
56  EXPECT_EQ("1000kB", Tools::formatMemory(1000));
57  EXPECT_EQ("1900kB", Tools::formatMemory(1900));
58 
59  EXPECT_EQ("2MB", Tools::formatMemory(2 * 1024));
60  EXPECT_EQ("1000MB", Tools::formatMemory(1000 * 1024));
61  EXPECT_EQ("1900MB", Tools::formatMemory(1900 * 1024));
62 
63  EXPECT_EQ("2GB", Tools::formatMemory(2 * 1024 * 1024));
64  EXPECT_EQ("1000GB", Tools::formatMemory(1000 * 1024 * 1024));
65  EXPECT_EQ("1900GB", Tools::formatMemory(1900 * 1024 * 1024));
66 
67  EXPECT_EQ("2TB", Tools::formatMemory(2L * 1024 * 1024 * 1024));
68  EXPECT_EQ("1000TB", Tools::formatMemory(1000L * 1024 * 1024 * 1024));
69  EXPECT_EQ("1900TB", Tools::formatMemory(1900L * 1024 * 1024 * 1024));
70 }

References EXPECT_EQ, and souffle::profile::Tools::formatMemory().

Here is the call graph for this function:

◆ TEST() [5/8]

TEST ( StringUtil  ,
formatNum   
)

Definition at line 30 of file profile_util_test.cpp.

30  {
31  EXPECT_EQ("0", Tools::formatNum(0));
32 
33  EXPECT_EQ("12", Tools::formatNum(12.0));
34  EXPECT_EQ("12.45", Tools::formatNum(12.45));
35 
36  EXPECT_EQ("12", Tools::formatNum(1, 12));
37  EXPECT_EQ("12", Tools::formatNum(2, 12));
38  EXPECT_EQ("123", Tools::formatNum(2, 123));
39  EXPECT_EQ("1.23K", Tools::formatNum(3, 1234));
40 
41  EXPECT_EQ("1.2K", Tools::formatNum(2, 1200));
42  EXPECT_EQ("12K", Tools::formatNum(2, 12345));
43  EXPECT_EQ("100K", Tools::formatNum(1, 123456));
44  EXPECT_EQ("120K", Tools::formatNum(2, 123456));
45  EXPECT_EQ("123K", Tools::formatNum(3, 123456));
46  EXPECT_EQ("1.2B", Tools::formatNum(2, 1234560000));
47  EXPECT_EQ("1.23B", Tools::formatNum(3, 1234560000));
48  EXPECT_EQ("1.234B", Tools::formatNum(4, 1234560000));
49  EXPECT_EQ("1.2t", Tools::formatNum(2, 1234560000000));
50  EXPECT_EQ("1.23q", Tools::formatNum(3, 1234560000000000));
51 }

References EXPECT_EQ, and souffle::profile::Tools::formatNum().

Here is the call graph for this function:

◆ TEST() [6/8]

TEST ( StringUtil  ,
formatTime   
)

Definition at line 72 of file profile_util_test.cpp.

72  {
73  std::chrono::microseconds time{0};
74  EXPECT_EQ(".000s", Tools::formatTime(time));
75  time = std::chrono::microseconds(1);
76  EXPECT_EQ(".000s", Tools::formatTime(time));
77  time = std::chrono::microseconds(1000);
78  EXPECT_EQ(".001s", Tools::formatTime(time));
79  time = std::chrono::microseconds(12340);
80  EXPECT_EQ(".012s", Tools::formatTime(time));
81  time = std::chrono::microseconds(123400);
82  EXPECT_EQ(".123s", Tools::formatTime(time));
83  time = std::chrono::microseconds(1234000);
84  EXPECT_EQ("1.23s", Tools::formatTime(time));
85  time = std::chrono::microseconds(12340000);
87 
88  time = std::chrono::microseconds(123400000);
90 
91  time = std::chrono::hours(25);
93 
94  time = std::chrono::hours(25 * 24);
96 }

References EXPECT_EQ, souffle::profile::Tools::formatTime(), and souffle::test::time().

Here is the call graph for this function:

◆ TEST() [7/8]

TEST ( StringUtil  ,
split   
)

Definition at line 98 of file profile_util_test.cpp.

98  {
99  std::vector<std::string> expected{"a", "b", "c"};
100  EXPECT_EQ(expected, Tools::split("a b c", " "));
101  EXPECT_EQ(expected, Tools::split("a,b,c", ","));
102  EXPECT_EQ(expected, Tools::split("aTESTbTESTc", "TEST"));
103 
104  expected = {"", "a", "b", "c", ""};
105  EXPECT_EQ(expected, Tools::split(" a b c ", " "));
106  EXPECT_EQ(expected, Tools::split("TESTTESTaTESTbTESTcTESTTEST", "TEST"));
107 
108  expected = {"a", "b", "", "c"};
109  EXPECT_EQ(expected, Tools::split(" a b c ", " "));
110  EXPECT_EQ(expected, Tools::split("TESTaTESTbTESTTESTcTEST", "TEST"));
111 }

References EXPECT_EQ, and souffle::profile::Tools::split().

Here is the call graph for this function:

◆ TEST() [8/8]

TEST ( StringUtil  ,
trimWhitespace   
)

Definition at line 113 of file profile_util_test.cpp.

113  {
114  EXPECT_EQ("a b c", Tools::trimWhitespace("\t \t a b c"));
115  EXPECT_EQ("a b c", Tools::trimWhitespace("\t \t a b c\t\t\t"));
116  EXPECT_EQ("a b c", Tools::trimWhitespace("\t \t a b c\t \t\t "));
117  EXPECT_EQ("a b c", Tools::trimWhitespace("\t \t a b c "));
118  EXPECT_EQ("a b c", Tools::trimWhitespace(" a b c "));
119 }

References EXPECT_EQ, and souffle::profile::Tools::trimWhitespace().

Here is the call graph for this function:
souffle::profile::Tools::cleanString
std::string cleanString(std::string val)
Remove and \t characters, and \t sequence of two chars, and wrapping quotes.
Definition: StringUtils.h:206
souffle::profile::Tools::trimWhitespace
std::string trimWhitespace(std::string str)
Definition: StringUtils.h:182
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: test.h:191
souffle::profile::Tools::formatMemory
std::string formatMemory(uint64_t kbytes)
Definition: StringUtils.h:97
souffle::profile::Tools::formatNum
std::string formatNum(double amount)
Definition: StringUtils.h:40
souffle::profile::Tools::cleanJsonOut
std::string cleanJsonOut(std::string value)
escape escapes and quotes, and remove surrounding quotes
Definition: StringUtils.h:232
souffle::profile::Tools::split
std::vector< std::string > split(std::string toSplit, std::string delimiter)
split on the delimiter
Definition: StringUtils.h:162
souffle::profile::Tools::formatTime
std::string formatTime(std::chrono::microseconds number)
Definition: StringUtils.h:108
souffle::test::time
long time(const std::string &name, const Op &operation)
Definition: btree_multiset_test.cpp:411