Skip to content

Instantly share code, notes, and snippets.

@daleth90
Last active April 1, 2018 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daleth90/4d125d1b59a586da7aa248b199e057f4 to your computer and use it in GitHub Desktop.
Save daleth90/4d125d1b59a586da7aa248b199e057f4 to your computer and use it in GitHub Desktop.
using NUnit.Framework;
using Zenject;
[TestFixture]
public class OthelloBoardModelTests : ZenjectUnitTestFixture {
[Test]
public void TryPlaceDiskAt3d_Default_InvokeOnPlaceDiskEventAt3d() {
OthelloBoardModel model = Container.Instantiate<OthelloBoardModel>();
int actualX = 0, actualY = 0;
model.OnPlaceDisk += delegate ( int x, int y, Disk disk ) {
actualX = x;
actualY = y;
};
model.TryPlaceDisk( 3, 4 );
Assert.AreEqual( 3, actualX );
Assert.AreEqual( 4, actualY );
}
[Test]
public void TryPlaceDiskAt8h_Default_InvokeOnPlaceDiskEventAt8h() {
OthelloBoardModel model = Container.Instantiate<OthelloBoardModel>();
int actualX = 0, actualY = 0;
model.OnPlaceDisk += delegate ( int x, int y, Disk disk ) {
actualX = x;
actualY = y;
};
model.TryPlaceDisk( 8, 8 );
Assert.AreEqual( 8, actualX );
Assert.AreEqual( 8, actualY );
}
[Test]
public void TryPlaceDiskOutOfBoard_Default_DoesNotInvokeOnPlaceDiskEvent() {
OthelloBoardModel model = Container.Instantiate<OthelloBoardModel>();
bool flag = false;
model.OnPlaceDisk += delegate ( int x, int y, Disk disk ) {
flag = true;
};
model.TryPlaceDisk( 1, 9 );
model.TryPlaceDisk( 0, 8 );
model.TryPlaceDisk( 9, 5 );
model.TryPlaceDisk( 9, -1 );
Assert.AreEqual( false, flag );
}
[Test]
public void TryPlaceDiskAt3d_DoTwice_TheSecondTimeDoesNotInvokeOnPlaceDiskEvent() {
OthelloBoardModel model = Container.Instantiate<OthelloBoardModel>();
model.TryPlaceDisk( 3, 4 );
bool flag = false;
model.OnPlaceDisk += delegate ( int x, int y, Disk disk ) {
flag = true;
};
model.TryPlaceDisk( 3, 4 );
Assert.AreEqual( false, flag );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment