forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSparseArrayTest.java
More file actions
86 lines (78 loc) · 1.86 KB
/
SparseArrayTest.java
File metadata and controls
86 lines (78 loc) · 1.86 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
package com.examplehub.datastructures.array;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Arrays;
import org.junit.jupiter.api.Test;
class SparseArrayTest {
@Test
void testWrite() {
int[][] origin = {
{11, 22, 0, 0, 0, 0, 0},
{0, 33, 44, 0, 0, 0, 0},
{0, 0, 55, 66, 77, 0, 0},
{0, 0, 0, 0, 0, 88, 0},
{0, 0, 0, 0, 0, 0, 99}
};
int[][] compression =
new int[][] {
{5, 7, 9},
{0, 0, 11},
{0, 1, 22},
{1, 1, 33},
{1, 2, 44},
{2, 2, 55},
{2, 3, 66},
{2, 4, 77},
{3, 5, 88},
{4, 6, 99}
};
assertTrue(Arrays.deepEquals(compression, SparseArray.write(origin)));
}
@Test
void testRead() {
int[][] origin = {
{11, 22, 0, 0, 0, 0, 0},
{0, 33, 44, 0, 0, 0, 0},
{0, 0, 55, 66, 77, 0, 0},
{0, 0, 0, 0, 0, 88, 0},
{0, 0, 0, 0, 0, 0, 99}
};
int[][] compression =
new int[][] {
{5, 7, 9},
{0, 0, 11},
{0, 1, 22},
{1, 1, 33},
{1, 2, 44},
{2, 2, 55},
{2, 3, 66},
{2, 4, 77},
{3, 5, 88},
{4, 6, 99}
};
assertTrue(Arrays.deepEquals(origin, SparseArray.read(compression)));
}
@Test
void testWriteRead() {
int[][] origin = {
{11, 22, 0, 0, 0, 0, 0},
{0, 33, 44, 0, 0, 0, 0},
{0, 0, 55, 66, 77, 0, 0},
{0, 0, 0, 0, 0, 88, 0},
{0, 0, 0, 0, 0, 0, 99}
};
int[][] compression =
new int[][] {
{5, 7, 9},
{0, 0, 11},
{0, 1, 22},
{1, 1, 33},
{1, 2, 44},
{2, 2, 55},
{2, 3, 66},
{2, 4, 77},
{3, 5, 88},
{4, 6, 99}
};
assertTrue(Arrays.deepEquals(origin, SparseArray.read(SparseArray.write(origin))));
}
}