Skip to content

Instantly share code, notes, and snippets.

Avatar

Dawid Sibiński dsibinski

View GitHub Profile
View discountApplier_stupid_else-block.ts
if (allProductsQuantity > 10 && allProductsQuantity <= 50) {
discountValue += 10;
} else if (allProductsQuantity > 50) {
discountValue += 15;
}
View discountApplier_equalityTests.test.ts
it('getDiscountPercentageValue returns 0 percent discount for total quantity of 10 and total price of 2', () => {
let discountApplier = new DiscountApplier();
let products = [new Product("Product 1", 1, 5), new Product("Product 2", 1, 5)];
let discountValue = discountApplier.getDiscountPercentageValue(products);
expect(discountValue).toBe(0);
});
it('getDiscountPercentageValue returns 0 percent discount for 2 products with total quantity of 2 and total price of 100', () => {
let discountApplier = new DiscountApplier();
View discountApplier_2products50quantity.test.ts
it('getDiscountPercentageValue returns 10 percent discount for total quantity of 50', () => {
let discountApplier = new DiscountApplier();
let products = [new Product("Product 1", 1, 25), new Product("Product 2", 1, 25)];
let discountValue = discountApplier.getDiscountPercentageValue(products);
expect(discountValue).toBe(10);
});
View discountApplier_1productnewtest.test.ts
it('getDiscountPercentageValue returns 0 discount for 1 product with quantity of 11', () => {
let discountApplier = new DiscountApplier();
let products = [new Product("Product 1", 25, 11)]; // quantity set to 11
let discountValue = discountApplier.getDiscountPercentageValue(products);
expect(discountValue).toBe(0);
});
View discountApplier_zeroProducts.ts
getDiscountPercentageValue(products: Product[]): number {
let discountValue = 0;
if (products.length === 1) {
return 0;
}
let allProductsQuantity = products.reduce((sum, product) => sum + product.quantity, 0);
if (allProductsQuantity > 10 && allProductsQuantity <= 50) {
discountValue += 10;
View stryker.conf.json
{
"mutate": ["src/discountApplier.ts"]
}
View discountApplier.ts
export class DiscountApplier {
getDiscountPercentageValue(products: Product[]): number {
let discountValue = 0;
if (products.length === 1) {
return 0;
}
let allProductsQuantity = products.reduce((sum, product) => sum + product.quantity, 0);
if (allProductsQuantity > 10 && allProductsQuantity <= 50) {
View UnitTest_WithAssertObject.cs
[Test]
public void ApplyBlackFridayDiscount_Should_ApplyBlackFridayDiscount_When_CalledOnNewProduct()
{
// given
var product = CreateProduct(basePrice: 100);
// when
product.ApplyBlackFridayDiscount();
// then
View AssertObject_pattern.cs
class ProductAssert
{
private readonly Product _product;
public ProductAssert(Product product)
{
_product = product;
}
public ProductAssert HaveDiscount(string name, int value)
View Asserts_problem.cs
[Test]
public void ApplyBlackFridayDiscount_Should_ApplyBlackFridayDiscount_When_CalledOnNewProduct()
{
// given
var product = CreateProduct(basePrice: 100);
// when
product.ApplyBlackFridayDiscount();
// then