Skip to content

Instantly share code, notes, and snippets.

@putuyoga
Created January 8, 2016 09:09
Show Gist options
  • Save putuyoga/6b8fef3c7599066e8d3f to your computer and use it in GitHub Desktop.
Save putuyoga/6b8fef3c7599066e8d3f to your computer and use it in GitHub Desktop.
Simple class of Human.
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;
}
}
[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