-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfinalTester.java
More file actions
195 lines (171 loc) · 6.84 KB
/
finalTester.java
File metadata and controls
195 lines (171 loc) · 6.84 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;
import java.io.BufferedReader;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import javafx.stage.DirectoryChooser;
public class finalTester {
static Commit a;
static Commit b;
static Commit c;
@BeforeAll
static void setUpBeforeClass() throws Exception {
Index.init();
}
public void file(String path, String content) throws IOException {
FileWriter fw = new FileWriter(path);
fw.write(content);
fw.close();
}
public void folder(String name) {
File folder = new File(name);
folder.mkdir();
}
@Test
void test1commit() throws Exception {
Index.init();
Index.add("file1");
Index.add("file2");
Commit onecommit = new Commit("", "Sam", "testing 1 commit");
// assertEquals("aaa", onecommit.getParentTree());
assertEquals("", onecommit.getParentCommit());
assertEquals("Sam", onecommit.getAuthor());
assertEquals("testing 1 commit", onecommit.getSummary());
assertEquals("", onecommit.getNextSha());
// assertTrue(onecommit.getParentTree().length() > 0);
}
@Test
void test2commits() throws Exception {
folder("commitFoler");
file("commitFoler/1", "1");
file("commitFoler/2", "2");
Index.add("commitFoler");
Commit commit = new Commit("", "kevin", "kill me");
commit.writeOut();
folder("commitFoler2");
file("commitFoler2/1", "1");
file("commitFoler2/2", "2");
Index.add("commitFoler2");
Commit commit2 = new Commit(commit.getParentTree(), commit.generateSha1(), "kevin", "kill me");
commit2.writeOut();
try (FileReader read = new FileReader("objects/" + commit.generateSha1());
BufferedReader br = new BufferedReader(read)) {
String treeSha = br.readLine();
String nextSha = br.readLine();
assertEquals(commit.getParentTree(), treeSha);
// assertEquals(commit2.generateSha1(), nextSha);
} catch (IOException e) {
e.printStackTrace();
}
try (FileReader read = new FileReader("objects/" + commit2.generateSha1());
BufferedReader br2 = new BufferedReader(read)) {
String treeSha2 = br2.readLine();
String prevSha2 = br2.readLine();
assertEquals(commit.getParentTree(), treeSha2);
assertEquals(commit2.getParentCommit(), prevSha2);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
void testBillionsOfCommits() throws Exception {
folder("commitFoler");
file("commitFoler/1", "1");
file("commitFoler/2", "2");
Index.add("commitFoler");
Commit commit = new Commit("", "kevin", "kill me");
commit.writeOut();
folder("commitFoler2");
file("commitFoler2/1", "1");
file("commitFoler2/2", "2");
Index.add("commitFoler2");
Commit commit2 = new Commit(commit.generateSha1(), "kevin", "kill me");
commit2.writeOut();
folder("commitFoler3");
file("commitFoler3/1", "1");
file("commitFoler3/2", "2");
Index.add("commitFoler3");
Commit commit3 = new Commit(commit.generateSha1(), "kevin", "kill me");
commit2.writeOut();
folder("commitFoler4");
file("commitFoler4/1", "1");
file("commitFoler4/2", "2");
Index.add("commitFoler3");
Commit commit4 = new Commit(commit.generateSha1(), "kevin", "kill me");
commit2.writeOut();
try (FileReader read = new FileReader("objects/" + commit.generateSha1());
BufferedReader br = new BufferedReader(read)) {
String treeSha = br.readLine();
String nextSha = br.readLine();
// assertEquals("aaa", treeSha);
// assertEquals(commit2.generateSha1(), nextSha);
} catch (IOException e) {
e.printStackTrace();
}
try (FileReader read = new FileReader("objects/" + commit2.generateSha1());
BufferedReader br2 = new BufferedReader(read)) {
String treeSha2 = br2.readLine();
String prevSha2 = br2.readLine();
// assertEquals("bbb", treeSha2);
assertEquals(commit2.getParentCommit(), prevSha2);
} catch (IOException e) {
e.printStackTrace();
}
try (FileReader read = new FileReader("objects/" + commit3.generateSha1());
BufferedReader br2 = new BufferedReader(read)) {
String treeSha2 = br2.readLine();
String prevSha2 = br2.readLine();
// assertEquals("bbb", treeSha2);
assertEquals(commit2.getParentCommit(), prevSha2);
} catch (IOException e) {
e.printStackTrace();
}
try (FileReader read = new FileReader("objects/" + commit4.generateSha1());
BufferedReader br2 = new BufferedReader(read)) {
String treeSha2 = br2.readLine();
String prevSha2 = br2.readLine();
// assertEquals("bbb", treeSha2);
assertEquals(commit2.getParentCommit(), prevSha2);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
void LastTestBRUHH() throws Exception {
folder("commitFoler");
file("commitFoler/1", "1");
file("commitFoler/2", "2");
Index.add("commitFoler");
Commit commit = new Commit("", "kevin", "kill me");
commit.writeOut();
folder("commitFoler2");
file("commitFoler2/1", "1");
file("commitFoler2/2", "2");
Index.add("commitFoler2");
Commit commit2 = new Commit(commit.generateSha1(), "kevin", "kill me");
commit2.writeOut();
folder("commitFoler3");
file("commitFoler3/1", "1");
file("commitFoler3/2", "2");
Index.add("commitFoler3");
Commit commit3 = new Commit(commit.generateSha1(), "kevin", "kill me");
commit2.writeOut();
folder("commitFoler4");
file("commitFoler4/1", "1");
Index.add("commitFoler4");
Commit commit4 = new Commit(commit.generateSha1(), "kevin", "kill me");
commit2.writeOut();
file("commitFoler4/3", "3");
Commit commit5 = new Commit(commit.generateSha1(), "Anrew Tiss", ":(");
Commit[] commits = new Commit[] { commit, commit2, commit3, commit4, commit5 };
for (Commit currentCommmit : commits) {
System.out.println("Next commmit " + currentCommmit.getNextSha());
}
}
}