Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WCCL
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Analysers
WCCL
Commits
87aecbd6
Commit
87aecbd6
authored
14 years ago
by
Adam Wardyński
Browse files
Options
Downloads
Patches
Plain Diff
Adding "Or" logical predicate
parent
a8f79386
Branches
Branches containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
libwccl/CMakeLists.txt
+1
-0
1 addition, 0 deletions
libwccl/CMakeLists.txt
libwccl/ops/or.cpp
+19
-0
19 additions, 0 deletions
libwccl/ops/or.cpp
libwccl/ops/or.h
+36
-0
36 additions, 0 deletions
libwccl/ops/or.h
tests/logicalpredicates.cpp
+84
-0
84 additions, 0 deletions
tests/logicalpredicates.cpp
with
140 additions
and
0 deletions
libwccl/CMakeLists.txt
+
1
−
0
View file @
87aecbd6
...
...
@@ -17,6 +17,7 @@ SET(libwccl_STAT_SRC
exception.cpp
main.cpp
ops/and.cpp
ops/or.cpp
ops/logicalpredicate.cpp
ops/predicate.cpp
sentencecontext.cpp
...
...
This diff is collapsed.
Click to expand it.
libwccl/ops/or.cpp
0 → 100644
+
19
−
0
View file @
87aecbd6
#include
<libwccl/ops/or.h>
namespace
Wccl
{
Or
::
BaseRetValPtr
Or
::
apply_internal
(
const
SentenceContext
&
context
)
const
{
foreach
(
BoolFunctionPtr
expression
,
*
expressions_
)
{
if
(
expression
->
apply
(
context
)
->
get_value
())
{
return
Predicate
::
True
->
apply
(
context
);
}
}
return
Predicate
::
False
->
apply
(
context
);
}
const
std
::
string
Or
::
raw_operator_name
()
const
{
return
"or"
;
}
}
/* end ns Wccl */
This diff is collapsed.
Click to expand it.
libwccl/ops/or.h
0 → 100644
+
36
−
0
View file @
87aecbd6
#ifndef OR_H
#define OR_H
#include
<boost/foreach.hpp>
#define foreach BOOST_FOREACH
#include
<libwccl/ops/logicalpredicate.h>
namespace
Wccl
{
/**
* Operator that realises logical predicate "or"
*/
class
Or
:
public
LogicalPredicate
{
public:
Or
(
const
boost
::
shared_ptr
<
BoolFunctionPtrVector
>&
expressions
)
:
LogicalPredicate
(
expressions
)
{
}
protected
:
typedef
FunctionBase
::
BaseRetValPtr
BaseRetValPtr
;
/**
* "Or" predicate evaluates expressions one by one in order from left to right,
* and True is returned once an expression evaluating to True is found.
* If all of the expressions were False, False is returned.
*/
virtual
BaseRetValPtr
apply_internal
(
const
SentenceContext
&
)
const
;
virtual
const
std
::
string
raw_operator_name
()
const
;
};
}
/* end ns Wccl */
#endif // OR_H
This diff is collapsed.
Click to expand it.
tests/logicalpredicates.cpp
+
84
−
0
View file @
87aecbd6
...
...
@@ -6,6 +6,7 @@
#include
<libwccl/ops/constant.h>
#include
<libwccl/ops/logicalpredicate.h>
#include
<libwccl/ops/and.h>
#include
<libwccl/ops/or.h>
#include
<libwccl/values/bool.h>
#include
<libwccl/sentencecontext.h>
...
...
@@ -50,6 +51,7 @@ BOOST_FIXTURE_TEST_CASE(and_1arg, PredFix)
BOOST_CHECK_EQUAL
(
false
,
pred_and
.
apply
(
sc
)
->
get_value
());
}
BOOST_FIXTURE_TEST_CASE
(
and_2arg
,
PredFix
)
{
for
(
int
arg1
=
0
;
arg1
<
2
;
++
arg1
)
{
...
...
@@ -79,6 +81,49 @@ BOOST_FIXTURE_TEST_CASE(and_3arg, PredFix)
}
}
BOOST_FIXTURE_TEST_CASE
(
or_1arg
,
PredFix
)
{
boost
::
shared_ptr
<
Or
::
BoolFunctionPtrVector
>
v
(
new
Or
::
BoolFunctionPtrVector
());
v
->
push_back
(
true_constant
);
Or
pred_or
(
v
);
BOOST_CHECK_EQUAL
(
true
,
pred_or
.
apply
(
sc
)
->
get_value
());
v
->
clear
();
v
->
push_back
(
false_constant
);
BOOST_CHECK_EQUAL
(
false
,
pred_or
.
apply
(
sc
)
->
get_value
());
}
BOOST_FIXTURE_TEST_CASE
(
or_2arg
,
PredFix
)
{
for
(
int
arg1
=
0
;
arg1
<
2
;
++
arg1
)
{
for
(
int
arg2
=
0
;
arg2
<
2
;
++
arg2
)
{
boost
::
shared_ptr
<
Or
::
BoolFunctionPtrVector
>
v
(
new
Or
::
BoolFunctionPtrVector
());
v
->
push_back
(
arg1
!=
0
?
true_constant
:
false_constant
);
v
->
push_back
(
arg2
!=
0
?
true_constant
:
false_constant
);
Or
pred_or
(
v
);
BOOST_CHECK_EQUAL
((
arg1
!=
0
)
||
(
arg2
!=
0
),
pred_or
.
apply
(
sc
)
->
get_value
());
}
}
}
BOOST_FIXTURE_TEST_CASE
(
or_3arg
,
PredFix
)
{
for
(
int
arg1
=
0
;
arg1
<
2
;
++
arg1
)
{
for
(
int
arg2
=
0
;
arg2
<
2
;
++
arg2
)
{
for
(
int
arg3
=
0
;
arg3
<
2
;
++
arg3
)
{
boost
::
shared_ptr
<
Or
::
BoolFunctionPtrVector
>
v
(
new
Or
::
BoolFunctionPtrVector
());
v
->
push_back
(
arg1
!=
0
?
true_constant
:
false_constant
);
v
->
push_back
(
arg2
!=
0
?
true_constant
:
false_constant
);
v
->
push_back
(
arg3
!=
0
?
true_constant
:
false_constant
);
Or
pred_or
(
v
);
BOOST_CHECK_EQUAL
((
arg1
!=
0
)
||
(
arg2
!=
0
)
||
(
arg3
!=
0
),
pred_or
.
apply
(
sc
)
->
get_value
());
}
}
}
}
//------ to_string test cases -------
BOOST_FIXTURE_TEST_CASE
(
and_to_string
,
PredFix
)
{
boost
::
shared_ptr
<
And
::
BoolFunctionPtrVector
>
v
(
new
And
::
BoolFunctionPtrVector
());
...
...
@@ -117,4 +162,43 @@ BOOST_FIXTURE_TEST_CASE(and_to_raw_string, PredFix)
BOOST_CHECK_EQUAL
(
"and(true, and(false, true, true))"
,
another_and
.
to_raw_string
());
}
BOOST_FIXTURE_TEST_CASE
(
or_to_string
,
PredFix
)
{
boost
::
shared_ptr
<
Or
::
BoolFunctionPtrVector
>
v
(
new
Or
::
BoolFunctionPtrVector
());
v
->
push_back
(
true_constant
);
boost
::
shared_ptr
<
Function
<
Bool
>
>
pred_or
(
new
Or
(
v
));
BOOST_CHECK_EQUAL
(
"or(true)"
,
pred_or
->
to_string
(
tagset
));
v
->
push_back
(
false_constant
);
BOOST_CHECK_EQUAL
(
"or(true, false)"
,
pred_or
->
to_string
(
tagset
));
v
->
push_back
(
true_constant
);
BOOST_CHECK_EQUAL
(
"or(true, false, true)"
,
pred_or
->
to_string
(
tagset
));
boost
::
shared_ptr
<
Or
::
BoolFunctionPtrVector
>
v2
(
new
Or
::
BoolFunctionPtrVector
());
v2
->
push_back
(
pred_or
);
v2
->
push_back
(
false_constant
);
Or
another_or
(
v2
);
BOOST_CHECK_EQUAL
(
"or(or(true, false, true), false)"
,
another_or
.
to_raw_string
());
v2
->
push_back
(
true_constant
);
BOOST_CHECK_EQUAL
(
"or(or(true, false, true), false, true)"
,
another_or
.
to_raw_string
());
}
BOOST_FIXTURE_TEST_CASE
(
or_to_raw_string
,
PredFix
)
{
boost
::
shared_ptr
<
Or
::
BoolFunctionPtrVector
>
v
(
new
Or
::
BoolFunctionPtrVector
());
v
->
push_back
(
false_constant
);
boost
::
shared_ptr
<
Function
<
Bool
>
>
pred_or
(
new
Or
(
v
));
BOOST_CHECK_EQUAL
(
"or(false)"
,
pred_or
->
to_raw_string
());
v
->
push_back
(
true_constant
);
BOOST_CHECK_EQUAL
(
"or(false, true)"
,
pred_or
->
to_raw_string
());
v
->
push_back
(
true_constant
);
BOOST_CHECK_EQUAL
(
"or(false, true, true)"
,
pred_or
->
to_raw_string
());
boost
::
shared_ptr
<
Or
::
BoolFunctionPtrVector
>
v2
(
new
Or
::
BoolFunctionPtrVector
());
v2
->
push_back
(
true_constant
);
v2
->
push_back
(
pred_or
);
Or
another_or
(
v2
);
BOOST_CHECK_EQUAL
(
"or(true, or(false, true, true))"
,
another_or
.
to_raw_string
());
}
BOOST_AUTO_TEST_SUITE_END
()
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment