MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / evaluateRandom

Method evaluateRandom

test/test_runner/test_parser.cpp:546–565  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

544}
545
546Value TestParser::evaluateRandom(const std::string& funcCall) {
547 // Extract parameter from random(param)
548 std::string param = funcCall.substr(7, funcCall.length() - 8); // Remove "random(" and ")"
549
550 if (param.empty()) {
551 // random() without parameter - return random integer 0-2^32
552 return Value(randomEngine.nextRandomInteger());
553 }
554 // random(max) - return random integer between 0 and max-1
555 int32_t maxVal = 0;
556 try {
557 maxVal = static_cast<int32_t>(stoi(param));
558 } catch (const std::exception&) {
559 throw TestException("Invalid random parameter [" + path + ":" + line + "].");
560 }
561 if (maxVal == 0) {
562 throw TestException("Random max value must be positive [" + path + ":" + line + "].");
563 }
564 return Value(randomEngine.nextRandomInteger(maxVal));
565}
566
567Value TestParser::evaluateRandomDotFunction(const std::string& funcCall) {
568 // Handle random.set_seed(value) and random.randInt32(max)

Callers

nothing calls this directly

Calls 5

TestExceptionClass · 0.85
lengthMethod · 0.80
nextRandomIntegerMethod · 0.80
ValueClass · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected