runTest(grA,grB, stateC,expectedDuplicates);
}
private LearnerGraphND runTest(LearnerGraphND grA, LearnerGraphND grB, String secondStateInKeyPair, String [] duplicatesExpectedString)
{
Configuration config = Configuration.getDefaultConfiguration().copy();config.setGdFailOnDuplicateNames(false);config.setGdKeyPairThreshold(.1);
GD<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData> gd = new GD<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData>();
gd.init(grA, grB, threadNumber,config);gd.identifyKeyPairs();
ChangesRecorder recorder = new ChangesRecorder(null);
gd.makeSteps();gd.computeDifference(recorder);
//Visualiser.updateFrame(grA,grB);Visualiser.updateFrame(gd.showGD(grA, grB, 1), null);
Assert.assertEquals(2,gd.aTOb.size());
Set<CmpVertex> keyPairsLeft = new TreeSet<CmpVertex>(),keyPairsRight = new TreeSet<CmpVertex>();
keyPairsLeft.addAll(Arrays.asList(new CmpVertex[]{grA.findVertex(VertexID.parseID("A")),grA.findVertex(VertexID.parseID("C"))}));
keyPairsRight.addAll(Arrays.asList(new CmpVertex[]{gd.origToNewB.get(grB.findVertex(VertexID.parseID("B"))),gd.origToNewB.get(grB.findVertex(VertexID.parseID(secondStateInKeyPair)))}));
Assert.assertEquals(keyPairsLeft, gd.aTOb.keySet());
Set<CmpVertex> actual = new TreeSet<CmpVertex>();actual.addAll(gd.aTOb.values());Assert.assertEquals(keyPairsRight, actual);
Set<CmpVertex> duplicatesExpected = new TreeSet<CmpVertex>();
for(String dup:duplicatesExpectedString) duplicatesExpected.add(gd.origToNewB.get(grB.findVertex(VertexID.parseID(dup))));
Assert.assertEquals(duplicatesExpected,gd.duplicates);
Configuration cloneConfig = config.copy();cloneConfig.setLearnerCloneGraph(true);
LearnerGraphND graph = new LearnerGraphND(cloneConfig);AbstractLearnerGraph.copyGraphs(grA, graph);
ChangesRecorder.applyGD(graph, recorder.writeGD(TestGD.createDoc()), converter);
LearnerGraphND outcome = new LearnerGraphND(config);AbstractLearnerGraph.copyGraphs(graph, outcome);
Assert.assertNull(WMethod.checkM(grB, graph));
// Now do the same as above, but renumber states to match grB
AbstractLearnerGraph.copyGraphs(grA, graph);
Configuration configMut = Configuration.getDefaultConfiguration().copy();config.setLearnerCloneGraph(false);
LearnerGraphMutator<List<CmpVertex>,LearnerGraphNDCachedData> graphPatcher = new LearnerGraphMutator<List<CmpVertex>,LearnerGraphNDCachedData>(graph,configMut,null);
ChangesRecorder.loadDiff(graphPatcher, recorder.writeGD(TestGD.createDoc()), converter);
graphPatcher.removeDanglingStates();
LearnerGraphND result = new LearnerGraphND(configMut);
graphPatcher.relabel(result);