1919
2020package org .apache .sysds .test .component .compress .mapping ;
2121
22+ import static org .junit .Assert .assertEquals ;
23+ import static org .junit .Assert .assertFalse ;
24+ import static org .junit .Assert .assertThrows ;
25+ import static org .junit .Assert .assertTrue ;
2226import static org .junit .Assert .fail ;
27+ import static org .mockito .Mockito .mock ;
28+ import static org .mockito .Mockito .spy ;
29+ import static org .mockito .Mockito .when ;
2330
31+ import org .apache .commons .lang3 .NotImplementedException ;
2432import org .apache .sysds .runtime .compress .CompressedMatrixBlock ;
33+ import org .apache .sysds .runtime .compress .DMLCompressionException ;
34+ import org .apache .sysds .runtime .compress .colgroup .mapping .AMapToData ;
2535import org .apache .sysds .runtime .compress .colgroup .mapping .MapToFactory ;
36+ import org .apache .sysds .runtime .compress .colgroup .offset .AOffset ;
37+ import org .apache .sysds .runtime .compress .colgroup .offset .OffsetFactory ;
38+ import org .apache .sysds .runtime .data .DenseBlock ;
39+ import org .apache .sysds .runtime .matrix .data .MatrixBlock ;
2640import org .junit .Test ;
2741
2842public class CustomMappingTest {
@@ -49,4 +63,87 @@ public void createBinary() {
4963 fail (e .getMessage ());
5064 }
5165 }
66+
67+ @ Test
68+ public void verifySpy () {
69+ CompressedMatrixBlock .debug = true ;
70+ AMapToData d = MapToFactory .create (data , 2 );
71+ AMapToData spy = spy (d );
72+ when (spy .getIndex (2 )).thenReturn (32 );
73+ assertThrows (DMLCompressionException .class , () -> spy .verify ());
74+ }
75+
76+ @ Test
77+ public void equals () {
78+ CompressedMatrixBlock .debug = true ;
79+ AMapToData d = MapToFactory .create (data , 2 );
80+ AMapToData d2 = MapToFactory .create (data , 2 );
81+ assertTrue (d .equals (d ));
82+ assertTrue (d .equals (d2 ));
83+ assertFalse (d .equals (MapToFactory .create (new int []{1 ,2 ,3 }, 4 )));
84+ assertFalse (d .equals (Integer .valueOf (23 )));
85+ }
86+
87+ @ Test
88+ public void countRuns () {
89+ CompressedMatrixBlock .debug = true ;
90+ AMapToData d = MapToFactory .create (new int [] {1 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 2 }, 3 );
91+ AOffset o = OffsetFactory .createOffset (new int [] {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 });
92+ assertEquals (d .countRuns (o ), 2 );
93+ }
94+
95+ @ Test
96+ public void countRuns2 () {
97+ CompressedMatrixBlock .debug = true ;
98+ AMapToData d = MapToFactory .create (new int [] {1 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 2 }, 3 );
99+ AOffset o = OffsetFactory .createOffset (new int [] {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 10 , 11 });
100+ assertEquals (d .countRuns (o ), 3 );
101+ }
102+
103+ @ Test
104+ public void getMax () {
105+ CompressedMatrixBlock .debug = true ;
106+ AMapToData d = MapToFactory .create (new int [] {1 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 2 }, 3 );
107+ assertEquals (d .getMax (), 2 );
108+ d = MapToFactory .create (new int [] {1 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 5 , 2 }, 10 );
109+ assertEquals (d .getMax (), 5 );
110+ d = MapToFactory .create (new int [] {1 , 1 , 1 , 9 , 1 , 2 , 2 , 2 , 2 , 2 }, 10 );
111+ assertEquals (d .getMax (), 9 );
112+ }
113+
114+ @ Test
115+ public void copyInt (){
116+ CompressedMatrixBlock .debug = true ;
117+ AMapToData d = MapToFactory .create (new int [] {10 ,9 ,8 ,7 ,6 ,5 ,4 ,3 ,2 ,1 }, 11 );
118+ AMapToData d2 = MapToFactory .create (new int [] {1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 }, Integer .MAX_VALUE -2 );
119+ d .copy (d2 );
120+ for (int i = 0 ; i < 10 ; i ++){
121+ assertEquals (d .getIndex (i ), d2 .getIndex (i ));
122+ }
123+ }
124+
125+ @ Test
126+ public void setInteger (){
127+ CompressedMatrixBlock .debug = true ;
128+ AMapToData d = MapToFactory .create (new int [] {10 ,9 ,8 ,7 ,6 ,5 ,4 ,3 ,2 ,1 }, 11 );
129+
130+ for (int i = 0 ; i < 10 ; i ++){
131+ assertEquals (d .getIndex (i ), 10 - i );
132+ }
133+ d .set (4 , Integer .valueOf (13 ));
134+ assertEquals (d .getIndex (4 ), 13 );
135+ }
136+
137+ @ Test (expected = NotImplementedException .class )
138+ public void preAggDenseNonContiguous (){
139+ AMapToData d = MapToFactory .create (new int [] {10 ,9 ,8 ,7 ,6 ,5 ,4 ,3 ,2 ,1 }, 11 );
140+ MatrixBlock mb = new MatrixBlock ();
141+ MatrixBlock spy = spy (mb );
142+ DenseBlock db = mock (DenseBlock .class );
143+ when (db .isContiguous ()).thenReturn (false );
144+ when (spy .getDenseBlock ()).thenReturn (db );
145+
146+ d .preAggregateDense (spy , null , 10 , 13 ,0 , 10 );
147+ }
148+
52149}
0 commit comments