Skip to content

Commit 8045c9f

Browse files
committed
测试 提交 日志
1 parent 61033bb commit 8045c9f

File tree

5 files changed

+113
-46
lines changed

5 files changed

+113
-46
lines changed

out.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
<version>4.11</version>
1515
<scope>test</scope>
1616
</dependency>
17+
<dependency>
18+
<groupId>org.jetbrains</groupId>
19+
<artifactId>annotations-java5</artifactId>
20+
<version>RELEASE</version>
21+
<scope>compile</scope>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.jetbrains</groupId>
25+
<artifactId>annotations-java5</artifactId>
26+
<version>RELEASE</version>
27+
<scope>compile</scope>
28+
</dependency>
1729
</dependencies>
1830

1931
</project>

src/main/java/example/One.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package example;
22

3-
public class One {
3+
class One {
44
String message = "foo";
55

6+
One() {
7+
}
8+
69
public String foo() {
710
return message;
811
}

src/test/java/example/OneTest.java

Lines changed: 90 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package example;
22

3-
import static org.junit.Assert.*;
4-
53
import org.junit.Before;
64
import org.junit.Test;
75

@@ -10,48 +8,105 @@
108
import java.io.FileInputStream;
119
import java.io.InputStreamReader;
1210
import java.util.ArrayList;
11+
import java.util.Collections;
12+
import java.util.Comparator;
1313
import java.util.List;
1414

15+
import static org.junit.Assert.assertEquals;
16+
1517
public class OneTest {
1618

17-
@Before
18-
public void beforeFoo(){
19-
File file = new File("out.txt");
20-
if(file.exists()){
21-
file.delete();
19+
// private String name ="11";
20+
21+
@Before
22+
public void beforeFoo() {
23+
File file = new File("out.txt");
24+
if (file.exists()) {
25+
boolean a = file.delete();
26+
if(a){
27+
System.out.println("aaa");
28+
}
29+
}
30+
}
31+
32+
private List<String> readOutFile() {
33+
File file = new File("out.txt");
34+
FileInputStream is;
35+
List<String> list = new ArrayList<String>();
36+
try {
37+
if (file.length() != 0) {
38+
is = new FileInputStream(file);
39+
InputStreamReader streamReader = new InputStreamReader(is);
40+
BufferedReader reader = new BufferedReader(streamReader);
41+
String line;
42+
while ((line = reader.readLine()) != null) {
43+
list.add(line);
44+
}
45+
reader.close();
46+
is.close();
47+
}
48+
49+
} catch (Exception e) {
50+
e.printStackTrace();
51+
}
52+
return list;
53+
54+
}
55+
56+
@Test
57+
public void testFoo() {
58+
One one = new One();
59+
one.foo();
60+
List<String> list = readOutFile();
61+
assertEquals("freets", list.get(2));
62+
63+
int count = 3;
64+
sortByThread(list, count);
65+
66+
// boolean isSuccese = writeToOutFile("output.txt", list);
67+
2268
}
23-
}
24-
25-
private List<String> readOutFile() {
26-
File file = new File("out.txt");
27-
FileInputStream is;
28-
List<String> list = new ArrayList<String>();
29-
try {
30-
if (file.length() != 0) {
31-
is = new FileInputStream(file);
32-
InputStreamReader streamReader = new InputStreamReader(is);
33-
BufferedReader reader = new BufferedReader(streamReader);
34-
String line;
35-
while ((line = reader.readLine()) != null) {
36-
list.add(line);
69+
70+
private void sortByThread(List<String> list, int threadNum) {
71+
if (null == list) {
72+
return;
3773
}
38-
reader.close();
39-
is.close();
40-
}
4174

42-
} catch (Exception e) {
43-
e.printStackTrace();
75+
76+
if (list.size() <= threadNum) {
77+
sortList(list);
78+
}
79+
80+
sortList(list);
81+
82+
//分配每个线程处理的队列长度
83+
// int length = list.size() / threadNum;
84+
// boolean zhenchu = true;
85+
// if (list.size() % threadNum != 0) {
86+
// length += 1;
87+
// zhenchu = false;
88+
// }
89+
90+
91+
int times = 0;
92+
for (int num = 0; num < threadNum; num++) {
93+
times = list.size()/threadNum;
94+
}
95+
96+
if ( times == 0){
97+
System.out.println("2345");
98+
}
99+
sortList(list);
100+
44101
}
45-
return list;
46102

47-
}
103+
private void sortList(List<String> list) {
48104

49-
@Test
50-
public void testFoo() {
51-
One one = new One();
52-
one.foo();
53-
List<String> list = readOutFile();
54-
assertEquals("freets", list.get(2));
55-
}
105+
Collections.sort(list, new Comparator<String>() {
106+
public int compare(String o1, String o2) {
107+
return o1.compareTo(o2);
108+
}
109+
});
110+
}
56111

57112
}

src/test/java/example/Test.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package example;
2+
3+
public class Test {
4+
public static void main(String[] args) {
5+
System.out.println("test");
6+
}
7+
}

0 commit comments

Comments
 (0)