Skip to content

Instantly share code, notes, and snippets.

@charlieamat
charlieamat / why-is-unit-testing-so-hard-1.cs
Last active March 6, 2017 20:56
Why is Unit Testing So Hard? - Example 1
public class StrongWeapon : Weapon
{
public override double Damage => 5.0;
}
public class Player
{
private Weapon _weapon;
public double Damage => _weapon.Damage;
@charlieamat
charlieamat / why-is-unit-testing-so-hard-3.cs
Last active March 5, 2017 20:05
Why is Unit Testing So Hard - Example 2
public class PlayerTest
{
[Test]
public void GetDamageFromWeapon()
{
var weapon = Substitute.For<Weapon>();
weapon.Damage.Returns(5.0);
Assert.AreEqual(5.0, new Player(weapon).Damage);
}
@charlieamat
charlieamat / why-is-unit-testing-so-hard-4.cs
Last active March 5, 2017 21:40
Why is Unit Testing So Hard - Change to strong weapon
public class StrongWeapon : Weapon
{
public double Damage => 4.0;
}
@charlieamat
charlieamat / why-is-unit-testing-so-hard-5.cs
Last active March 6, 2017 15:45
Why is Unit Testing So Hard - Example 3
public class Powerup : IPowerup
{
public double Multiplier { get; }
}
public class Player : IPlayer
{
private const int MaxPowerups = 3;
private Weapon _weapon;
@charlieamat
charlieamat / example-2-tests.cs
Last active March 6, 2017 16:00
Why Is Unit Testing So Hard? - Example 2 Tests
public class PlayerTest
{
private Weapon _weapon;
private IPowerup _powerup;
[SetUp]
public void Init()
{
_weapon = Substitute.For<Weapon>();
_weapon.Damage.Returns(1);
@charlieamat
charlieamat / example-2_refactored-tests_why-is-unit-testing-so-hard.cs
Last active March 6, 2017 16:48
Why Is Unit Testing So Hard? - Example 2 Refactored Tests
public class PlayerTest
{
private Weapon _weapon;
private IPowerup _powerup;
[SetUp]
public void Init()
{
_weapon = Substitute.For<Weapon>();
_weapon.Damage.Returns(1);
@charlieamat
charlieamat / example-2_source_why-is-unit-testing-so-hard.cs
Last active March 6, 2017 16:53
Why Is Unit Testing So Hard? - Example 2
public class Powerup : IPowerup
{
public double Multiplier { get; }
}
public class Player
{
private const int MaxPowerups = 4;
private Weapon _weapon;
public class Player
{
private const double MaxPowerups = 2;
private Weapon _weapon;
public List<IPowerup> Powerups { get; } = new List<IPowerup>();
public double Damage => _weapon.Damage * Powerups.Take(MaxPowerups).Sum(p => p.Multiplier);
}
using UnityEngine;
using UnityEngine.Events;
public class Goal : MonoBehaviour {
public Players scoresTo;
public IScoreEvent scoreEvent;
public void Construct(Players scoresTo, IScoreEvent scoreEvent) {
this.scoresTo = scoresTo;
public class MyCollaborator : MonoBehaviour
{
private void OnCollisionEnter(Collision collision)
{
foreach (ContactPoint contact in collision.contacts)
{
Debug.DrawRay(contact.point, contact.normal, Color.white);
}
}
}