Skip to content

Commit

Permalink
Filter UI tweak (#108)
Browse files Browse the repository at this point in the history
therealryan authored Sep 29, 2022
1 parent f45a51e commit df410a3
Showing 15 changed files with 202 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -35,8 +35,6 @@
*/
public class FilterGui {

private static final long serialVersionUID = 1L;

/**
* @return <code>true</code> if the gui should be invoked
*/
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package com.mastercard.test.flow.assrt.filter.gui;

import static com.mastercard.test.flow.assrt.filter.gui.FilterGui.titled;
@@ -26,6 +27,7 @@
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.TitledBorder;

import com.mastercard.test.flow.Flow;
@@ -183,7 +185,7 @@ class FlowPanel extends JPanel {
refresh();
} );

add( titled( "Disabled", disabledFlows ),
add( titled( "Disabled", new JScrollPane( disabledFlows ) ),
new GBCB()
.fill( BOTH )
.gridx( 0 ).gridy( 0 )
@@ -207,7 +209,7 @@ class FlowPanel extends JPanel {
.weightx( 0 ).weighty( 1 )
.get() );

add( titled( "Enabled", enabledFlows ),
add( titled( "Enabled", new JScrollPane( enabledFlows ) ),
new GBCB()
.fill( BOTH )
.gridx( 2 ).gridy( 0 )
@@ -259,7 +261,11 @@ void refresh() {
flow.meta().description(),
flow.meta().tags().stream()
.filter( t -> !includedTags.contains( t ) )
.collect( joining( " " ) ) );
.collect( joining( " " ) ) )
// We're using swing's html support to render tags in gray, but the renderer
// will also try
// to wrap lines. We want our items to only take one line, so...
.replace( " ", "&nbsp;" );
listedFlows.put( rendered, new IndexedFlow( index, flow ) );

if( indices.isEmpty() || indices.contains( new IndexedFlow( index, flow ).index ) ) {
@@ -300,6 +306,7 @@ void refresh() {
}

private class IndexedFlow {

public final int index;
public final Flow flow;

Original file line number Diff line number Diff line change
@@ -196,7 +196,8 @@ private static final String toRendered( String flow ) {
if( m.find() ) {
return String.format(
"<html>%s <span style=\"color:gray\">%s</span></html>",
m.group( 1 ), m.group( 2 ) );
m.group( 1 ), m.group( 2 ) )
.replaceAll( " ", "&nbsp;" );
}
return flow;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package com.mastercard.test.flow.assrt.filter.gui;

import static java.util.stream.Collectors.joining;
@@ -33,6 +34,7 @@
* Utility for extracting the state of the gui as character art
*/
class GuiRender {

private GuiRender() {
// no instances
}
@@ -185,7 +187,7 @@ private static Deque<String> listContent( JListFixture list, int width, int heig
"<html>(.*) <span style=\"color:gray\">(.*)</span></html>" );

private static final String fromRendered( String flow ) {
Matcher m = FROM_RENDERED.matcher( flow );
Matcher m = FROM_RENDERED.matcher( flow.replaceAll( "&nbsp;", " " ) );
if( m.find() ) {
return String.format( "%s | %s", m.group( 1 ), m.group( 2 ) );
}
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.ToIntBiFunction;
import java.util.function.ToIntFunction;

import javax.swing.AbstractAction;
import javax.swing.Action;
@@ -57,7 +59,9 @@
*/
public class Coppice {

private final CachingDiffDistance<Flow> diffDistance = new CachingDiffDistance<>(
private ToIntFunction<
Flow> creationCost = f -> InheritanceHealth.flatten( f ).split( "\n" ).length;
private ToIntBiFunction<Flow, Flow> derivationCost = new CachingDiffDistance<>(
InheritanceHealth::flatten,
InheritanceHealth::diffDistance );

@@ -125,7 +129,7 @@ public void actionPerformed( ActionEvent arg0 ) {
final FlowList flowList = new FlowList( selectionManager::update );
private final Range dfc = new Range( "Diff distance filter" );
private final GraphTree actualHierarchy = new GraphTree( "Actual Hierarchy",
diffDistance, selectionManager::update, popupMenu, dfc );
creationCost, derivationCost, selectionManager::update, popupMenu, dfc );

/**
* Flow detail views
@@ -227,6 +231,30 @@ public void mouseClicked( MouseEvent e ) {
progress.update( "Model", "instantiating", -1, 1 );
}

/**
* Controls how the creation cost of a {@link Flow} is calculated
*
* @param cc When supplied with a {@link Flow}, calculates the cost of creating
* that {@link Flow} from nothing
* @return <code>this</code>
*/
public Coppice creationCost( ToIntFunction<Flow> cc ) {
creationCost = cc;
return this;
}

/**
* Controls how the derivation cost of a {@link Flow} is calculated
*
* @param dc When supplied with a parent and child {@link Flow}s, calculates the
* cost of deriving the child from the parent
* @return <code>this</code>
*/
public Coppice derivationCost( ToIntBiFunction<Flow, Flow> dc ) {
derivationCost = dc;
return this;
}

/**
* Sets the model to be examined
*
@@ -269,8 +297,8 @@ public Coppice examine( Model model ) {
/**
* @return The diffing function
*/
public CachingDiffDistance<Flow> diffDistance() {
return diffDistance;
public ToIntBiFunction<Flow, Flow> diffDistance() {
return derivationCost;
}

/**
@@ -319,8 +347,8 @@ public void optimiseParent() {
Flow txn = selectionManager.getSelected();
if( txn != null ) {
GraphTree gt = new GraphTree( "Optimal parent for " + txn.meta().id(),
diffDistance, selectionManager::update, popupMenu, dfc );
Runnable task = new OptimiseParent( flows, txn, diffDistance, gt, progress );
creationCost, derivationCost, selectionManager::update, popupMenu, dfc );
Runnable task = new OptimiseParent( flows, txn, derivationCost, gt, progress );
runTask( gt, task );
}
}
@@ -332,8 +360,8 @@ public void optimiseChildren() {
Flow txn = selectionManager.getSelected();
if( txn != null ) {
GraphTree gt = new GraphTree( "Optimal hierarchy from " + txn.meta().id(),
diffDistance, selectionManager::update, popupMenu, dfc );
Runnable task = new OptimiseChildren( flows, txn, diffDistance, gt, progress );
creationCost, derivationCost, selectionManager::update, popupMenu, dfc );
Runnable task = new OptimiseChildren( flows, txn, derivationCost, gt, progress );
runTask( gt, task );
}
}
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.ToIntBiFunction;
import java.util.stream.Collectors;

import javax.swing.Timer;
@@ -15,7 +16,6 @@
import com.mastercard.test.flow.validation.coppice.ui.GraphTree;
import com.mastercard.test.flow.validation.coppice.ui.GraphView;
import com.mastercard.test.flow.validation.coppice.ui.Progress;
import com.mastercard.test.flow.validation.graph.CachingDiffDistance;
import com.mastercard.test.flow.validation.graph.DiffGraph;

/**
@@ -32,23 +32,23 @@ class OptimiseChildren implements Runnable {

private final List<Flow> corpus;
private final Flow txn;
private final CachingDiffDistance<Flow> diffDistance;
private final ToIntBiFunction<Flow, Flow> derivationCost;
private final GraphTree display;
private final Progress progress;

/**
* @param corpus The list of flows
* @param txn The flow to find start our MST at
* @param diffDistance How to calculate inter-flow distance
* @param display Where to display the results
* @param progress How to show processing progress
* @param corpus The list of flows
* @param txn The flow to find start our MST at
* @param derivationCost How to calculate inter-flow distance
* @param display Where to display the results
* @param progress How to show processing progress
*/
public OptimiseChildren( List<Flow> corpus, Flow txn,
CachingDiffDistance<Flow> diffDistance, GraphTree display,
ToIntBiFunction<Flow, Flow> derivationCost, GraphTree display,
Progress progress ) {
this.corpus = corpus;
this.txn = txn;
this.diffDistance = diffDistance;
this.derivationCost = derivationCost;
this.display = display;
this.progress = progress;
}
@@ -73,7 +73,7 @@ public void run() {
progress.update( "Dissolving", "complete", 1, 1 );

// build diffgraph
DiffGraph<Flow> diffGraph = new DiffGraph<>( diffDistance );
DiffGraph<Flow> diffGraph = new DiffGraph<>( derivationCost );
compat.forEach( diffGraph::add );
i.set( 0 );
diffGraph.withMSTListener( ( parent, child ) -> {
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
package com.mastercard.test.flow.validation.coppice;

import java.util.List;
import java.util.function.ToIntBiFunction;

import javax.swing.SwingUtilities;
import javax.swing.Timer;
@@ -17,7 +18,6 @@
import com.mastercard.test.flow.validation.coppice.ui.GraphTree;
import com.mastercard.test.flow.validation.coppice.ui.GraphView;
import com.mastercard.test.flow.validation.coppice.ui.Progress;
import com.mastercard.test.flow.validation.graph.CachingDiffDistance;

/**
* This task will, for a single flow, find the most similar flow in the corpus.
@@ -29,7 +29,7 @@ class OptimiseParent implements Runnable {

private final List<Flow> corpus;
private final Flow txn;
private final CachingDiffDistance<Flow> diffDistance;
private final ToIntBiFunction<Flow, Flow> derivationCost;
private final GraphTree display;
private final Progress progress;

@@ -38,18 +38,18 @@ class OptimiseParent implements Runnable {
private int testIndex = 0;

/**
* @param corpus The list of flows
* @param txn The flow to find a parent for
* @param diffDistance How to calculate inter-flow distance
* @param display How to show the results
* @param progress How to signal task progress
* @param corpus The list of flows
* @param txn The flow to find a parent for
* @param derivationCost How to calculate inter-flow distance
* @param display How to show the results
* @param progress How to signal task progress
*/
public OptimiseParent( List<Flow> corpus, Flow txn,
CachingDiffDistance<Flow> diffDistance, GraphTree display,
ToIntBiFunction<Flow, Flow> derivationCost, GraphTree display,
Progress progress ) {
this.corpus = corpus;
this.txn = txn;
this.diffDistance = diffDistance;
this.derivationCost = derivationCost;
this.display = display;
this.progress = progress;
}
@@ -77,7 +77,7 @@ public void run() {
testIndex++, corpus.size() );
Node tn = display.getNode( t );

int distance = diffDistance.apply( txn, t );
int distance = derivationCost.applyAsInt( txn, t );

Edge testEdge = display.graph().graph().addEdge( "test", tn, gn );

Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
import javax.swing.border.TitledBorder;

import com.mastercard.test.flow.Flow;
import com.mastercard.test.flow.validation.InheritanceHealth;
import com.mastercard.test.flow.validation.coppice.Coppice;
import com.mastercard.test.flow.validation.coppice.Diff;

@@ -44,7 +45,7 @@ public class DiffView {
*/
public DiffView( Coppice coppice, SelectionManager selection, Flow src ) {
source = src;
flatten = coppice.diffDistance()::stringify;
flatten = InheritanceHealth::flatten;

sourceName.addActionListener( e -> {
if( source != null ) {
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@
import java.util.TreeMap;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.ToIntBiFunction;
import java.util.function.ToIntFunction;
import java.util.stream.Collectors;

import javax.swing.JComponent;
@@ -42,14 +44,13 @@
import org.graphstream.ui.graphicGraph.GraphicElement;

import com.mastercard.test.flow.Flow;
import com.mastercard.test.flow.validation.graph.CachingDiffDistance;

/**
* Provides a linked tree and graph view of a flow hierarchy
*/
public class GraphTree implements SelectionManager.Client {

private final CachingDiffDistance<Flow> diffDistance;
private final ToIntBiFunction<Flow, Flow> diffDistance;
private final JSplitPane component;

/**
@@ -80,14 +81,19 @@ public class GraphTree implements SelectionManager.Client {

/**
* @param name The name of the view
* @param diffDistance How to calculate the distance between items
* @param creationCost How to calculate the construction cost of a flow
* @param derivationCost How to calculate the derivation cost of a flow
* @param selectionListener How items are selected
* @param popupMenu What to display when an item is clicked
* @param diffWeightFilter Which diffs to display
*/
public GraphTree( String name, CachingDiffDistance<Flow> diffDistance,
Consumer<Flow> selectionListener, JPopupMenu popupMenu, Range diffWeightFilter ) {
this.diffDistance = diffDistance;
public GraphTree( String name,
ToIntFunction<Flow> creationCost,
ToIntBiFunction<Flow, Flow> derivationCost,
Consumer<Flow> selectionListener,
JPopupMenu popupMenu,
Range diffWeightFilter ) {
diffDistance = derivationCost;
this.selectionListener = selectionListener;
this.diffWeightFilter = diffWeightFilter;

@@ -166,7 +172,7 @@ public void mouseClicked( MouseEvent e ) {
( k, v ) -> v != null ? v + 1 : 1 );
}
else {
rootWeight += diffDistance.stringify( flow ).split( "\n" ).length;
rootWeight += creationCost.applyAsInt( flow );
}
}

@@ -402,7 +408,7 @@ public Edge addEdge( Flow from, Flow to, String uiClass ) {
n.removeFromParent();
p.add( n );

Integer dd = diffDistance.apply( from, to );
Integer dd = diffDistance.applyAsInt( from, to );
basisDistance.put( to, dd );
minDistance = Math.min( minDistance, dd );
maxDistance = Math.max( maxDistance, dd );
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package com.mastercard.test.flow.validation;

import static java.util.stream.Collectors.joining;
@@ -17,6 +18,8 @@
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.ToIntBiFunction;
import java.util.function.ToIntFunction;
import java.util.stream.Stream;

import com.fasterxml.jackson.databind.ObjectMapper;
@@ -61,7 +64,8 @@
*/
public class InheritanceHealth {

private final CachingDiffDistance<Flow> diffDistance = new CachingDiffDistance<>(
private ToIntFunction<Flow> creationCost = f -> flatten( f ).split( "\n" ).length;
private ToIntBiFunction<Flow, Flow> derivationCost = new CachingDiffDistance<>(
InheritanceHealth::flatten,
InheritanceHealth::diffDistance );

@@ -125,6 +129,30 @@ public InheritanceHealth progress( Phase phase, BiConsumer<Flow, Float> listener
return this;
}

/**
* Controls how the creation cost of a {@link Flow} is calculated
*
* @param cc When supplied with a {@link Flow}, calculates the cost of creating
* that {@link Flow} from nothing
* @return <code>this</code>
*/
public InheritanceHealth creationCost( ToIntFunction<Flow> cc ) {
creationCost = cc;
return this;
}

/**
* Controls how the derivation cost of a {@link Flow} is calculated
*
* @param dc When supplied with a parent and child {@link Flow}s, calculates the
* cost of deriving the child from the parent
* @return <code>this</code>
*/
public InheritanceHealth derivationCost( ToIntBiFunction<Flow, Flow> dc ) {
derivationCost = dc;
return this;
}

/**
* Computes inheritance health and compares against expected value
*
@@ -173,11 +201,11 @@ private StructureCost actualCost( Model model, int total ) {
model.flows()
.forEach( flow -> {
if( flow.basis() == null ) {
rootWeight.addAndGet( diffDistance.stringify( flow ).split( "\n" ).length );
rootWeight.addAndGet( creationCost.applyAsInt( flow ) );
}
else {
edgeCosts.compute(
diffDistance.apply( flow.basis(), flow ),
derivationCost.applyAsInt( flow.basis(), flow ),
( k, v ) -> v == null ? 1 : v + 1 );
}
progress( Phase.ACTUAL_COST, flow, count.incrementAndGet(), total );
@@ -187,7 +215,7 @@ private StructureCost actualCost( Model model, int total ) {
}

private StructureCost optimalCost( Model model, int total ) {
DiffGraph<Flow> dg = new DiffGraph<>( diffDistance );
DiffGraph<Flow> dg = new DiffGraph<>( derivationCost );
model.flows().forEach( dg::add );

// The root of the MST only affects the final root weight - edge cost will be
@@ -209,11 +237,11 @@ private StructureCost optimalCost( Model model, int total ) {
TreeMap<Integer, Integer> edgeCosts = new TreeMap<>();
optimal.traverse( dag -> {
if( dag.parent() == null ) {
rootWeight.addAndGet( diffDistance.stringify( dag.value() ).split( "\n" ).length );
rootWeight.addAndGet( creationCost.applyAsInt( dag.value() ) );
}
else {
edgeCosts.compute(
diffDistance.apply( dag.parent().value(), dag.value() ),
derivationCost.applyAsInt( dag.parent().value(), dag.value() ),
( k, v ) -> v == null ? 1 : v + 1 );
}
progress( Phase.OPTIMAL_COST, dag.value(), count.incrementAndGet(), total );
@@ -228,6 +256,7 @@ private void progress( Phase phase, Flow flow, int current, int total ) {
}

private static class StructureCost {

final int rootWeight;
final TreeMap<Integer, Integer> edgeCosts;

@@ -241,14 +270,14 @@ String toString( String name, Histograph hstg ) {
if( !edgeCosts.isEmpty() && edgeCosts.firstKey() < hstg.getMinimum() ) {
throw new IllegalArgumentException(
String.format( ""
+ "Minimum edge weight %s lower than plot range minimum %s\n."
+ "Minimum edge weight %s lower than plot range minimum %s.\n"
+ "Decrease the plot range minimum to at most %s and try again.",
edgeCosts.firstKey(), hstg.getMinimum(), edgeCosts.firstKey() ) );
}
if( !edgeCosts.isEmpty() && edgeCosts.lastKey() > hstg.getMaximum() ) {
throw new IllegalArgumentException(
String.format( ""
+ "Maximum edge weight %s higher than plot range maximum %s\n."
+ "Maximum edge weight %s higher than plot range maximum %s.\n"
+ "Increase the plot range maximum to at least %s and try again.",
edgeCosts.lastKey(), hstg.getMaximum(), edgeCosts.lastKey() ) );
}
Original file line number Diff line number Diff line change
@@ -10,14 +10,15 @@
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.ToIntBiFunction;

/**
* A function that computes the distance between two item, caching intermediate
* results for performance
*
* @param <S> item type
*/
public class CachingDiffDistance<S> implements BiFunction<S, S, Integer> {
public class CachingDiffDistance<S> implements ToIntBiFunction<S, S> {

/**
* How to turn an item into a string to be diffed
@@ -51,7 +52,7 @@ public CachingDiffDistance( Function<S, String> stringify,
}

@Override
public Integer apply( S a, S b ) {
public int applyAsInt( S a, S b ) {
if( !diffCache.containsKey( a ) || !diffCache.get( a ).containsKey( b ) ) {
String as = stringify( a );
String bs = stringify( b );
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
import java.util.HashSet;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.ToIntBiFunction;

/**
* Represents a graph of items that can be compared against each other and the
@@ -20,7 +20,7 @@
public class DiffGraph<S> {

private final Set<S> nodes = new HashSet<>();
private final BiFunction<S, S, Integer> diff;
private final ToIntBiFunction<S, S> diff;

private BiConsumer<S, S> mstListener = ( parent, child ) -> {
// default no-op
@@ -35,7 +35,7 @@ public class DiffGraph<S> {
* between the items</li>
* </ul>
*/
public DiffGraph( BiFunction<S, S, Integer> diff ) {
public DiffGraph( ToIntBiFunction<S, S> diff ) {
this.diff = diff;
}

Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
import static java.util.Comparator.comparing;

import java.util.Comparator;
import java.util.function.BiFunction;
import java.util.function.ToIntBiFunction;

/**
* A node in graph over which we're running Prim's algorithm to find the Minimum
@@ -26,7 +26,7 @@ class PrimNode<S> {
/**
* How to calculate the distance between values
*/
private final BiFunction<S, S, Integer> diff;
private final ToIntBiFunction<S, S> diff;

/**
* The closest node in the MST
@@ -49,11 +49,11 @@ class PrimNode<S> {
* @param value Node value
* @param diff How to compute distances between node values
*/
public PrimNode( DAG<S> closest, S value, BiFunction<S, S, Integer> diff ) {
public PrimNode( DAG<S> closest, S value, ToIntBiFunction<S, S> diff ) {
this.value = value;
this.closest = closest;
this.diff = diff;
distance = diff.apply( closest.value(), value );
distance = diff.applyAsInt( closest.value(), value );
}

/**
@@ -71,7 +71,7 @@ public DAG<S> joinTree() {
* @param dag The newest node in the MST
*/
public void update( DAG<S> dag ) {
int d = diff.apply( dag.value(), value );
int d = diff.applyAsInt( dag.value(), value );
if( d < distance ) {
distance = d;
closest = dag;
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package com.mastercard.test.flow.validation;

import static java.util.stream.Collectors.joining;
@@ -15,6 +16,7 @@
import java.util.Optional;
import java.util.TreeMap;
import java.util.function.BiConsumer;
import java.util.function.ToIntFunction;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@@ -284,21 +286,79 @@ void plotRange() {
IllegalArgumentException iae = assertThrows( IllegalArgumentException.class,
() -> low.expect( mdl, "" ) );
assertEquals( ""
+ "Maximum edge weight 4 higher than plot range maximum 3\n"
+ ".Increase the plot range maximum to at least 4 and try again.",
+ "Maximum edge weight 4 higher than plot range maximum 3.\n"
+ "Increase the plot range maximum to at least 4 and try again.",
iae.getMessage() );
}
{
InheritanceHealth high = new InheritanceHealth( 5, 5, 5, Assertions::assertEquals );
IllegalArgumentException iae = assertThrows( IllegalArgumentException.class,
() -> high.expect( mdl, "" ) );
assertEquals( ""
+ "Minimum edge weight 4 lower than plot range minimum 5\n"
+ ".Decrease the plot range minimum to at most 4 and try again.",
+ "Minimum edge weight 4 lower than plot range minimum 5.\n"
+ "Decrease the plot range minimum to at most 4 and try again.",
iae.getMessage() );
}
}

/**
* Shows that the cost-estimation behaviour can be altered. Here the creation
* cost is just the numeric value of the flow description, and the derivation
* cost is the numeric difference. Optimisation takes us from:
*
* <pre>
* 1
* └16 15
* └2 14
* └8 6
* └4 4
* </pre>
*
* to:
*
* <pre>
* 1
* └2 1
* └4 2
* └8 4
* └16 8
* </pre>
*/
@Test
void customCost() {
Model mdl = mdl( "1", "1>16", "16>2", "2>8", "8>4" );

ToIntFunction<Flow> value = f -> Integer
.parseInt( f.meta().description().replaceAll( "\\D", "" ) );

InheritanceHealth ih = new InheritanceHealth( 0, 15, 16, Assertions::assertEquals );
assertSame( ih, ih.creationCost( value ) );
assertSame( ih, ih.derivationCost( ( p, c ) -> Math.abs(
value.applyAsInt( p ) - value.applyAsInt( c ) ) ) );

ih.expect( mdl,
"Actual | Optimal ",
"roots 1 | roots 1",
"edges 39 | edges 15",
"total 40 | total 16",
" 0 0.00% | 0 0.00%",
" 0 0.00% | 1 25.00%",
" 0 0.00% | 1 25.00%",
" 0 0.00% | 0 0.00%",
" 1 25.00% | 1 25.00%",
" 0 0.00% | 0 0.00%",
" 1 25.00% | 0 0.00%",
" 0 0.00% | 0 0.00%",
" 0 0.00% | 1 25.00%",
" 0 0.00% | 0 0.00%",
" 0 0.00% | 0 0.00%",
" 0 0.00% | 0 0.00%",
" 0 0.00% | 0 0.00%",
" 0 0.00% | 0 0.00%",
" 1 25.00% | 0 0.00%",
" 1 25.00% | 0 0.00%" );
}

private static final Pattern CHILD = Pattern.compile( "(.*)>(.*)" );

private static Model mdl( String... flowDefs ) {
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package com.mastercard.test.flow.validation.graph;

import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -52,11 +53,11 @@ void apply() {
Item i = new Item( 3 );
Item j = new Item( 5 );

assertEquals( 2, cdd.apply( i, j ), "results as expected" );
assertEquals( 2, cdd.applyAsInt( i, j ), "results as expected" );
assertEquals( 2, toStringCount.get(), "stringifed each item once" );
assertEquals( 1, distanceCount.get(), "distance computed once" );

assertEquals( 2, cdd.apply( i, j ), "results as expected again" );
assertEquals( 2, cdd.applyAsInt( i, j ), "results as expected again" );
assertEquals( 2, toStringCount.get(), "still only stringifed each item once" );
assertEquals( 1, distanceCount.get(), "distance computed still only once" );
}

0 comments on commit df410a3

Please sign in to comment.