Page Menu
Home
Xreate
Search
Configure Global Search
Log In
Docs
Questions
Repository
Issues
Patches
Internal API
Files
F4866794
loops.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Sep 13, 8:42 PM
Size
1 KB
Mime Type
text/x-c++
Expires
Tue, Sep 15, 8:42 PM (1 d, 19 h)
Engine
blob
Format
Raw Data
Handle
291456
Attached To
rXR Xreate
loops.cpp
View Options
#include "passmanager.h"
#include "gtest/gtest.h"
using namespace std;
TEST(Loop, Break1){
string code =
R"CODE(
main = function:: int; entry {
input = [0..10]:: [int].
loop fold(input->el::int, 0->a)::[int]
{
if (a>=5)::int {
5:: int; break
} else {a+el}
}
}
)CODE";
xreate::PassManager* man = xreate::PassManager::prepareForCode(move(code));
int (*funcMain)() = (int (*)()) man->run();
int answerActual = funcMain();
ASSERT_EQ(5, answerActual);
}
TEST(Loop, InfiniteLoop1){
string code =
R"Code(
fac = function(x:: int):: int{
range = [2..x] :: [int].
loop fold(range->i::int, 1->acc)::int {
acc * i
}
}
main = function:: int; entry {
loop fold inf(2->state) :: int {
if (fac(state)==120)::int {
state::int; break
} else {state + 1}
}
}
)Code" ;
xreate::PassManager* man = xreate::PassManager::prepareForCode(move(code));
int (*funcMain)() = (int (*)()) man->run();
int answerActual = funcMain();
ASSERT_EQ(5, answerActual);
}
Event Timeline
Log In to Comment