package tcra.exercises.resolve_stack_mystery_private;

import java.util.List;
import tcra.math.Assertion;
import tcra.math.MathInteger;
import tcra.math.MathString;
import tcra.math.MathType;

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

   @SuppressWarnings("unchecked")
   public boolean check(List<MathType> l)
   {
      MathString<MathType> lb_self = (MathString<MathType>)l.get(0);
      MathString<MathType> lb_t    = (MathString<MathType>)l.get(1);
      MathString<MathType> self    = (MathString<MathType>)l.get(2);
      MathString<MathType> t       = (MathString<MathType>)l.get(3);
      
      MathInteger e = (MathInteger)lb_self.elementAt(0);
      
      if(!(t.prepend(self.reverse()).equals(
           lb_t.prepend(lb_self.reverse())))) return false;
      if(!lb_self.equals(self.prepend(e)))    return false;
      
      return true;
   } // end check(List)
   
   public String toString()
   {
      return("∃ E: Integer ∋  Rev(S) * T = Rev(#S) * #T and "+
             "&gt;E&lt; * S = #S;");
   } // end toString()

   @SuppressWarnings("unchecked")
   public String toInstanceString(List<MathType> l)
   {
      MathString<MathType> lb_self = (MathString<MathType>)l.get(0);
      MathString<MathType> lb_t    = (MathString<MathType>)l.get(1);
      MathString<MathType> self    = (MathString<MathType>)l.get(2);
      MathString<MathType> t       = (MathString<MathType>)l.get(3);
      
      MathInteger e = (MathInteger)lb_self.elementAt(0);
      
      return("∃ E: Integer ∋  Rev("+self.toHTMLString()+") * "+
             t.toHTMLString()+" = Rev("+lb_self.toHTMLString()+
             ") * "+lb_t.toHTMLString()+" and &gt;"+e.toHTMLString()+
             "&lt; * "+self.toHTMLString()+" = "+
             lb_self.toHTMLString()+";");
   } // end toInstanceString(List)
} // end class
