Skip to content

Commit

Permalink
better message for processing "time" and bug solved
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbuzatto committed Oct 14, 2023
1 parent 933d554 commit f653b63
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/main/java/br/com/davidbuzatto/yaas/gui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,9 @@ public void run() {

private void openExample() {
if ( ApplicationConstants.IN_DEVELOPMENT ) {
createTMInternalFrame( TMExamples.createDTMMonusHalt(), true, true, "0000100", TMAcceptanceType.HALT );
createTMInternalFrame(
TMExamples.createDTMDivideHalt(), true, true,
"00001001", TMAcceptanceType.HALT );
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/main/java/br/com/davidbuzatto/yaas/gui/tm/TMInternalFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ public class TMInternalFrame extends javax.swing.JInternalFrame {
private static final String MODEL_PROPERTIES_CARD = "model";
private static final String STATE_PROPERTIES_CARD = "state";
private static final String TRANSITION_PROPERTIES_CARD = "transition";
private static final String MAX_COUNT_ERROR_MESSAGE = String.format(
"""
It seems that the designed Turing Machine doesn't halt!
Since YAAS can store around %d transitions in tests,
either your input takes too long to be processed, or you
have an infinite loop.
""", ApplicationConstants.TURING_MACHINE_MAX_COUNT );

private TM tm;
private MainWindow mainWindow;
Expand Down Expand Up @@ -1526,8 +1534,7 @@ private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
drawPanel.requestFocus();

} else {
Utils.showErrorMessage( this,
"The designed Turing Machine never halts!" );
Utils.showErrorMessage( this, MAX_COUNT_ERROR_MESSAGE );
enableGUI();
}

Expand Down Expand Up @@ -2293,8 +2300,7 @@ private void runSingleTest() throws HeadlessException {
}

} else {
Utils.showErrorMessage( this,
"The designed Turing Machine never halts!" );
Utils.showErrorMessage( this, MAX_COUNT_ERROR_MESSAGE );
}

} else {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/br/com/davidbuzatto/yaas/model/tm/TMID.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ public TMID derive( TMTransition transition, TMOperation operation ) {
newString = CharacterConstants.BLANK_TAPE_SYMBOL + newString;
}

if ( newPosition < 0 ) {
newPosition = 0;
} else if ( newPosition >= newString.length() ) {
newPosition = newString.length()-1;
}

return new TMID(
transition.getTargetState(),
newString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public interface ApplicationConstants {
public static final String LIGHT_THEME = "LIGHT";
public static final String DARK_THEME = "DARK";

public static final int TURING_MACHINE_MAX_COUNT = 2000;
public static final int TURING_MACHINE_MAX_COUNT = 4000;

}

0 comments on commit f653b63

Please sign in to comment.