Package statechum.analysis.learning

Examples of statechum.analysis.learning.StatePair


   */
  @Test
  public final void testStatePairEquality()
  {
    final Object samePairs[] = new StatePair[]{
        new StatePair(new StringVertex("a"), new StringVertex("b")),
        new StatePair(new DeterministicVertex("a"), new StringVertex("b")),
        new StatePair(new StringVertex("a"), new DeterministicVertex("b")),
        new StatePair(new DeterministicVertex("a"), new DeterministicVertex("b"))       
    },
    differentPairs[] = new Object[] {
        new StatePair(new StringVertex("a"), new StringVertex("c")),
        new StatePair(new StringVertex("d"), new StringVertex("b")),
        new StatePair(new StringVertex("d"), new StringVertex("e")),
        constructOrigPair("a", "b")
    };
    for(int sameFirst=0;sameFirst<samePairs.length;++sameFirst)
      for(int sameSecond=0;sameSecond<samePairs.length;++sameSecond)
        for(int different=0;different<differentPairs.length;++different)
View Full Code Here


 
  /** Tests that nulls are valid elements of state pairs. */
  public final void testStatePairEqualityWithNulls1()
  {
    final Object samePairs[] = new StatePair[]{
        new StatePair(null, new StringVertex("b")),
        new StatePair(null, new DeterministicVertex("b"))     
    },
    differentPairs[] = new Object[] {
        new StatePair(new StringVertex("b"), new StringVertex("b")),
        new StatePair(new DeterministicVertex("b"), new StringVertex("b")),
        new StatePair(null, null),
        constructOrigPair("a", "b")
    };
    for(int sameFirst=0;sameFirst<samePairs.length;++sameFirst)
      for(int sameSecond=0;sameSecond<samePairs.length;++sameSecond)
        for(int different=0;different<differentPairs.length;++different)
View Full Code Here

 
  /** Tests that nulls are valid elements of state pairs. */
  public final void testStatePairEqualityWithNulls2()
  {
    final Object samePairs[] = new StatePair[]{
        new StatePair(new StringVertex("b"), null),
        new StatePair(new DeterministicVertex("b"),null)
    },
    differentPairs[] = new Object[] {
        new StatePair(new StringVertex("b"), new StringVertex("b")),
        new StatePair(new DeterministicVertex("b"), new StringVertex("b")),
        new StatePair(null, null),
        constructOrigPair("a", "b")
    };
    for(int sameFirst=0;sameFirst<samePairs.length;++sameFirst)
      for(int sameSecond=0;sameSecond<samePairs.length;++sameSecond)
        for(int different=0;different<differentPairs.length;++different)
View Full Code Here

 
  /** Tests that nulls are valid elements of state pairs. */
  public final void testStatePairEqualityWithNulls3()
  {
    final Object samePairs[] = new StatePair[]{
        new StatePair(null, null)
    },
    differentPairs[] = new Object[] {
        new StatePair(null, new StringVertex("b")),
        new StatePair(new DeterministicVertex("b"), null),
        constructOrigPair("a", "b")
    };
    for(int sameFirst=0;sameFirst<samePairs.length;++sameFirst)
      for(int sameSecond=0;sameSecond<samePairs.length;++sameSecond)
        for(int different=0;different<differentPairs.length;++different)
View Full Code Here

   
  }
 
  private final static void checkLess(String a,String b,String c,String d)
  {
    checkLessHelper(new StatePair(new StringVertex(a), new StringVertex(b)), new StatePair(new StringVertex(c), new StringVertex(d)));
    checkLessHelper(new StatePair(new DeterministicVertex(a), new StringVertex(b)), new StatePair(new DeterministicVertex(c), new StringVertex(d)));
    checkLessHelper(new StatePair(new StringVertex(a), new DeterministicVertex(b)), new StatePair(new StringVertex(c), new DeterministicVertex(d)));
  }
View Full Code Here

  }
 
  @Test
  public final void testStatePairComparisonWithNull()
  {
    checkLessHelper(new StatePair(null,null),new StatePair(new StringVertex("a"),null));
    checkLessHelper(new StatePair(null,null),new StatePair(null,new StringVertex("a")));
    checkLessHelper(new StatePair(null,new StringVertex("a")),new StatePair(new StringVertex("a"),null));
    checkLessHelper(new StatePair(null,new StringVertex("a")),new StatePair(new StringVertex("a"),new StringVertex("b")));
    checkLessHelper(new StatePair(new StringVertex("a"),null),new StatePair(new StringVertex("a"),new StringVertex("b")));
    Assert.assertEquals(0,new StatePair(null,null).compareTo(new StatePair(null,null)));
  }
View Full Code Here

    return new PairScore(aV,bV, score,score);
  }

  static protected void checkLess(String a, String b, int abS, String c, String d, int cdS, Configuration config)
  {
    StatePair p = constructPairScore(a,b,abS,config),
        q=constructPairScore(c,d,cdS,config);
    assertFalse(p.equals(q));
    assertTrue(p.compareTo(q)<0);
    assertTrue(q.compareTo(p)>0);
    assertFalse(p.hashCode() == q.hashCode());
    assertEquals(0,p.compareTo(p));
    assertEquals(0,q.compareTo(q));
  }
View Full Code Here

  }

  @Test
  public void testPairScoreEquality()
  {
    StatePair p = constructPairScore("a","b",4,testConfig), q=constructPairScore("a","b",4,testConfig);
    assertTrue(p.equals(p));
    assertTrue(p.equals(q));
    assertFalse(p.equals(null));
    assertFalse(p.equals("test"));
    assertFalse(p.equals(constructPairScore("a","c",4,testConfig)));
    assertFalse(p.equals(constructPairScore("a","b",6,testConfig)));
    assertFalse(p.equals(constructPairScore("b","b",4,testConfig)));
  }
View Full Code Here

    stateActual = actual.getInit();stateExpected = expected.getInit();
  }
 
  Queue<StatePair> currentExplorationBoundary = new LinkedList<StatePair>();// FIFO queue
  CollectionOfPairs statesAddedToBoundary = new CollectionOfPairs(expected,actual);
  currentExplorationBoundary.add(new StatePair(stateExpected,stateActual));statesAddedToBoundary.addAndCheck(new StatePair(stateExpected,stateActual));
  switch(compareVertices)
  {
  case DEEP:
    if (!DeterministicDirectedSparseGraph.deepEquals(stateExpected,stateActual))
      return new DifferentFSMException("vertices "+stateExpected+" and "+stateActual+" have different values of attributes");
    if (stateActual.getOrigState() == null)
    {
      if (stateExpected.getOrigState() != null)
      return new DifferentFSMException("vertices "+stateExpected+" and "+stateActual+" have different names");
    }
    else
      if (!stateActual.getOrigState().equals(stateExpected.getOrigState()))
        return new DifferentFSMException("vertices "+stateExpected+" and "+stateActual+" have different names");
    break;
  case NAMES: 
    if (!stateActual.getOrigState().equals(stateExpected.getOrigState()))
      return new DifferentFSMException("vertices "+stateExpected+" and "+stateActual+" have different names");
    break;
  case NONE:// nothing needs doing
    break;
  }

  CmpVertex sink = generateSinkState(expected);
  boolean prefixClosed = expected.config.isPrefixClosed() && actual.config.isPrefixClosed();
  Map<Label, CmpVertex> sinkRow = expected.createNewRow();
  while(!currentExplorationBoundary.isEmpty())
  {
    StatePair statePair = currentExplorationBoundary.remove();
    assert statePair.firstElem == sink || expected.transitionMatrix.containsKey(statePair.firstElem) : "state "+statePair.firstElem+" is not known to the expected graph";
    assert statePair.secondElem == sink || actual.transitionMatrix.containsKey(statePair.secondElem) : "state "+statePair.secondElem+" is not known to the actual graph";
    if (statePair.firstElem.isAccept() != statePair.secondElem.isAccept())
      return new DifferentFSMException("states "+statePair.firstElem+" and " + statePair.secondElem+" have a different acceptance labelling between the machines");

    Map<Label,CmpVertex> expectedTargets = statePair.firstElem == sink?sinkRow:expected.transitionMatrix.get(statePair.firstElem);
    Map<Label,CmpVertex> actualTargets = statePair.secondElem == sink?sinkRow:actual.transitionMatrix.get(statePair.secondElem);
    //if (prefixClosed && expectedTargets.size() != actualTargets.size())// each of them is equal to the keyset size from determinism
    //  return new DifferentFSMException("different number of transitions from states "+statePair);
    Set<Label> outgoing = new TreeSet<Label>();outgoing.addAll(expectedTargets.keySet());outgoing.addAll(actualTargets.keySet());
    for(Label label:outgoing)
    {
      CmpVertex nextExpectedState = null;
      if (!expectedTargets.containsKey(label))
      {
        if (prefixClosed)
          return new DifferentFSMException("no transition with expected label \""+label+"\" from a state \""+statePair.secondElem+"\" corresponding to \""+statePair.firstElem+"\"");
       
        nextExpectedState = sink; 
      }
      else
        nextExpectedState = expectedTargets.get(label);
     
      CmpVertex nextActualState = null;
      if (!actualTargets.containsKey(label))
      {
        if (prefixClosed)
          return new DifferentFSMException("no transition with actual label \""+label+"\" from a state \""+statePair.firstElem+"\" corresponding to \""+statePair.secondElem+"\"");
       
        nextActualState = sink; 
      }
      else
        nextActualState = actualTargets.get(label);

      StatePair nextPair = new StatePair(nextExpectedState,nextActualState);
      //System.out.println("outgoing: "+statePair.getR()+","+statePair.getQ()+"-"+label+"->"+nextPair.getR()+","+nextPair.getQ());// elements of the pairs are in reverse order
      if (statesAddedToBoundary.addAndCheck(nextPair))
      {
        switch(compareVertices)
        {
View Full Code Here

   
    // Here P is a singleton and R is empty, hence they are ignored.
    List<StatePair> outcome = MarkovClassifier.collectionOfSetsToPairs(collectionOfSets);
    // three pairs, here we have a hardwired expected response that unfortunately depends on the implementation of collectionOfSetsToPairs.
    Assert.assertEquals(3,outcome.size());
    Assert.assertTrue(outcome.contains(new StatePair(gr.findVertex("B"),gr.findVertex("C"))));
    Assert.assertTrue(outcome.contains(new StatePair(gr.findVertex("C"),gr.findVertex("D"))));
    Assert.assertTrue(outcome.contains(new StatePair(gr.findVertex("D"),gr.findVertex("E"))));
  }
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.StatePair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.