本文整理汇总了C++中Branch::contains方法的典型用法代码示例。如果您正苦于以下问题:C++ Branch::contains方法的具体用法?C++ Branch::contains怎么用?C++ Branch::contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Branch
的用法示例。
在下文中一共展示了Branch::contains方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_if_elif_else
void test_if_elif_else()
{
Branch branch;
branch.compile("if true { a = 1 } elif true { a = 2 } else { a = 3 } a=a");
evaluate_branch(&branch);
test_assert(branch.contains("a"));
test_equals(branch["a"]->asInt(), 1);
branch.compile(
"if false { b = 'apple' } elif false { b = 'orange' } else { b = 'pineapple' } b=b");
evaluate_branch(&branch);
test_assert(branch.contains("b"));
test_assert(branch["b"]->asString() == "pineapple");
// try one without 'else'
branch.clear();
branch.compile("c = 0");
branch.compile("if false { c = 7 } elif true { c = 8 }; c=c");
evaluate_branch(&branch);
test_assert(branch.contains("c"));
test_assert(branch["c"]->asInt() == 8);
// try with some more complex conditions
branch.clear();
branch.compile("x = 5");
branch.compile("if x > 6 { compare = 1 } elif x < 6 { compare = -1 } else { compare = 0}");
branch.compile("compare=compare");
evaluate_branch(&branch);
test_assert(branch.contains("compare"));
test_assert(branch["compare"]->asInt() == -1);
}
示例2: test_dont_always_rebind_inner_names
void test_dont_always_rebind_inner_names()
{
Branch branch;
branch.compile("if false { b = 1 } elif false { c = 1 } elif false { d = 1 } else { e = 1 }");
evaluate_branch(&branch);
test_assert(!branch.contains("b"));
test_assert(!branch.contains("c"));
test_assert(!branch.contains("d"));
test_assert(!branch.contains("e"));
}
示例3: test_if_joining
void test_if_joining()
{
Branch branch;
// Test that a name defined in one branch is not rebound in outer scope
branch.eval("if true { apple = 5 }");
test_assert(!branch.contains("apple"));
// Test that a name which exists in the outer scope is rebound
Term* original_banana = create_int(&branch, 10, "banana");
branch.eval("if true { banana = 15 }");
test_assert(branch["banana"] != original_banana);
// Test that if a name is defined in both 'if' and 'else' branches, that it gets
// defined in the outer scope.
branch.eval("if true { Cardiff = 5 } else { Cardiff = 11 }");
test_assert(branch.contains("Cardiff"));
// Test that the type of the joined name is correct
branch.compile("if true { a = 4 } else { a = 5 }; a = a");
test_equals(get_output_type(branch["a"])->name, "int");
}