Created
January 8, 2016 09:09
-
-
Save putuyoga/6b8fef3c7599066e8d3f to your computer and use it in GitHub Desktop.
Simple class of Human.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Human | |
{ | |
public int Energy { get; private set; } | |
public bool Tired { get; private set; } | |
public void Eat(int calory) | |
{ | |
Energy += calory; | |
} | |
public void Work(int calory) | |
{ | |
Energy -= calory; | |
if (Energy < 0) | |
{ | |
Energy = 0; | |
Tired = true; | |
} | |
} | |
public void Rest() | |
{ | |
Tired = false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestClass] | |
public class HumanClassTest | |
{ | |
[TestMethod] | |
public void TooMuchWorkAndBecomeTired() | |
{ | |
var human = new Human(); | |
human.Eat(100); | |
human.Work(200); | |
Assert.AreEqual(true, human.Tired); | |
Assert.AreEqual(0, human.Energy); | |
} | |
[TestMethod] | |
public void EatSomethingAndEnergyIncreased() | |
{ | |
var human = new Human(); | |
var calory = 100; | |
var beginEnergy = human.Energy; | |
human.Eat(calory); | |
var endEnergy = human.Energy; | |
Assert.AreEqual(calory, endEnergy - beginEnergy); | |
} | |
[TestMethod] | |
public void AfterRestNotTiredAgain() | |
{ | |
var human = new Human(); | |
human.Work(100); | |
Assert.AreEqual(true, human.Tired); | |
human.Rest(); | |
Assert.AreEqual(false, human.Tired); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment