// compares 's' to a string describing its values // thus stack123 = "123". desc MUST be a sequence of // decimal number chars // // NOTE: THIS CAN FAIL WITH A WORKING STACK IF RatPoly.unparse IS BROKEN! private void assertStackIs(RatPolyStack s, String desc) { assertTrue(s.size() == desc.length()); for (int i = 0; i < desc.length(); i++) { RatPoly p = s.get(i); char c = desc.charAt(i); String asstr = "Elem(" + i + "): " + p.unparse() + ", Expected " + c + ", (Expected Stack:" + desc + ")"; assertTrue(asstr, eqv(p, constantPoly(c))); } }
// RatPoly equality check // (getting around non-definition of RatPoly.equals) private boolean eqv(RatPoly p1, RatPoly p2) { return p1.unparse().equals(p2.unparse()); }