Index: trunk/src/org/expeditee/actions/Simple.java
===================================================================
--- trunk/src/org/expeditee/actions/Simple.java	(revision 161)
+++ trunk/src/org/expeditee/actions/Simple.java	(revision 162)
@@ -162,5 +162,5 @@
 		do {
 			next = FrameIO.LoadNext(next);
-		} while (next != null && next.isTestFrame());
+		} while (next != null && !next.isTestFrame());
 		FrameUtils.DisplayFrame(next, true);
 	}
@@ -170,5 +170,5 @@
 		do {
 			prev = FrameIO.LoadPrevious(prev);
-		} while (prev != null && prev.isTestFrame());
+		} while (prev != null && !prev.isTestFrame());
 
 		FrameUtils.DisplayFrame(prev, true);
@@ -783,24 +783,62 @@
 			// Check for set statements
 		} else if (tokens[0].startsWith("calculatestring")) {
-			assertMinParametreCount(tokens, 2);
-			String toCalculate = context.getPrimitives().getStringValue(tokens[1]);
+			assertMinParametreCount(tokens, 1);
+			String toCalculate = context.getPrimitives().getStringValue(
+					tokens[1]);
 			boolean result = true;
+			String error = "";
 			ExpediteeJEP myParser = new ExpediteeJEP();
-			//Add the variables in the system
+			// Add the variables in the system
 			context.getPrimitives().addToParser(myParser);
 			Node equation = myParser.parseExpression(toCalculate);
-			//TODO get the answer
-			
+			// TODO get the answer
+			if (equation == null) {
+				result = false;
+				error = myParser.getErrorInfo().replace("\n", "");
+			} else {
+				double value = myParser.getValue();
+				if (myParser.hasError()) {
+					result = false;
+					error = myParser.getErrorInfo().replace("\n", "");
+				} else {
+					// Add a new variable if its an assignment statement
+					String newVar = myParser.getNewVariable();
+					if (newVar.length() > 0) {
+						try {
+							context.getPrimitives().setValue(newVar,
+									new SReal(value));
+						} catch (IncorrectTypeException e) {
+							result = false;
+							error = e.getMessage();
+						}
+					}
+					if (tokens.length > 2) {
+						context.getPrimitives().setValue(tokens[2],
+								new SReal(value));
+					}
+				}
+			}
+			// Set the result variable if there is one
+			if (tokens.length > 3) {
+				context.getPrimitives().setValue(tokens[3],
+						new SBoolean(result));
+				// Set the result variable if there is one
+				if (tokens.length > 4 && !result) {
+					context.getPrimitives().setValue(tokens[4], error);
+				}
+			}
 		} else if (tokens[0].startsWith("calculateitem")) {
 			assertMinParametreCount(tokens, 1);
 			assertVariableType(tokens[1], 1, SPointer.itemPrefix);
-			Item item = (Item)context.getPointers().getVariable(tokens[1]).getValue();
+			Item item = (Item) context.getPointers().getVariable(tokens[1])
+					.getValue();
 			Frame frame = null;
-			if(tokens.length > 2){
+			if (tokens.length > 2) {
 				assertVariableType(tokens[2], 2, SPointer.framePrefix);
-				frame = (Frame)context.getPointers().getVariable(tokens[2]).getValue();
+				frame = (Frame) context.getPointers().getVariable(tokens[2])
+						.getValue();
 			}
 			Misc.calculate(frame, item);
-		}else if (tokens[0].startsWith("issearchpatternvalid")) {
+		} else if (tokens[0].startsWith("issearchpatternvalid")) {
 			assertExactParametreCount(tokens, 2);
 			boolean result = true;
@@ -885,5 +923,14 @@
 				String pattern = context.getPrimitives().getStringValue(
 						tokens[2]);
-				SearchAgent searchAgent = new SearchFrameset();
+				long firstFrame = 1;
+				long maxFrame = Long.MAX_VALUE;
+				if(tokens.length > 7){
+					firstFrame = context.getPrimitives().getIntegerValue(tokens[7]);
+					if(tokens.length > 8){
+						maxFrame = context.getPrimitives().getIntegerValue(tokens[8]);
+					}
+				}
+				
+				SearchAgent searchAgent = new SearchFrameset(firstFrame, maxFrame);
 				searchAgent.initialise(null, null, frameset, resultsFrameset,
 						replacementString, pattern);
@@ -1187,4 +1234,29 @@
 							.getStringValue(tokens[1]), context.getPrimitives()
 							.getStringValue(tokens[2]));
+			} else if (tokens[0].equals("assertequalframes")) {
+				assertExactParametreCount(tokens, 2);
+				assertVariableType(tokens[1], 1, SPointer.framePrefix);
+				assertVariableType(tokens[2], 2, SPointer.framePrefix);
+				Frame frame1 = (Frame) context.getPointers().getVariable(
+						tokens[1]).getValue();
+				Frame frame2 = (Frame) context.getPointers().getVariable(
+						tokens[2]).getValue();
+				// Check that all the items on the frame are the same
+				List<Item> items1 = frame1.getVisibleItems();
+				List<Item> items2 = frame2.getVisibleItems();
+				if (items1.size() != items2.size()) {
+					throw new UnitTestFailedException(items1.size() + " items",
+							items2.size() + " items");
+				} else {
+					for (int i = 0; i < items1.size(); i++) {
+						Item i1 = items1.get(i);
+						Item i2 = items2.get(i);
+						String s1 = i1.getText();
+						String s2 = i2.getText();
+						if (!s1.equals(s2)) {
+							throw new UnitTestFailedException(s1, s2);
+						}
+					}
+				}
 			} else if (tokens[0].equals("assertdefined")) {
 				assertExactParametreCount(tokens, 1);
@@ -1193,4 +1265,6 @@
 							"not defined");
 				}
+			} else {
+				throw new RuntimeException("Invalid Assert statement");
 			}
 		} else if (tokens[0].startsWith("goto")) {
@@ -1957,13 +2031,27 @@
 				freshCopy.setFrameset(destinationFrameset);
 			}// Otherwise add it to the end of this frameset
-			freshCopy.setFrameNumber(FrameIO.getLastNumber(freshCopy
-					.getFramesetName()) + 1);
-			context.getPointers().setObject(tokens[2], freshCopy);
-			String fileContents = FrameIO.ForceSaveFrame(freshCopy);
+			int nextNumber = FrameIO.getLastNumber(freshCopy.getFramesetName()) + 1;
+			// if the frameset doesnt already exist then create it
+			if (nextNumber <= 0) {
+				try {
+					FrameIO.CreateFrameset(freshCopy.getFramesetName(),
+							frameToCopy.path);
+					nextNumber = 1;
+				} catch (Exception e) {
+				}
+			}
+			boolean success = false;
+			if (nextNumber > 0) {
+				freshCopy.setFrameNumber(nextNumber);
+				context.getPointers().setObject(tokens[2], freshCopy);
+				String fileContents = FrameIO.ForceSaveFrame(freshCopy);
+				success = fileContents != null;
+			}
 			FrameIO.ResumeCache();
-			// Need to add the new copy to the cache in case it is edited by
-			// other simple statements
-			FrameIO.addToCache(freshCopy);
-			boolean success = fileContents != null;
+			if (success) {
+				// Need to add the new copy to the cache in case it is edited by
+				// other simple statements
+				FrameIO.addToCache(freshCopy);
+			}
 			if (!success && _verbose)
 				MessageBay.warningMessage("Error copying "
