package tcra.exercises.resolve_stack_mystery_private;

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

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

   @SuppressWarnings("unchecked")
   public boolean check(List<MathType> t)
   {
      MathString<MathType> lb_self   = (MathString<MathType>)t.get(0);
      MathString<MathType> self      = (MathString<MathType>)t.get(2);
      MathInteger          mystery   = (MathInteger)t.get(3);
      
      MathString<MathType> rst = lb_self.split(0).get(1);
      
      if(!self.equals(rst.prepend(mystery))) return false;
      if(!self.equals(lb_self)) return false;
      
      return true;
   } // end check(List)
   
   public String toString()
   {
      return("∃  F: Integer, Rst: Str(Integer) ∋ &lt;F&gt; *"+
             " Rst = #S and &lt;I&gt; * Rst = S;");
   } // 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(2);
      MathInteger          mystery   = (MathInteger)t.get(3);
      
      Vector<MathString<MathType>> split = lb_self.split(0);
      MathInteger          f   = (MathInteger)split.get(0).elementAt(0);
      MathString<MathType> rst = split.get(1);
      
      return("∃  F: Integer, Rst: Str(Integer) ∋ &lt;"+f.toHTMLString()+
             "&gt; * "+rst.toHTMLString()+" = "+
             lb_self.toHTMLString()+" and &lt;"+
             mystery.toHTMLString()+"&gt; * "+rst.toHTMLString()+
             " = "+self.toHTMLString()+";");
   } // end toInstanceString(List)
} // end class
