Skip to content

Commit

Permalink
[PlaybackSerialiser] Fixed tests
Browse files Browse the repository at this point in the history
- Added pruneList to clear endlineComments which have only null values
- [VirtualInput] Fixed equals method in VirtualCameraAngle returning false when pitch or yaw is null
  • Loading branch information
ScribbleTAS committed Jun 20, 2024
1 parent 62d85db commit d18ecd1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ public TickContainer() {

@Override
public String toString() {
String.join("\n// ", comments.inlineComments);
return keyboard.toString() + "|" + mouse.toString() + "|" + cameraAngle.toString();
}

Expand Down Expand Up @@ -716,6 +717,11 @@ public boolean equals(Object obj) {
}
return super.equals(obj);
}

@Override
public String toString() {
return inlineComments.toString()+"\n\n"+endlineComments.toString();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public abstract class SerialiserFlavorBase {
* Debug subtick field for error handling
*/
protected int currentSubtick = 0;

protected TickContainer previousTickContainer = null;

public abstract String flavorName();

Expand Down Expand Up @@ -305,8 +307,6 @@ protected String joinNotEmpty(String delimiter, String... args) {
*
*/

protected TickContainer previousTickContainer = null;

public boolean deserialiseFlavorName(List<String> headerLines) {
for (String line : headerLines) {
Matcher matcher = extract("^Flavor: " + flavorName(), line);
Expand Down Expand Up @@ -340,7 +340,7 @@ public List<String> extractHeader(BigArrayList<String> lines) {
throw new PlaybackLoadException("Cannot find the end of the header");
}

public void deserialiseFileCommandNames(List<String> headerLines) {
protected void deserialiseFileCommandNames(List<String> headerLines) {
for (String line : headerLines) {
Matcher matcher = extract("FileCommand-Extensions: ?(.*)", line);

Expand All @@ -355,7 +355,7 @@ public void deserialiseFileCommandNames(List<String> headerLines) {
throw new PlaybackLoadException("FileCommand-Extensions value was not found in the header");
}

public void deserialiseMetadata(List<String> headerLines) {
protected void deserialiseMetadata(List<String> headerLines) {
List<PlaybackMetadata> out = new ArrayList<>();

String metadataName = null;
Expand Down Expand Up @@ -582,7 +582,9 @@ protected void deserialiseContainer(BigArrayList<TickContainer> out, List<String
List<List<PlaybackFileCommand>> endlineFileCommands = new ArrayList<>();

splitInputs(containerLines, keyboardStrings, mouseStrings, cameraAngleStrings, endlineComments, endlineFileCommands);


pruneList(endlineComments);

VirtualKeyboard keyboard = deserialiseKeyboard(keyboardStrings);
VirtualMouse mouse = deserialiseMouse(mouseStrings);
VirtualCameraAngle cameraAngle = deserialiseCameraAngle(cameraAngleStrings);
Expand Down Expand Up @@ -826,8 +828,6 @@ protected void splitInputs(List<String> lines, List<String> serialisedKeyboard,

endlineFileCommands.add(deserialisedFileCommands);
}


}
}

Expand Down Expand Up @@ -909,6 +909,20 @@ public static <T extends Serializable> void addAll(BigArrayList<T> list, List<T>
list.add(element);
}
}

/**
* Empties the list if it only consists of null values
* @param <T> The element of the list
* @param list The list to prune
*/
protected <T> void pruneList(List<T> list){
for(T element : list) {
if(element != null) {
return;
}
}
list.clear();
}

@Override
protected abstract SerialiserFlavorBase clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,18 @@ public VirtualCameraAngle clone() {
public boolean equals(Object obj) {
if (obj instanceof VirtualCameraAngle) {
VirtualCameraAngle angle = (VirtualCameraAngle) obj;
return (pitch != null && pitch.equals(angle.pitch)) && (yaw != null && yaw.equals(angle.yaw));
if(pitch == null && angle.pitch != null) {
return false;
}
if(yaw == null && angle.yaw != null) {
return false;
}
if(pitch != null && !pitch.equals(angle.pitch)) {
return false;
}
if(yaw != null && !yaw.equals(angle.yaw))
return false;
return true;
}
return super.equals(obj);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ void testDeserialiser() throws PlaybackLoadException, IOException {
keyboard.updateFromEvent(VirtualKey.T, true, 't');

CommentContainer container = new CommentContainer();
container.addInlineComment("This is a regular comment");
container.addInlineComment(null);
container.addEndlineComment("test");
container.addEndlineComment(null);
expected.add(new TickContainer(keyboard, new VirtualMouse(), new VirtualCameraAngle(), container));

assertBigArrayList(expected, actual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.junit.jupiter.api.Test;

import com.dselent.bigarraylist.BigArrayList;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.CommentContainer;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TickContainer;
import com.minecrafttas.tasmod.playback.filecommands.PlaybackFileCommand;
import com.minecrafttas.tasmod.playback.filecommands.PlaybackFileCommand.PlaybackFileCommandExtension;
Expand Down Expand Up @@ -681,7 +682,7 @@ void testDeserialiseContainer() {
cameraAngle.updateFromState(17.85F, -202.74799F);
cameraAngle.updateFromState(11.85F, -2.74799F);
cameraAngle.updateFromState(45F, -22.799F);

expected.add(new TickContainer(keyboard, mouse, cameraAngle));

assertBigArrayList(expected, actual);
Expand Down
11 changes: 0 additions & 11 deletions src/test/resources/serialiser/PlaybackSerialiserTest2.mctas

This file was deleted.

0 comments on commit d18ecd1

Please sign in to comment.