Skip to content

Instantly share code, notes, and snippets.

View emilybache's full-sized avatar

Emily Bache emilybache

View GitHub Profile
@emilybache
emilybache / test_gilded_rose.py
Created June 1, 2024 08:15
approvals and all combinations test in Python for Gilded Rose
# -*- coding: utf-8 -*-
import unittest
from approvaltests import combination_approvals
from gilded_rose import Item, GildedRose
class GildedRoseTest(unittest.TestCase):
def test_update_quality(self):
combination_approvals.verify_all_combinations(
@emilybache
emilybache / test_gilded_rose.py
Created June 1, 2024 08:06
Sample test code for python using approvals with all combinations to cover the Gilded Rose functionality
# -*- coding: utf-8 -*-
import unittest
from approvaltests import combination_approvals
from gilded_rose import Item, GildedRose
class GildedRoseTest(unittest.TestCase):
def test_update_quality(self):
combination_approvals.verify_all_combinations(
@emilybache
emilybache / GildedRoseApprovalTest.java
Created May 31, 2024 13:28
Sample approval test in Java that covers the Gilded Rose functionality
package com.gildedrose;
import org.approvaltests.Approvals;
import org.approvaltests.combinations.CombinationApprovals;
import org.approvaltests.reporters.DiffReporter;
import org.approvaltests.reporters.UseReporter;
import org.junit.jupiter.api.Test;
@UseReporter(DiffReporter.class)
public class GildedRoseApprovalTest {
@emilybache
emilybache / gildedrose_catch.cpp
Created May 23, 2024 16:42
If you just want to do the Gilded Rose refactoring in C++ and would like a Combination Approvals test to lean on. Use this with the 'cpp_catch2' version.
#include <catch2/catch.hpp>
#include "ApprovalTests.hpp"
#include "GildedRose.h"
std::ostream &operator<<(std::ostream &os, const Item &obj) {
return os
<< "name: " << obj.name
<< ", sellIn: " << obj.sellIn
<< ", quality: " << obj.quality;
@emilybache
emilybache / EmailChangedMessage.java
Last active January 18, 2022 10:51
Peel with a domain event instead of a boolean
record EmailChangedMessage(int userId, String newEmail) implements DomainEvent {}
@emilybache
emilybache / User.java
Created January 18, 2022 10:37
after peeling the call to MessageBus
public void changeEmail(String newEmail)
{
if (changeEmailInDatabase(newEmail)) return;
MessageBus.sendEmailChangedMessage(this.userId, newEmail);
}
boolean changeEmailInDatabase(String newEmail) {
Object[] data = Database.getUserById(userId);
email = (String)data[1];
userType = (UserType)data[2];
public void changeEmail(String newEmail)
{
Object[] data = Database.getUserById(userId);
email = (String)data[1];
userType = (UserType)data[2];
if (Objects.equals(email, newEmail))
return;
Object[] companyData = Database.getCompany(userId);
@emilybache
emilybache / GildedRoseTest.test_foo.approved.txt
Created August 23, 2018 07:56
issue #386 in cosmic ray - the files needed to reproduce the problem
args: ('foo', -1, 0) => 'foo, -2, 0'
args: ('foo', -1, 1) => 'foo, -2, 0'
args: ('foo', -1, 49) => 'foo, -2, 47'
args: ('foo', -1, 50) => 'foo, -2, 48'
args: ('foo', 0, 0) => 'foo, -1, 0'
args: ('foo', 0, 1) => 'foo, -1, 0'
args: ('foo', 0, 49) => 'foo, -1, 47'
args: ('foo', 0, 50) => 'foo, -1, 48'
args: ('foo', 11, 0) => 'foo, 10, 0'
args: ('foo', 11, 1) => 'foo, 10, 0'
@emilybache
emilybache / spec_helper.rb
Last active December 17, 2015 19:38
I'm having trouble getting started with approval testing in ruby, I can't find any documentation, and I can't seem to make sense of the source code. I'd really appreciate some help getting this code to run.
require 'approvals'
require 'approvals/rspec'
Approvals.configuration.approvals_path = './'