Skip to content

Instantly share code, notes, and snippets.

@cyriux
cyriux / NestedMonoidMapTest.java
Last active August 8, 2018 21:05
An example of a nested monoidal map with monoidal values, e.g. used to manage application settings
package com.cyrillemartraire.monoids;
import static org.junit.Assert.assertEquals;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
public class NestedMonoidMapTest {
@cyriux
cyriux / AverageTest.java
Created July 19, 2018 13:33
A simple example of a monoid to compose partial averages into a bigger average
package com.cyrillemartraire.monoids;
import static java.util.Arrays.stream;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class AverageTest {
@Test
@cyriux
cyriux / RatioTest.java
Created July 19, 2018 13:29
A simple example of a multiplicative monoid
package com.cyrillemartraire.monoids;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class RatioTest {
@Test
public void testNeutral() {
@cyriux
cyriux / EnvironmentalImpactTest.java
Last active May 17, 2024 08:26
CaseStudyEnvironmentalImpact
package com.cyrillemartraire.monoids;
import static com.cyrillemartraire.monoids.EnvironmentalImpactTest.CertifiedAmount.certified;
import static com.cyrillemartraire.monoids.EnvironmentalImpactTest.CertifiedAmount.uncertified;
import static com.cyrillemartraire.monoids.EnvironmentalImpactTest.EnvironmentalImpact.singleSupplier;
import static java.lang.Double.doubleToLongBits;
import static java.lang.Math.abs;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
@cyriux
cyriux / Pattern.java
Created October 23, 2016 22:09
Generative-music bluff code from generic patterns manipulations (clone & transform, recombine, group), with a concept of distance (similarity, expected to be not too high & not too low) between the patterns.
package com.martraire.generativemusic;
import static org.apache.commons.lang3.StringUtils.getLevenshteinDistance;
import static org.apache.commons.lang3.StringUtils.join;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
Scenario: Create an invoice
Given I am authenticated with an admin role
And there is a client "test client" with name: "test client"
When I review the admin invoices
Then the user "test client" is in the list of clients to invoice
When I define the global invoiced amount for "test client" with "123"
And I review again the admin invoices
Then the user "test client" is no longer in the list of clients to invoice
@cyriux
cyriux / shipping_cost_kata.md
Created May 24, 2012 15:40
Shipping cost TDD kata

E-commerce shipping company

On an e-commerce shop, during the checkout process you need to calculate the shipping costs, based on various information.

You work for a shipping company.

You receive a big message with plenty of data for one order from the online shop, and you must return the calculated shipping cost.

We gonna focus on the domain module that does the calculation.