Skip to content

Commit 3e4ec4b

Browse files
committed
Added UnitTests for Cell and implemented Cell
1 parent 13933eb commit 3e4ec4b

149 files changed

Lines changed: 195421 additions & 13 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vs/CellSimulator/v15/.suo

97 KB
Binary file not shown.

CellSimulator.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.28307.438
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CellSimulator", "CellSimulator.csproj", "{614DFFFA-D549-426F-882F-AB68DFB66BC4}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CellSimulatorTests", "..\CellSimulatorTests\CellSimulatorTests.csproj", "{EF80D7FC-6DC4-44CE-91DE-815E3DEE43B8}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{614DFFFA-D549-426F-882F-AB68DFB66BC4}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{614DFFFA-D549-426F-882F-AB68DFB66BC4}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{614DFFFA-D549-426F-882F-AB68DFB66BC4}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{EF80D7FC-6DC4-44CE-91DE-815E3DEE43B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{EF80D7FC-6DC4-44CE-91DE-815E3DEE43B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{EF80D7FC-6DC4-44CE-91DE-815E3DEE43B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{EF80D7FC-6DC4-44CE-91DE-815E3DEE43B8}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

Enums/ActionEnum.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ namespace CellSimulator.Enums
33
{
44
public enum ActionEnum
55
{
6-
6+
Born,
77
}
88
}

Interfaces/ICell.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public interface ICell
1313
ActionEnum LastAction { get; set; }
1414

1515
bool TrySplit();
16-
bool Split();
16+
bool TryEat();
1717
}
1818
}

Models/Cell.cs

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,48 @@ namespace CellSimulator.Models
1010
{
1111
public class Cell : ICell
1212
{
13-
public int ID { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
14-
public int Age { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
15-
public int Food { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
16-
public int MaxFood { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
17-
public int Energy { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
18-
public int MaxEnergy { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
19-
public ActionEnum LastAction { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
20-
21-
public bool Split()
13+
public int ID { get; set; }
14+
public int Age { get; set; }
15+
public int Food { get; set; }
16+
public int MaxFood { get; set; }
17+
public int Energy { get; set; }
18+
public int MaxEnergy { get; set; }
19+
public ActionEnum LastAction { get; set; }
20+
21+
private const double PROPABILITY_EAT_FOOD = 0.25;
22+
private const int INCREMENTOR_EAT_FOOD = 40;
23+
24+
private const double PROPABILITY_SPLIT = 0.25;
25+
26+
private Random rand;
27+
28+
public Cell(int id = 0, Random rand = null)
29+
{
30+
ID = id;
31+
this.rand = rand ?? new Random();
32+
}
33+
34+
public bool TryEat()
35+
{
36+
bool didEat = rand.NextDouble() <= PROPABILITY_EAT_FOOD;
37+
if(didEat)
38+
{
39+
IncrementFood();
40+
}
41+
return didEat;
42+
}
43+
44+
private void IncrementFood()
2245
{
23-
throw new NotImplementedException();
46+
if((Food += INCREMENTOR_EAT_FOOD) > MaxFood)
47+
{
48+
Food = MaxFood;
49+
}
2450
}
2551

2652
public bool TrySplit()
2753
{
28-
throw new NotImplementedException();
54+
return rand.NextDouble() <= PROPABILITY_SPLIT;
2955
}
3056
}
3157
}
9.14 KB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)