Skip to content

Commit

Permalink
Migrate ReasoningIT to BDD (#81)
Browse files Browse the repository at this point in the history
## What is the goal of this PR?

To identify and de-duplicate integration tests that test the fundamentals of Reasoner, categorise them appropriately and migrate them to BDD scenarios.

This PR focuses on ReasoningIT in grakn.

This PR forms part of the work towards typedb/typedb#5721

## What are the changes implemented in this PR?

Added tests that were migrated from the relevant IT files in grakn. Also moved some tests around, so that everything is in the right place.
  • Loading branch information
Alex Walker authored Jul 28, 2020
1 parent f1feb1a commit 39f044e
Show file tree
Hide file tree
Showing 18 changed files with 2,361 additions and 260 deletions.
1 change: 1 addition & 0 deletions behaviour/graql/language/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ exports_files([
"get.feature",
"insert.feature",
"match.feature",
"rule-validation.feature",
"undefine.feature",
])
4 changes: 3 additions & 1 deletion behaviour/graql/language/define.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,8 @@ Feature: Graql Define Query
# RULES #
#########

# Note: These tests verify only the ability to create rules, and are not concerned with their application.

Scenario: a rule can infer both an attribute and its ownership
Given graql define
"""
Expand Down Expand Up @@ -1281,7 +1283,7 @@ Feature: Graql Define Query
| RUL |


Scenario: a rule can infer a relation
Scenario: when defining a rule using `sub rule`, the rule is successfully created
Given graql define
"""
define
Expand Down
37 changes: 37 additions & 0 deletions behaviour/graql/language/insert.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,43 @@ Feature: Graql Insert Query
| MIC | TAR |


Scenario: match-insert can take an attribute's value and copy it to an attribute of a different type
Given graql define
"""
define
height sub attribute, value long;
person has height;
"""
Given graql insert
"""
insert
$x isa person, has name "Susie", has age 16, has ref 0;
$y isa person, has name "Donald", has age 25, has ref 1;
$z isa person, has name "Ralph", has age 18, has ref 2;
"""
Given the integrity is validated
Given graql insert
"""
match
$x isa person, has age 16;
insert
$x has height 16;
"""
Given the integrity is validated
When get answers of graql query
"""
match
$x has height $z;
get $x;
"""
And concept identifiers are
| | check | value |
| SUS | key | ref:0 |
Then uniquely identify answer concepts
| x |
| SUS |


Scenario: if match-insert matches nothing, then nothing is inserted
Given graql define
"""
Expand Down
102 changes: 100 additions & 2 deletions behaviour/graql/language/match.feature
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,75 @@ Feature: Graql Match Clause
| REF0 | REF1 |


Scenario: relations between distinct concepts are not retrieved when matching concepts that relate to themselves
Given graql insert
"""
insert
$x isa person, has ref 1;
$y isa person, has ref 2;
(friend: $x, friend: $y) isa friendship, has ref 0;
"""
Given the integrity is validated
When get answers of graql query
"""
match (friend: $x, friend: $x) isa friendship; get;
"""
Then answer size is: 0


Scenario: matching a chain of relations only returns answers if there is a chain of the required length
Given graql define
"""
define
gift-delivery sub relation,
relates sender,
relates recipient;
person plays sender,
plays recipient;
"""
Given the integrity is validated
Given graql insert
"""
insert
$x1 isa person, has name "Soroush", has ref 0;
$x2a isa person, has name "Martha", has ref 1;
$x2b isa person, has name "Patricia", has ref 2;
$x2c isa person, has name "Lily", has ref 3;
(sender: $x1, recipient: $x2a) isa gift-delivery;
(sender: $x1, recipient: $x2b) isa gift-delivery;
(sender: $x1, recipient: $x2c) isa gift-delivery;
(sender: $x2a, recipient: $x2b) isa gift-delivery;
"""
Given the integrity is validated
When get answers of graql query
"""
match
(sender: $a, recipient: $b) isa gift-delivery;
(sender: $b, recipient: $c) isa gift-delivery;
get;
"""
When concept identifiers are
| | check | value |
| SOR | key | ref:0 |
| MAR | key | ref:1 |
| PAT | key | ref:2 |
Then uniquely identify answer concepts
| a | b | c |
| SOR | MAR | PAT |
When get answers of graql query
"""
match
(sender: $a, recipient: $b) isa gift-delivery;
(sender: $b, recipient: $c) isa gift-delivery;
(sender: $c, recipient: $d) isa gift-delivery;
get;
"""
Then answer size is: 0


Scenario: an error is thrown when matching an entity type as if it were a role
Then graql get throws
"""
Expand Down Expand Up @@ -1308,14 +1377,43 @@ Feature: Graql Match Clause
| PER |


Scenario: value comparison of unbound variables throws an error
@ignore
# TODO: re-enable when variables used in multiple value predicates are resolvable (grakn#5845)
Scenario: an attribute variable used in both `==` and `>=` predicates is correctly resolved
Given graql insert
"""
insert
$x isa person, has name "Susie", has age 16, has ref 0;
$y isa person, has name "Donald", has age 25, has ref 1;
$z isa person, has name "Ralph", has age 18, has ref 2;
"""
Given the integrity is validated
When get answers of graql query
"""
match
$x has age == $z;
$z >= 17;
$z isa age;
get $x;
"""
And concept identifiers are
| | check | value |
| DON | key | ref:1 |
| RAL | key | ref:2 |
Then uniquely identify answer concepts
| x |
| DON |
| RAL |


Scenario: concept comparison of unbound variables throws an error
Then graql get throws
"""
match $x != $y; get;
"""


Scenario: concept comparison of unbound variables throws an error
Scenario: value comparison of unbound variables throws an error
Then graql get throws
"""
match $x !== $y; get;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

Feature: Graql Reasoner Rule Validation
Feature: Graql Rule Validation

Background: Initialise a session and transaction for each scenario
Given connection has been opened
Expand Down
12 changes: 10 additions & 2 deletions behaviour/graql/reasoner/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
package(default_visibility = ["//visibility:public"])

exports_files([
"resolution.feature",
"rule-validation.feature",
"attribute-attachment.feature",
"concept-inequality.feature",
"negation.feature",
"relation-inference.feature",
"roleplayer-attachment.feature",
"resolution-test-framework.feature",
"type-generation.feature",
"type-hierarchy.feature",
"value-predicate.feature",
"variable-roles.feature",
])
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Feature: Concept Inequality Resolution
"""
define
person sub entity,
has name;
ball sub entity,
has name,
plays ball1,
Expand Down Expand Up @@ -395,3 +398,128 @@ Feature: Concept Inequality Resolution
# Then all answers are correct in reasoned keyspace
Then answer size in reasoned keyspace is: 36
# Then materialised and reasoned keyspaces are the same size


@ignore
# TODO: re-enable once grakn#5821 is fixed (in some answers, $typeof_ax is 'base-attribute' which is incorrect)
# TODO: re-enable all steps once implicit attribute variables are resolvable
# TODO: migrate to concept-inequality.feature
Scenario: when restricting concept types of a pair of inferred attributes with `!=`, the answers have distinct types
Given for each session, graql define
"""
define
soft-drink sub entity,
has name,
has retailer;
base-attribute sub attribute, value string, abstract;
string-attribute sub base-attribute;
name sub base-attribute;
retailer sub base-attribute;
person has string-attribute;
tesco-sells-all-soft-drinks sub rule,
when {
$x isa soft-drink;
},
then {
$x has retailer 'Tesco';
};
"""
Given for each session, graql insert
"""
insert
$x isa person, has string-attribute "Tesco";
$y isa soft-drink, has name "Tesco";
"""
When materialised keyspace is completed
Then for graql query
"""
match
$x has base-attribute $ax;
$y has base-attribute $ay;
$ax isa! $typeof_ax;
$ay isa! $typeof_ay;
$typeof_ax != $typeof_ay;
get;
"""
Then all answers are correct in reasoned keyspace
# x | ax | y | ay |
# PER | STA | SOF | NAM |
# PER | STA | SOF | RET |
# SOF | NAM | PER | STA |
# SOF | RET | PER | STA |
# SOF | NAM | SOF | STA |
# SOF | STA | SOF | NAM |
Then answer size in reasoned keyspace is: 6
Then materialised and reasoned keyspaces are the same size

@ignore
# TODO: re-enable once grakn#5821 is fixed
# TODO: re-enable all steps once implicit attribute variables are resolvable
# TODO: migrate to concept-inequality.feature
Scenario: inferred attribute matches can be simultaneously restricted by both concept type and attribute value
Given for each session, graql define
"""
define
soft-drink sub entity,
has name,
has retailer;
base-attribute sub attribute, value string, abstract;
string-attribute sub base-attribute;
retailer sub base-attribute;
person has string-attribute;
transfer-string-attribute-to-other-people sub rule,
when {
$x isa person, has string-attribute $r1;
$y isa person;
},
then {
$y has string-attribute $r1;
};
tesco-sells-all-soft-drinks sub rule,
when {
$x isa soft-drink;
},
then {
$x has retailer 'Tesco';
};
if-ocado-exists-it-sells-all-soft-drinks sub rule,
when {
$x isa retailer;
$x == 'Ocado';
$y isa soft-drink;
},
then {
$y has retailer $x;
};
"""
Given for each session, graql insert
"""
insert
$w isa person, has string-attribute "Ocado";
$x isa person, has string-attribute "Tesco";
$y isa soft-drink, has name "Sprite";
$z "Ocado" isa retailer;
"""
When materialised keyspace is completed
Then for graql query
"""
match
$x has base-attribute $value;
$y has base-attribute $unwantedValue;
$value !== $unwantedValue;
$unwantedValue "Ocado";
$value isa! $type;
$unwantedValue isa! $type;
$type != $unwantedType;
$unwantedType type string-attribute;
get $x, $value, $type;
"""
Then all answers are correct in reasoned keyspace
# x | value | type |
# Sprite | Tesco | retailer |
Then answer size in reasoned keyspace is: 1
# Then materialised and reasoned keyspaces are the same size
Loading

0 comments on commit 39f044e

Please sign in to comment.