-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnitTests.java
More file actions
115 lines (91 loc) · 4.83 KB
/
UnitTests.java
File metadata and controls
115 lines (91 loc) · 4.83 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package piecetable;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Nick
*
*
*/
public class UnitTests {
private static final String editsBufferPath = "C:\\Users\\Nick\\Downloads\\audioResearch\\hello1.txt";
private static final String objectPath = "C:\\Users\\Nick\\Downloads\\audioResearch\\hello.txt";
private static final String editsPath = "C:\\Users\\Nick\\Downloads\\audioResearch\\hello3.txt";
private static final String originalBufferPath = "C:\\Users\\Nick\\Downloads\\audioResearch\\hello2.txt";
private static final String removeBufferPath = "C:\\Users\\Nick\\Downloads\\audioResearch\\hello96.txt";
private static PieceTableAPI piecetable;
private static RandomAccessFile edits;
private static RandomAccessFile original;
public static void main(String[] args) {
intialize();
test_add_remove();
intialize();
test_original_remove_add_find();
rigourously_test_undo_redo(piecetable,edits);
intialize();
add_original_add_at_zero_add_add_at_zero();
intialize();
test_undo_redo_original_then_more_edits();
}
public static void intialize(){
piecetable = new PieceTableAPI(objectPath,editsBufferPath,editsPath,originalBufferPath,removeBufferPath);
edits = null;
try {
original = new RandomAccessFile(originalBufferPath,"rw");
edits = new RandomAccessFile(editsBufferPath,"rw");
edits.setLength(0);
original.setLength(0);
}
catch (IOException ex) {
Logger.getLogger(PieceTable.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static boolean test_original_remove_add_find(){
try {
original.write("hellogoodbye".getBytes());
}
catch (IOException ex) {
Logger.getLogger(PieceTable.class.getName()).log(Level.SEVERE, null, ex);
}
piecetable.add_original(12);
assert new String(piecetable.get_text()).equals(new String(piecetable.find(0,piecetable.byte_length))) : "get_text() != find(0, length)";
assert new String(piecetable.get_text()).equals("hellogoodbye"): "an edit sequence occured with an error";
//"hellogoodbye"
piecetable.remove(piecetable.byte_length-7, 3);
assert new String(piecetable.get_text()).equals(new String(piecetable.find(0,piecetable.byte_length))) : "get_text() != find(0, length)";
assert new String(piecetable.get_text()).equals("hellodbye"): "an edit sequence occured with an error";
//"hellodbye"
piecetable.undo();
assert new String(piecetable.get_text()).equals(new String(piecetable.find(0,piecetable.byte_length))) : "get_text() != find(0, length)";
assert new String(piecetable.get_text()).equals("hellogoodbye"): "an edit sequence occured with an error";
//"hellogoodbye"
piecetable.redo();
assert new String(piecetable.get_text()).equals(new String(piecetable.find(0,piecetable.byte_length))) : "get_text() != find(0, length)";
assert new String(piecetable.get_text()).equals("hellodbye"): "an edit sequence occured with an error";
//"hellodbye"
piecetable.undo();
assert new String(piecetable.get_text()).equals(new String(piecetable.find(0,piecetable.byte_length))) : "get_text() != find(0, length)";
assert new String(piecetable.get_text()).equals("hellogoodbye"): "an edit sequence occured with an error";
//"hellogoodbye"
try {
edits.seek(edits.length());
edits.write("adding I love programming".getBytes());
}
catch (IOException ex) {
Logger.getLogger(PieceTable.class.getName()).log(Level.SEVERE, null, ex);
}
piecetable.add(25, (int) piecetable.byte_length);
assert new String(piecetable.find(0,piecetable.byte_length)).equals(new String (piecetable.get_text())) : "get_text() != find(0, length)";
assert new String(piecetable.get_text()).equals("hellogoodbyeadding I love programming"): "an edit sequence occured with an error";
//"hellogoodbyeadding I love programming"
piecetable.remove(piecetable.byte_length-7, 3);
assert new String(piecetable.find(0,piecetable.byte_length)).equals(new String (piecetable.get_text())) : "get_text() != find(0, length)";
assert new String(piecetable.get_text()).equals("hellogoodbyeadding I love progming"): "an edit sequence occured with an error";
//"hellogoodbyeadding I love progming