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
[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; | |
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 PrintInvoiceCommand | |
{ | |
private readonly IDatabase _database; | |
private readonly IPrinter _printer; | |
private readonly IDateTimeWrapper _dateTime; | |
public PrintInvoiceCommand( | |
IDatabase database, | |
IPrinter printer, | |
IDateTimeWrapper dateTime) |
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
// Interfaces | |
public interface IDatabase | |
{ | |
Invoice GetInvoice(int invoiceId); | |
} | |
public interface IPrinter | |
{ | |
void WriteLine(string text); | |
} |
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 PrintInvoiceCommand | |
{ | |
public void Execute(int invoiceId) | |
{ | |
var database = new Database(); | |
var invoice = database.GetInvoice(invoiceId); | |
Printer.WriteLine("Invoice ID: " + invoice.Id); |
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
[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>>(); |
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
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); |
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
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++) | |
{ |
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
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; |
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
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++; |
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
// 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; |