package tcra.exercises.q3_mystery_private;

import java.util.*;
import tcra.math.*;

public class Q3MysteryExercise_PostMystery3Assertion implements
      Assertion
{
   public Q3MysteryExercise_PostMystery3Assertion() {}

   @SuppressWarnings("unchecked")
   public boolean check(List<MathType> t)
   {
      MathString<MathType> lb_self  = (MathString<MathType>)t.get(0);
      MathInteger          lb_index = (MathInteger)t.get(1);
      MathString<MathType> lb_b     = (MathString<MathType>)t.get(2);
      MathString<MathType> self     = (MathString<MathType>)t.get(3);
      MathInteger          index    = (MathInteger)t.get(4);
      MathString<MathType> b        = (MathString<MathType>)t.get(5);
      
      MathString<MathType> A, B, X, Y;
      
      A = lb_self.split(lb_index.getValue()-1).get(0);
      B = lb_self.split(lb_index.getValue()-1).get(1);
      X = lb_b.split(lb_index.getValue()-1).get(0);
      Y = lb_b.split(lb_index.getValue()-1).get(1);
      
      if(!lb_self.equals(A.concat(B))) return false;
      if(!lb_b.equals(X.concat(Y))) return false;
      if(A.length() != lb_index.getValue()) return false;
      if(X.length() != lb_index.getValue()) return false;
      if(!self.equals(A.concat(Y))) return false;
      if(!b.equals(X.concat(B))) return false;
      
      return true;
   } // end check(List)
   
   public String toString()
   {
      return("there exists A, B, X, Y: String of Object such that<br>"+
             "#self = A * B and<br>"+
             "#b = X * Y and<br>"+
             "|A| = index and<br>"+
             "|X| = index and<br>"+
             "self = A * Y and<br>"+
             "b = X * B;");
   } // end toString()

   @SuppressWarnings("unchecked")
   public String toInstanceString(List<MathType> t)
   {
      MathString<MathType> lb_self  = (MathString<MathType>)t.get(0);
      MathInteger          lb_index = (MathInteger)t.get(1);
      MathString<MathType> lb_b     = (MathString<MathType>)t.get(2);
      MathString<MathType> self     = (MathString<MathType>)t.get(3);
      MathInteger          index    = (MathInteger)t.get(4);
      MathString<MathType> b        = (MathString<MathType>)t.get(5);
	      
      MathString<MathType> A, B, X, Y;
	      
      A = lb_self.split(lb_index.getValue()-1).get(0);
      B = lb_self.split(lb_index.getValue()-1).get(1);
      X = lb_b.split(lb_index.getValue()-1).get(0);
      Y = lb_b.split(lb_index.getValue()-1).get(1);
      
      return("there exists A, B, X, Y: String of Object such that<br>"+
              lb_self.toHTMLString()+" = "+A.toHTMLString()+" * "+B.toHTMLString()+" and<br>"+
              lb_b.toHTMLString()+" = "+X.toHTMLString()+" * "+Y.toHTMLString()+" and<br>"+
              "|"+A.toHTMLString()+"| = "+lb_index.toHTMLString()+" and<br>"+
              "|"+X.toHTMLString()+"| = "+lb_index.toHTMLString()+" and<br>"+
              self.toHTMLString()+" = "+A.toHTMLString()+" * "+Y.toHTMLString()+" and<br>"+
              b.toHTMLString()+" = "+X.toHTMLString()+" * "+B.toHTMLString()+";");
   } // end toInstanceString(List)
} // end class
