-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMyFileWriterTester.java
More file actions
85 lines (79 loc) · 3.39 KB
/
MyFileWriterTester.java
File metadata and controls
85 lines (79 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
public class MyFileWriterTester {
public static void main(String[] args) {
testHashFileNormalFiles();
testHashFileEmptyFiles();
testHashFileLargeFiles();
testHashFileSpecialChars();
testHashFileNonExistent();
}
public static void testHashFileNormalFiles() {
// File f = new File("normal");
String data = "Hello World!";
String name = "normal.txt";
try {
Files.write(Paths.get(name), data.getBytes(StandardCharsets.UTF_8));
// Files.write(Paths.get("normal"), data.getBytes(StandardCharsets.UTF_8));
} catch (Exception e) {
// TODO: handle exception
}
System.out.print("Expected: 7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069\nResult: ");
System.out.println(MyFileWriter.hashFile(name));
}
public static void testHashFileEmptyFiles() {
// File f = new File("normal");
String data = "";
String name = "empty.txt";
try {
Files.write(Paths.get(name), data.getBytes(StandardCharsets.UTF_8));
// Files.write(Paths.get("normal"), data.getBytes(StandardCharsets.UTF_8));
} catch (Exception e) {
// TODO: handle exception
}
System.out.print("Expected: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\nResult: ");
System.out.println(MyFileWriter.hashFile(name));
}
public static void testHashFileLargeFiles() {
// THIS DOESN'T WORK AND IDK WHY
// File f = new File("normal");
// String data = "Hello World!";
String name = "script.txt";
// try {
// Files.write(Paths.get(name), data.getBytes(StandardCharsets.UTF_8));
// // Files.write(Paths.get("normal"), data.getBytes(StandardCharsets.UTF_8));
// } catch (Exception e) {
// // TODO: handle exception
// }
System.out.print("Expected: bedff2cf7a3d54b4e6ed9720b80e0f3a01df47c1a5737e60016b54caf4bbbad0\nResult: ");
System.out.println(MyFileWriter.hashFile(name));
}
public static void testHashFileSpecialChars() {
// File f = new File("normal");
String data = "😊🤣😊😊😊🤣🤣💕😘😂😁";
String name = "special.txt";
try {
Files.write(Paths.get(name), data.getBytes(StandardCharsets.UTF_8));
// Files.write(Paths.get("normal"), data.getBytes(StandardCharsets.UTF_8));
} catch (Exception e) {
// TODO: handle exception
}
System.out.print("Expected: feb38533d12ea354b9912f076ff25420b916098dd37a7c73f963702fa4fb3081\nResult: ");
System.out.println(MyFileWriter.hashFile(name));
}
public static void testHashFileNonExistent() {
// File f = new File("normal");
// String data = "Hello World!";
String name = "nonexistent.txt";
// try {
// Files.write(Paths.get(name), data.getBytes(StandardCharsets.UTF_8));
// // Files.write(Paths.get("normal"), data.getBytes(StandardCharsets.UTF_8));
// } catch (Exception e) {
// // TODO: handle exception
// }
System.out.println("Expected: Error");
System.out.println(MyFileWriter.hashFile(name));
}
}