Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rnd any tests #183

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 3 additions & 4 deletions testlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -3578,13 +3578,12 @@ static inline long long stringToLongLong(InStream &in, const char *buffer) {

bool minus = false;
size_t length = strlen(buffer);
if (length == 0 || length > 20)
in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str());

if (length > 1 && buffer[0] == '-')
minus = true;

if (length > 20)
in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str());

long long retval = 0LL;

int zeroes = 0;
Expand Down Expand Up @@ -5418,7 +5417,7 @@ T optValueToIntegral(const std::string &s_, bool nonnegative) {
for (size_t i = pos; i < s.length(); i++) {
if (s[i] < '0' || s[i] > '9')
__testlib_fail("Opts: expected integer but '" + compress(s_) + "' found");
value = value * 10 + s[i] - '0';
value = T(value * 10 + s[i] - '0');
about = about * 10 + s[i] - '0';
}
value *= sign;
Expand Down
3 changes: 3 additions & 0 deletions tests/test-003_run-rnd/refs/r1/stdout
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ vutwaahqooeqoxzxwetlpecqiwgdbogiqqulttysyohwhzxzphvsfmnplizxoebzcvvfyppqbhxjksuz
1880
1973
1850
2916
1444
g
3 changes: 3 additions & 0 deletions tests/test-003_run-rnd/refs/r2/stdout
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,6 @@ clizwkchataumicxkohcrpqnyrjyzbjvsypznpembvkkkbyzvzckcmhbjbuopfbwbkntswhwsdfzabjg
1363
1897
1175
8281
6084
a
7 changes: 7 additions & 0 deletions tests/test-003_run-rnd/src/gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,11 @@ int main(int argc, char* argv[])
std::cout << rnd.wnext((signed long long) 42, (signed long long) 2011, 4) << std::endl;
std::cout << rnd.wnext((signed int) 42, (signed int) 2011, 4) << std::endl;
std::cout << rnd.wnext((signed short) 42, (signed short) 2011, 4) << std::endl;

println(rnd.wany(a, 1));
println(rnd.wany(a, -1));

set<string> b;
b.insert("a"); b.insert("b"); b.insert("c"); b.insert("d"); b.insert("e"); b.insert("f"); b.insert("g");
println(rnd.any(b));
}
12 changes: 12 additions & 0 deletions tests/test-004_use-test.h/refs/r1/stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ FAIL Token parameter [name=n] equals to "abacab", doesn't correspond to pattern
FAIL Token parameter [name=n] equals to "abacabaa", doesn't correspond to pattern "a|test|abacaba|ok|abac" (based on )
FAIL Token parameter [name=n] equals to "abacaba!", doesn't correspond to pattern "a|test|abacaba|ok|abac" (based on )
FAIL Integer element a[4] equals to 4, violates the range [1, 3] (based on )
FAIL Expected integer, but "" found ()
FAIL Expected integer, but "-" found ()
FAIL Expected integer, but "+" found ()
FAIL Expected integer, but "00" found ()
FAIL Expected integer, but "0123" found ()
FAIL Expected integer, but "+123" found ()
FAIL Expected integer, but "9223372036854775808" found ()
FAIL Expected integer, but "-9223372036854775809" found ()
FAIL Expected integer, but "1 " found ()
FAIL Expected integer, but " 1" found ()
FAIL Expected integer, but "1 2" found ()
FAIL Expected integer, but "-0" found ()
3 changes: 2 additions & 1 deletion tests/test-004_use-test.h/refs/r1/stdout
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ Running test 'tokenize'
Running test 'opts' OK
Running test 'instream' OK
Running test 'pattern' OK
Running test 'stringToLongLong' OK

SUCCESS 6 tests passed.
SUCCESS 7 tests passed.
1 change: 1 addition & 0 deletions tests/test-004_use-test.h/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using namespace std;
#include "tests/test-opts.cpp"
#include "tests/test-instream.cpp"
#include "tests/test-pattern.cpp"
#include "tests/test-stringToLongLong.cpp"

int main() {
disableFinalizeGuard();
Expand Down
2 changes: 1 addition & 1 deletion tests/test-004_use-test.h/tests/test-opts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TEST(opts) {
for (size_t i = 0; i < parts.size(); ++i) {
opts[i + 1] = parts[i].c_str();
}
prepareOpts(opts.size(), (char**)opts.data());
prepareOpts(int(opts.size()), (char**)opts.data());
}
{
GenArrayOpts res;
Expand Down
19 changes: 19 additions & 0 deletions tests/test-004_use-test.h/tests/test-stringToLongLong.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
TEST(stringToLongLong) {
ensure(stringToLongLong(inf, "123") == 123LL);
ensure(stringToLongLong(inf, "-123") == -123LL);
ensure(stringToLongLong(inf, "0") == 0LL);
ensure(stringToLongLong(inf, "9223372036854775807") == 9223372036854775807LL);
ensure(stringToLongLong(inf, "-9223372036854775808") == -9223372036854775807LL - 1LL);
ensure_exit(3, [](){stringToLongLong(inf, "");});
ensure_exit(3, [](){stringToLongLong(inf, "-");});
ensure_exit(3, [](){stringToLongLong(inf, "+");});
ensure_exit(3, [](){stringToLongLong(inf, "00");});
ensure_exit(3, [](){stringToLongLong(inf, "0123");});
ensure_exit(3, [](){stringToLongLong(inf, "+123");});
ensure_exit(3, [](){stringToLongLong(inf, "9223372036854775808");});
ensure_exit(3, [](){stringToLongLong(inf, "-9223372036854775809");});
ensure_exit(3, [](){stringToLongLong(inf, "1 ");});
ensure_exit(3, [](){stringToLongLong(inf, " 1");});
ensure_exit(3, [](){stringToLongLong(inf, "1 2");});
ensure_exit(3, [](){stringToLongLong(inf, "-0");});
}
Loading