5
5
import org .assertj .core .api .Assertions ;
6
6
import org .junit .Test ;
7
7
import org .tensorics .core .lang .Tensorics ;
8
- import org .tensorics .core .tensor .ImmutableScalar ;
9
8
import org .tensorics .core .tensor .Scalar ;
10
9
import org .tensorics .core .tensor .Tensor ;
11
10
import org .tensorics .core .tensorbacked .AbstractTensorbacked ;
12
11
import org .tensorics .core .tensorbacked .TensorbackedInternals ;
13
12
import org .tensorics .core .tensorbacked .annotation .Dimensions ;
14
13
14
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
15
15
import static org .tensorics .core .lang .Tensorics .at ;
16
16
17
17
public class NestingTest {
18
18
19
19
@ Test
20
- public void mapoutTensorWorks () {
20
+ public void nestmapTensorWorks () {
21
21
AnInheritedTensorbacked val = Tensorics .builderFor (AnInheritedTensorbacked .class )//
22
22
.put (at ("A" , 1 ), 0.11 )//
23
23
.put (at ("B" , 1 ), 0.21 )
24
24
.put (at ("A" , 2 ), 0.12 )//
25
25
.put (at ("B" , 2 ), 0.22 )
26
26
.build ();
27
27
28
- Object nested = TensorbackedGsonAdapter .nested (val .tensor (), TensorbackedInternals .dimensionListFrom (AnInheritedTensorbacked .class ));
28
+ Object nested = TensorbackedGsonAdapter .nestmap (val .tensor (), TensorbackedInternals .dimensionListFrom (AnInheritedTensorbacked .class ));
29
29
30
30
Assertions .assertThat (nested ).isEqualTo (ImmutableMap .of (
31
31
"A" , ImmutableMap .of (1 , 0.11 , 2 , 0.12 ), //
@@ -35,27 +35,34 @@ public void mapoutTensorWorks() {
35
35
36
36
37
37
@ Test
38
- public void mapoutScalarIsPlain () {
38
+ public void nestmapScalarIsPlain () {
39
39
Scalar <Double > scalar = Tensorics .scalarOf (0.33 );
40
40
41
- Object nested = TensorbackedGsonAdapter .nested (scalar , ImmutableList .of ());
41
+ Object nested = TensorbackedGsonAdapter .nestmap (scalar , ImmutableList .of ());
42
42
Assertions .assertThat (nested ).isEqualTo (0.33 );
43
43
}
44
44
45
45
@ Dimensions ({String .class , Integer .class })
46
46
public static class AnInheritedTensorbacked extends AbstractTensorbacked <Double > {
47
-
48
47
public AnInheritedTensorbacked (Tensor <Double > tensor ) {
49
48
super (tensor );
50
49
}
51
-
52
50
}
53
51
52
+ /* XXX Is this the correct behaviour? */
54
53
@ Test
55
- public void mapoutEmptyTensorIsNull () {
54
+ public void nestmapEmptyTensorIsNull () {
56
55
Tensor <Object > empty = Tensorics .builder (String .class , Integer .class ).build ();
57
- Object nested = TensorbackedGsonAdapter .nested (empty , ImmutableList .of (String .class , Integer .class ));
56
+ Object nested = TensorbackedGsonAdapter .nestmap (empty , ImmutableList .of (String .class , Integer .class ));
58
57
Assertions .assertThat (nested ).isNull ();
59
58
}
60
59
60
+ @ Test
61
+ public void nestmapWrongDimensionAmountThrows () {
62
+ Tensor <Object > empty = Tensorics .builder (String .class , Integer .class ).build ();
63
+ assertThatThrownBy (() -> TensorbackedGsonAdapter .nestmap (empty , ImmutableList .of (Integer .class )))//
64
+ .isInstanceOf (IllegalArgumentException .class )
65
+ .hasMessageContaining ("do not match!" );
66
+ }
67
+
61
68
}
0 commit comments