-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Unit Test to Thoroughly Tests Mastodon's Undo Redo Mechanism #289
Conversation
The test currently fails because of a but in the Undo/Redo mechanism. That will be fixed by this PR mastodon-sc/mastodon-collection#16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main contribution of this PR is a unit test that checks if the undo/redo function works correctly on the Model. This is very valuable! Some parts of the test need some time to understand them, but overall the test is well written.
Also, this PR improves the dumping methods of ModelUtils a bit, which is also a good contribution.
- I made some suggestion mainly regarding code formatting and also a bit regarding code structuring.
- The unit tests for ModelUtils were failing on my machine due to a different default locale. However, this can be fixed with little effort. I made some suggestion regarding this.
testUndoRedoAfterModelImporter
is failing in the CI environment. This should be handled.
spotsTable.defineColumn( 9, "Label", "", Spot::getLabel ); | ||
spotsTable.defineColumn( 6, "Frame", "", spot -> Integer.toString( spot.getTimepoint() ) ); | ||
spotsTable.defineColumn( 9, "X", bracket( spaceUnits ), spot -> String.format( "%9.1f", spot.getDoublePosition( 0 ) ) ); | ||
spotsTable.defineColumn( 9, "Y", bracket( spaceUnits ), spot -> String.format( "%9.1f", spot.getDoublePosition( 1 ) ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spotsTable.defineColumn( 9, "Y", bracket( spaceUnits ), spot -> String.format( "%9.1f", spot.getDoublePosition( 1 ) ) ); | |
spotsTable.defineColumn( 9, "Y", bracket( spaceUnits ), spot -> String.format( Locale.US, "%9.1f", spot.getDoublePosition( 1 ) ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
private static void testUndoRedo( Model model ) | ||
{ | ||
final List< String > states = new ArrayList<>(); | ||
makeVariousChangesAndRecordUndoPoints( model, states ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it confusing when reading code, where changes to the variables that are given to the method happen inside the method. I usually do not expect this to happen.
Could this method maybe return a Pair<Model, List> instead? That would confuse me less.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I introduced a UndoVerifier class to solve that problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better now. Perhaps UndoRedoModifier
would be a bit better suited as class name?
This increases the reproducibility of the dump method, and makes it easier to test.
1. Broke large dump(...) method into smaller methods. 2. Merged redundant methods addLinkFeatureColumns and addSpotFeatureColumns into one method "addFeatureColumns".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I addressed all the reviewers comments
import org.mastodon.feature.FeatureSpec; | ||
import org.mastodon.feature.IntFeatureProjection; | ||
import org.mastodon.mamut.feature.SpotTrackIDFeature; | ||
import org.mastodon.model.tag.ObjTagMap; | ||
import org.mastodon.model.tag.ObjTags; | ||
import org.mastodon.model.tag.TagSetModel; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* The tables by default contain all spot and link properties as well | ||
* as the feature values. | ||
* <p> | ||
* There is also a method that {@link #dump(Model, DumpFlags...)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* @param maxLines | ||
* the max number of rows to print in the two tables. | ||
* @return a String representation of the model. | ||
* Which information to include in the table can be changed using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* Which information to include in the table can be changed using | ||
* {@link DumpFlags}. | ||
*/ | ||
public static final String dump( final Model model, final DumpFlags... options ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Difficult topic. I will leave it as it is to be consistent with the old code. You may read about the topic here:
Intellij doesn't like it, stack overflow recommends "public static final".
private static void testUndoRedo( Model model ) | ||
{ | ||
final List< String > states = new ArrayList<>(); | ||
makeVariousChangesAndRecordUndoPoints( model, states ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I introduced a UndoVerifier class to solve that problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from a minor suggestion to rename UndoVerifier to UndoRedoVerifier, which I leave up to your decision, I have no further suggestions to this PR.
return String.format( "%" + width + "s", "unset" ); | ||
} | ||
|
||
private static class TablePrinter< T > |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
* Which information to include in the table can be changed using | ||
* {@link DumpFlags}. | ||
*/ | ||
public static final String dump( final Model model, final DumpFlags... options ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Thanks for the explanation. The link is an interesting read. There are pros and cons regarding this that I was not aware of.
There is a PR to fix a small problem in Mastodon's undo/redo mechanism: mastodon-sc/mastodon-collection#16
The goal of this PR is to ensure that Mastodons very important undo/redo mechanism works properly. I there for added a unit test
ModelUndoRedoTest
. The unit test uses theModelUtils.dump(...)
method to convert the current status of theModel
into a string. Converting the model status into string allows me to test if the model is correctly rolled back into a specific (previously) recorded state.It was necessary to extend the
ModelUtils.dump(...)
method to also print the tag sets. (The undo redo mechanism handle tags as well.)