Skip to content

Instantly share code, notes, and snippets.

View marzoukali's full-sized avatar
:octocat:
Coding

Ahmed Ali marzoukali

:octocat:
Coding
  • Dublin, Ireland
View GitHub Profile
@marzoukali
marzoukali / unittest-example-3.cs
Created July 1, 2017 16:48
unittest-example-3
[TestFixture]
public class PrintInvoiceCommandTests
{
// Define the needed class and it's dependencies mocks
private PrintInvoiceCommand _command;
private Mock<IDatabase> _mockDatabase;
private Mock<IPrinter> _mockPrinter;
private Mock<IDateTimeWrapper> _mockDateTime;
private Invoice _invoice;
@marzoukali
marzoukali / unittest-example-3.cs
Created July 1, 2017 16:35
unittest-example-3
public class PrintInvoiceCommand
{
private readonly IDatabase _database;
private readonly IPrinter _printer;
private readonly IDateTimeWrapper _dateTime;
public PrintInvoiceCommand(
IDatabase database,
IPrinter printer,
IDateTimeWrapper dateTime)
@marzoukali
marzoukali / unittest-example-2.cs
Created July 1, 2017 16:32
unittest-example-2
// Interfaces
public interface IDatabase
{
Invoice GetInvoice(int invoiceId);
}
public interface IPrinter
{
void WriteLine(string text);
}
public class PrintInvoiceCommand
{
public void Execute(int invoiceId)
{
var database = new Database();
var invoice = database.GetInvoice(invoiceId);
Printer.WriteLine("Invoice ID: " + invoice.Id);
[TestFixture]
public class GameServiceTests
{
[Test]
public void GetGameById_WithValidId_ReturnsGame()
{
// Arrange and Act
var mockUnitOfWork = new Mock<IUnitOfWork>();
var mockQueries = new Mock<IQueries<Game>>();
var mockQueryable = new Mock<IQueryable<Game>>();
@marzoukali
marzoukali / gist:0fbb453252f41f0b4a1dfa2ae3da469c
Created May 29, 2017 15:48
C++ - Simple Problems - Problem 3 - Code Enhance Performance
int count = 0;
for(int a = 0; a < 100; a++)
{
for(int b = 0; b < 100; b++)
{
for(int c = 0; c < 100; c++)
{
int d = 100 - (a + b + c);
@marzoukali
marzoukali / cpp-simple-problems-third-perf-issue
Created May 29, 2017 15:39
C++ - Simple Problems - Problem 3 - Code With Performance Issue
int count = 0;
for(int a = 0; a < 100; a++)
{
for(int b = 0; b < 100; b++)
{
for(int c = 0; c < 100; c++)
{
for(int d = 0; d < 100; d++)
{
@marzoukali
marzoukali / gist:648b2e2fbf49e72eceb58755d3499bb3
Created May 29, 2017 15:27
c++ - Simple Problems - Second Problem - Third Trial
int count = 0;
for(int x =1; x<=100;++x)
 {
 for(int y = (x > 70 ? x + 1 : 70); y<=200; y++)
 {
 if((x+y) % 7 == 0) count++;
 }
}
cout << count;
@marzoukali
marzoukali / cpp-simple-problems-second
Created May 29, 2017 15:26
C++ Simple Problems - Problem 2 - Second Trial
int count = 0;
for(int x =1; x<=100;++x)
 {
 int y = 70
 
 if(x > y) y = x + 1; // If X already bigger than start of Y so skip all the small Y and move to y = x + 1; to enhance performance.
 
 for(; y<=200; y++)
 {
 if((x+y) % 7 == 0) count++;
@marzoukali
marzoukali / gist:ad19c6b7df8b17456e5989a81b30bfcc
Created May 29, 2017 15:24
C++ Simple Problems - Problem 2 - First Trial
// First Trial:
int count = 0;
for(int x =1; x<=100;++x)
 {
 for(int y = 70; y<=200; y++)
 {
 if(x<y && (x+y) % 7 == 0) count++;
 }
}
cout << count;