Skip to content
Snippets Groups Projects

Resolve "Create tests for write to file"

Merged Eskild Smestu requested to merge 40-create-tests-for-write-to-file into main
2 files
+ 92
20
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -18,7 +18,6 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/*
* Class for handling configuration file for chaos game.
*
@@ -118,7 +117,7 @@ public class FileHandling {
Complex point = new Complex(doubles.get(0), doubles.get(1));
int sign = 1;
//int sign = doubles.get(2).intValue();
// int sign = doubles.get(2).intValue();
return new JuliaTransform(point, sign);
}
@@ -191,6 +190,18 @@ public class FileHandling {
}
}
/**
* Deletes a transform file.
*
* @param filename The name of the file to delete.
* @throws Exception if the file cannot be deleted.
*/
public static void deleteFile(String filename) throws Exception {
if (!new java.io.File(filename).delete()) {
throw new Exception("File could not be deleted");
}
}
/**
* Converts a vector to a string.
*
@@ -208,17 +219,22 @@ public class FileHandling {
* @return The affine transform as a string.
*/
private static String affineTransformToString(AffineTransform2D transform) {
return transform.getMatrix().getMatrix()[0]
+ ", "
+ transform.getMatrix().getMatrix()[1]
+ ", "
+ transform.getMatrix().getMatrix()[2]
+ ", "
+ transform.getMatrix().getMatrix()[3]
+ ", "
+ transform.getVector().getVector()[0]
+ ", "
+ transform.getVector().getVector()[1];
StringBuilder matrixString = new StringBuilder();
for (int i = 0; i < transform.getMatrix().getMatrix().length; i++) {
for (int j = 0; j < transform.getMatrix().getMatrix().length; j++) {
matrixString.append(transform.getMatrix().getMatrix()[i][j]).append(", ");
}
}
for (double vectorComponent : transform.getVector().getVector()) {
matrixString.append(vectorComponent).append(", ");
}
// remove last comma and space
matrixString.delete(matrixString.length() - 2, matrixString.length());
return matrixString.toString();
}
/**
Loading