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
|
import org.junit.jupiter.api.Test;
import java.io.*;
import static org.junit.jupiter.api.Assertions.*;
class MergingTablesTest {
@Test
void test() {
MergingTables.InputReader reader = new MergingTables.InputReader(System.in);
MergingTables.OutputWriter writer = new MergingTables.OutputWriter(System.out);
MergingTables mergingTables = new MergingTables(reader, writer);
mergingTables.tables = new MergingTables.Table[5];
MergingTables.Table t0 = new MergingTables.Table(1);
MergingTables.Table t1 = new MergingTables.Table(1);
MergingTables.Table t2 = new MergingTables.Table(1);
MergingTables.Table t3 = new MergingTables.Table(1);
MergingTables.Table t4 = new MergingTables.Table(1);
mergingTables.tables[0] = t0;
mergingTables.tables[1] = t1;
mergingTables.tables[2] = t2;
mergingTables.tables[3] = t3;
mergingTables.tables[4] = t4;
mergingTables.maximumNumberOfRows = 1;
mergingTables.rank = new int[]{0, 0, 0, 0, 0};
mergingTables.parent = new int[]{0, 1, 2, 3, 4};
mergingTables.merge(2, 4);
assertEquals(2, mergingTables.maximumNumberOfRows);
mergingTables.merge(1, 3);
assertEquals(2, mergingTables.maximumNumberOfRows);
mergingTables.merge(0, 3);
assertEquals(3, mergingTables.maximumNumberOfRows);
mergingTables.merge(4, 3);
assertEquals(5, mergingTables.maximumNumberOfRows);
mergingTables.merge(4, 2);
assertEquals(5, mergingTables.maximumNumberOfRows);
}
@Test
void test1() {
MergingTables.InputReader reader = new MergingTables.InputReader(System.in);
MergingTables.OutputWriter writer = new MergingTables.OutputWriter(System.out);
MergingTables mergingTables = new MergingTables(reader, writer);
mergingTables.tables = new MergingTables.Table[6];
MergingTables.Table t0 = new MergingTables.Table(10);
MergingTables.Table t1 = new MergingTables.Table(0);
MergingTables.Table t2 = new MergingTables.Table(5);
MergingTables.Table t3 = new MergingTables.Table(0);
MergingTables.Table t4 = new MergingTables.Table(3);
MergingTables.Table t5 = new MergingTables.Table(3);
mergingTables.tables[0] = t0;
mergingTables.tables[1] = t1;
mergingTables.tables[2] = t2;
mergingTables.tables[3] = t3;
mergingTables.tables[4] = t4;
mergingTables.tables[5] = t5;
mergingTables.maximumNumberOfRows = 10;
mergingTables.rank = new int[]{0, 0, 0, 0, 0, 0};
mergingTables.parent = new int[]{0, 1, 2, 3, 4, 5};
mergingTables.merge(5, 5);
assertEquals(10, mergingTables.maximumNumberOfRows);
mergingTables.merge(5, 4);
assertEquals(10, mergingTables.maximumNumberOfRows);
mergingTables.merge(4, 3);
assertEquals(10, mergingTables.maximumNumberOfRows);
mergingTables.merge(3, 2);
assertEquals(11, mergingTables.maximumNumberOfRows);
}
}
|