-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathDecompositionTest.java
90 lines (78 loc) · 2.72 KB
/
DecompositionTest.java
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
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
public class DecompositionTest extends Assert {
private static String readFile(String path) throws IOException {
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, Charset.forName("UTF-8")).trim();
}
@Test
public void test1() {
Decomposition t = new Decomposition(1);
assertEquals(1, t.N);
// Заменяю System.out на свой объект, который будет печатать в строчку
ByteArrayOutputStream os = new ByteArrayOutputStream();
System.setOut(new PrintStream(os));
t.gen();
assertEquals(String.format("1 = 1%n"), os.toString());
}
@Test
public void test2() {
Decomposition t = new Decomposition(2);
assertEquals(2, t.N);
// Заменяю System.out на свой объект, который будет печатать в строчку
ByteArrayOutputStream os = new ByteArrayOutputStream();
System.setOut(new PrintStream(os));
t.gen();
assertEquals(String.format("2 = 2%n2 = 1 + 1%n"), os.toString());
}
@Test
public void testPrint() {
Decomposition t = new Decomposition(2);
// Заменяю System.out на свой объект, который будет печатать в строчку
ByteArrayOutputStream os = new ByteArrayOutputStream();
System.setOut(new PrintStream(os));
int[] A = {1, 1};
t.print(A, A.length);
assertEquals(String.format("2 = 1 + 1%n"), os.toString());
}
@Test
public void test3() throws IOException {
checkFile(3);
}
@Test
public void test4() throws IOException {
checkFile(4);
}
@Test
public void test5() throws IOException {
checkFile(5);
}
@Test
public void test6() throws IOException {
checkFile(6);
}
@Test
public void test7() throws IOException {
checkFile(7);
}
private void checkFile(int n) throws IOException {
Decomposition t = new Decomposition(n);
ByteArrayOutputStream os = new ByteArrayOutputStream();
System.setOut(new PrintStream(os));
t.gen();
assertEquals(readFile(String.format("%02d.a", n)), os.toString().trim());
}
@Test
@Ignore // Тест производительности (слишком долгий)
public void test40() {
Decomposition t = new Decomposition(40);
t.gen();
}
}