Skip to content

Commit 34d1b51

Browse files
authored
Merge pull request #1 from Ameneh-Keshavarz/simpletests
Simpletests
2 parents b3078c1 + 5d22a28 commit 34d1b51

File tree

2 files changed

+78
-21
lines changed

2 files changed

+78
-21
lines changed

TDD/Families/Families.cs

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,79 +28,136 @@ public class Person : IPerson
2828
readonly string _id = Guid.NewGuid().ToString();
2929
public string Id => _id;
3030

31+
private string _name;
32+
private Gender _gender;
33+
private IPerson? _father;
34+
private IPerson? _mother;
35+
36+
private HashSet<IPerson> _children = new HashSet<IPerson>();
37+
private HashSet<IPerson> _brothers = new HashSet<IPerson>();
38+
private HashSet<IPerson> _sisters = new HashSet<IPerson>();
39+
private HashSet<IPerson> _daughters = new HashSet<IPerson>();
40+
private HashSet<IPerson> _sons = new HashSet<IPerson>();
41+
42+
43+
3144
public Person(string name, Gender gender)
3245
{
33-
46+
this._name = name;
47+
this._gender = gender;
3448
}
3549

36-
public string Name {
37-
get => throw new NotImplementedException();
38-
set => throw new NotImplementedException();
50+
public string Name
51+
{
52+
get => _name;
53+
set => _name = value;
3954
}
4055

4156
public void addBrother(IPerson brother)
4257
{
43-
throw new NotImplementedException();
58+
if (!this.getBrothers().Contains(brother))
59+
this._brothers.Add(brother);
60+
61+
if (!brother.getSisters().Contains(this))
62+
brother.addSister(this);
4463
}
4564

4665
public void addDaughter(IPerson daughter)
4766
{
48-
throw new NotImplementedException();
67+
if (!this._daughters.Contains(daughter))
68+
{
69+
this._daughters.Add(daughter);
70+
}
71+
72+
if (!this._children.Contains(daughter))
73+
{
74+
this._children.Add(daughter);
75+
76+
77+
}
4978
}
5079

5180
public void addSister(IPerson sister)
5281
{
53-
throw new NotImplementedException();
82+
if (!this.getSisters().Contains(sister))
83+
this._sisters.Add(sister);
84+
85+
if (!sister.getBrothers().Contains(this))
86+
sister.addBrother(this);
5487
}
5588

5689
public void addSon(IPerson son)
5790
{
58-
throw new NotImplementedException();
91+
if (!this._sons.Contains(son))
92+
{
93+
this._sons.Add(son);
94+
}
95+
96+
if (!this._children.Contains(son))
97+
{
98+
this._children.Add(son);
99+
}
59100
}
60101

61102
public IEnumerable<IPerson> getBrothers()
62103
{
63-
throw new NotImplementedException();
104+
return _brothers;
64105
}
65106

66107
public IEnumerable<IPerson> getChildren()
67108
{
68-
throw new NotImplementedException();
109+
return _children;
69110
}
70111

71112
public IEnumerable<IPerson> getDaughters()
72113
{
73-
throw new NotImplementedException();
114+
return _daughters;
74115
}
75116

76117
public IPerson? getFather()
77118
{
78-
throw new NotImplementedException();
119+
return this._father;
79120
}
80121

81122
public IPerson? getMother()
82123
{
83-
throw new NotImplementedException();
124+
return this._mother;
84125
}
85126

86127
public IEnumerable<IPerson> getSisters()
87128
{
88-
throw new NotImplementedException();
129+
return _sisters;
89130
}
90131

91132
public IEnumerable<IPerson> getSons()
92133
{
93-
throw new NotImplementedException();
134+
return _sons;
94135
}
95136

96137
public void setFather(IPerson father)
97138
{
98-
throw new NotImplementedException();
139+
this._father = father;
140+
if (this._gender == Gender.Male)
141+
{
142+
father.addSon(this);
143+
}
144+
else
145+
{
146+
father.addDaughter(this);
147+
}
99148
}
100149

101150
public void setMother(IPerson mother)
102151
{
103-
throw new NotImplementedException();
152+
this._mother = mother;
153+
if (this._gender == Gender.Male)
154+
{
155+
mother.addSon(this);
156+
}
157+
else
158+
{
159+
mother.addDaughter(this);
160+
}
104161
}
105162
}
106163
}

TDD/Tests/SimpleTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public void TestBrotherAndSister()
4343
alice.addBrother(chuck);
4444

4545
// Then
46-
Assert.Contains(alice, chuck.getBrothers());
47-
Assert.DoesNotContain(alice, chuck.getSisters());
48-
Assert.Single(chuck.getBrothers());
49-
Assert.Empty(chuck.getSisters());
46+
Assert.Contains(chuck, alice.getBrothers());
47+
Assert.Contains(alice, chuck.getSisters());
48+
Assert.Single(alice.getBrothers());
49+
Assert.Single(chuck.getSisters());
5050
}
5151

5252
[Fact]

0 commit comments

Comments
 (0)