summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md10
-rw-r--r--lib/family_tree.rb2
-rw-r--r--spec/family_tree_spec.rb4
3 files changed, 13 insertions, 3 deletions
diff --git a/README.md b/README.md
index f681386..97c89f7 100644
--- a/README.md
+++ b/README.md
@@ -18,12 +18,13 @@ Example: `./ruby family_tree.rb /path/to/actions.txt`
**Supported Genders**
- `MALE`
-- `FEMAL`
+- `FEMALE`
**Supported Relationship Types**
- `MOTHER`
- `FATHER`
+- `SIBLING`
- `SIBLINGS`
- `CHILD`
- `DAUGHTER`
@@ -73,6 +74,13 @@ Based on the family tree, here are the expected outputs for commoon scenarios:
| `GET_RELATIONSHIP "King Arthur" "Pets"` | _no output_ | Invalid relationship type |
| `GET_RELATIONSHIP "King Arthur"` | _no output_ | Invalid number of arguments |
+## Assumptions
+
+- Both quoted and unquoted action parameters are supported, as seen in the provided examples.
+- Invalid actions and relationships produce no output, as this behavior was not documented. This prevents failures in a test harness due to unexpected output.
+- While most relationship types are singular, `SIBLINGS` is kept plural to ensure compatibility with existing tests.
+- Although relationship types are defined as singular, the `GET_RELATIONSHIP` action may return multiple values. This makes sense since it queries for all individuals related by the specified type.
+
## Approach
The implementation of this project follows a structured approach:
diff --git a/lib/family_tree.rb b/lib/family_tree.rb
index 9850280..4fa5dca 100644
--- a/lib/family_tree.rb
+++ b/lib/family_tree.rb
@@ -67,7 +67,7 @@ class FamilyTree
case relationship.downcase
when 'mother', 'father'
handle_parent_relationship(child_of_family, relationship)
- when 'siblings'
+ when 'siblings', 'sibling'
handle_siblings_relationship(child_of_family, name)
when 'child', 'daughter', 'son'
handle_children_relationship(parent_of_family, relationship)
diff --git a/spec/family_tree_spec.rb b/spec/family_tree_spec.rb
index dcff803..0d7c101 100644
--- a/spec/family_tree_spec.rb
+++ b/spec/family_tree_spec.rb
@@ -67,10 +67,12 @@ RSpec.describe FamilyTree do
context 'finding siblings' do
it 'returns sibling\'s name if present' do
- expect(FamilyTree.instance.get_relationship('Draco', 'siblings')).to eq('Aster')
+ expect(FamilyTree.instance.get_relationship('Draco', 'sibling')).to eq('Aster')
+ expect(FamilyTree.instance.get_relationship('Draco', 'sibling')).to eq('Aster')
end
it 'returns NONE if there are no siblings' do
+ expect(FamilyTree.instance.get_relationship('Remus', 'sibling')).to eq('NONE')
expect(FamilyTree.instance.get_relationship('Remus', 'siblings')).to eq('NONE')
end
end