package tcra.exercises.q2_mystery_private;

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

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

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

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