Two tests fails (local build)

these 2 tests are failing

  1. undoEditLines()
  2. onUndoTheCursorShouldBeReturnedToRightPosition()

this is the earlier discussion about it

am using 2 stacks one to perform undo and other to perform redo operation.
when I debugged it and found this;
lets say

  • abcdefgh is the first version
  • editlines is called and its changed to abc12fgh (let “de” be the two lines that are updated)
  • now I have both of these versions in my undostack, (redostack is empty here)
  • when undo method is called. I popped abc12fgh from my undostack and pushed it on to redostack
  • and my logic returns abcdefgh ie top element of my undostack in this case

according to the assertion, it says abc12fgh is the version to be returned in this case. (at this point I have it in redostack & if I use that, other test cases will fail) I dint understand why it is so. I thought it is expecting to revert a single line change but that’s not the case.
and I found that it can be passed if at all top element of my undostack has latest edited version.(but other cases fails) and according to me abcdefgh is the version to be returned in above case.


even with the other test similar thing is happening. 1st editlines is called and a line is added and in searchreplace (we replace “LINENUMBER” to “lineno” here) the added line is changed from LINENUM101 to lineno101. At this point my logic returns latest version but it expects an earlier version with LINENUM101 but not the recent one. according to my approach it has to be the latest version.

I already spent a lot of time on this. definitely there’s some mistake with the way am thinking about it. But unable to understand what it is.

@AmoghaKS I was reviewing your code, I got some compilation errors. Can you please check and let me know when your code will be updated.

Hey @Saurav_Crio.Do,
but there’s no compilation error. I just checked it again.

Hey can you check with this FAQ
to have an idea how to utilize the stack/queue to save the versions of the source file Version.

https://forum.crio.do/t/randomundoredo-test-fails/10481/5

@Rahul-Crio.do yeah, I had gone through this FAQ, in the code I have written, i tried to do something similar.

Hey,

As i can see your onUndoTheCursorShouldBeReturnedToRightPosition test is fails. That mean after doing the operation your cursor is not at right position. Can you please check it once what our test is excepting ?

@gouravsardana from the very beginning my tests are failing cz of mismatch in pages. so there;s some problem with the undo implementation, and so far I didn’t actually faced any problem with cursors.

functions called from test file

  • loadfile //v1
  • editlines //v2 , linenum100 to LINENUM100
  • searchreplace //v3 pattern = LINENUM newpattern= linenum, (but here I was expecting that it replaces LINENUM100 to linenum100, but test was expecting v2 itself…somehow managed to return the same (now my stack has v1 v2 v3 & v2==v3, cz there was no change )
  • undo // I pop v3,
  • undo again //so I pop v2 and I return v1

but it is expecting v2 the one with LINENUM100, I think there’s some mistake in my approach itself
cz according to me v1 is the version to be returned and that is what am returning

where am I going wrong??

(Since there was no change in V2 v3…maybe it shudnt be considered as a new version. I worked considering this fact too)

Hey,

For better understanding just run your build again and see the assertion line. Just go to your test file and see the assertion line for the test (onUndoTheCursorShouldBeReturnedToRightPosition) and then compare the cursor position of our test with your file :slight_smile:

@gouravsardana
these are the last 2 lines of the test (onUndoTheCursorShouldBeReturnedToRightPosition)
assertEquals(new Cursor(0, 0), pageAfterSecondUndo.getCursorAt()); (1)
assertEquals(fileInfo.getLines(), pageAfterSecondUndo.getLines()); (2)

and my code is failing in (2) , where it is checking only the lines that it received. and in my last comment I was speaking about this test itself, after I checked the assertion in testfile. And so i thought everything is good with the cursors. also not much hint is there about the cursors in testfile, (1) is the only thing checking the cursor positions and (1) is passing for me. still couldn’t get it

Hey,

If you see this assertion -
assertEquals(new Cursor(0, 0), pageAfterSecondUndo.getCursorAt()); (1)
If you go one line up and see -
Page pageAfterSecondUndo = sourceFileHandlerArrayListImpl.getLinesFrom(pageRequest);
This is calling getlineFrom. Can you please check getlinefrom. It might be the case our test is expecting cursor at (0,0)

Yes and the page I returned also has cursor at (0,0)

(everything wrt SourceFileHandlerArrayListImpl…, have not implemented it for LinkedList yet. )

Dming you about this.

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.