1919
2020public class ClassificationTests extends AbstractSerializingTestCase <Classification > {
2121
22+ private static final BoostedTreeParams BOOSTED_TREE_PARAMS = new BoostedTreeParams (0.0 , 0.0 , 0.5 , 500 , 1.0 );
23+
2224 @ Override
2325 protected Classification doParseInstance (XContentParser parser ) throws IOException {
2426 return Classification .fromXContent (parser , false );
@@ -43,32 +45,68 @@ protected Writeable.Reader<Classification> instanceReader() {
4345 return Classification ::new ;
4446 }
4547
46- public void testConstructor_GivenTrainingPercentIsNull () {
47- Classification classification = new Classification ("foo" , new BoostedTreeParams (0.0 , 0.0 , 0.5 , 500 , 1.0 ), "result" , 3 , null );
48- assertThat (classification .getTrainingPercent (), equalTo (100.0 ));
49- }
50-
51- public void testConstructor_GivenTrainingPercentIsBoundary () {
52- Classification classification = new Classification ("foo" , new BoostedTreeParams (0.0 , 0.0 , 0.5 , 500 , 1.0 ), "result" , 3 , 1.0 );
53- assertThat (classification .getTrainingPercent (), equalTo (1.0 ));
54- classification = new Classification ("foo" , new BoostedTreeParams (0.0 , 0.0 , 0.5 , 500 , 1.0 ), "result" , 3 , 100.0 );
55- assertThat (classification .getTrainingPercent (), equalTo (100.0 ));
56- }
57-
5848 public void testConstructor_GivenTrainingPercentIsLessThanOne () {
5949 ElasticsearchStatusException e = expectThrows (ElasticsearchStatusException .class ,
60- () -> new Classification ("foo" , new BoostedTreeParams ( 0.0 , 0.0 , 0.5 , 500 , 1.0 ) , "result" , 3 , 0.999 ));
50+ () -> new Classification ("foo" , BOOSTED_TREE_PARAMS , "result" , 3 , 0.999 ));
6151
6252 assertThat (e .getMessage (), equalTo ("[training_percent] must be a double in [1, 100]" ));
6353 }
6454
6555 public void testConstructor_GivenTrainingPercentIsGreaterThan100 () {
6656 ElasticsearchStatusException e = expectThrows (ElasticsearchStatusException .class ,
67- () -> new Classification ("foo" , new BoostedTreeParams ( 0.0 , 0.0 , 0.5 , 500 , 1.0 ) , "result" , 3 , 100.0001 ));
57+ () -> new Classification ("foo" , BOOSTED_TREE_PARAMS , "result" , 3 , 100.0001 ));
6858
6959 assertThat (e .getMessage (), equalTo ("[training_percent] must be a double in [1, 100]" ));
7060 }
7161
62+ public void testConstructor_GivenNumTopClassesIsLessThanZero () {
63+ ElasticsearchStatusException e = expectThrows (ElasticsearchStatusException .class ,
64+ () -> new Classification ("foo" , BOOSTED_TREE_PARAMS , "result" , -1 , 1.0 ));
65+
66+ assertThat (e .getMessage (), equalTo ("[num_top_classes] must be an integer in [0, 1000]" ));
67+ }
68+
69+ public void testConstructor_GivenNumTopClassesIsGreaterThan1000 () {
70+ ElasticsearchStatusException e = expectThrows (ElasticsearchStatusException .class ,
71+ () -> new Classification ("foo" , BOOSTED_TREE_PARAMS , "result" , 1001 , 1.0 ));
72+
73+ assertThat (e .getMessage (), equalTo ("[num_top_classes] must be an integer in [0, 1000]" ));
74+ }
75+
76+ public void testGetNumTopClasses () {
77+ Classification classification = new Classification ("foo" , BOOSTED_TREE_PARAMS , "result" , 7 , 1.0 );
78+ assertThat (classification .getNumTopClasses (), equalTo (7 ));
79+
80+ // Boundary condition: num_top_classes == 0
81+ classification = new Classification ("foo" , BOOSTED_TREE_PARAMS , "result" , 0 , 1.0 );
82+ assertThat (classification .getNumTopClasses (), equalTo (0 ));
83+
84+ // Boundary condition: num_top_classes == 1000
85+ classification = new Classification ("foo" , BOOSTED_TREE_PARAMS , "result" , 1000 , 1.0 );
86+ assertThat (classification .getNumTopClasses (), equalTo (1000 ));
87+
88+ // num_top_classes == null, default applied
89+ classification = new Classification ("foo" , BOOSTED_TREE_PARAMS , "result" , null , 1.0 );
90+ assertThat (classification .getNumTopClasses (), equalTo (2 ));
91+ }
92+
93+ public void testGetTrainingPercent () {
94+ Classification classification = new Classification ("foo" , BOOSTED_TREE_PARAMS , "result" , 3 , 50.0 );
95+ assertThat (classification .getTrainingPercent (), equalTo (50.0 ));
96+
97+ // Boundary condition: training_percent == 1.0
98+ classification = new Classification ("foo" , BOOSTED_TREE_PARAMS , "result" , 3 , 1.0 );
99+ assertThat (classification .getTrainingPercent (), equalTo (1.0 ));
100+
101+ // Boundary condition: training_percent == 100.0
102+ classification = new Classification ("foo" , BOOSTED_TREE_PARAMS , "result" , 3 , 100.0 );
103+ assertThat (classification .getTrainingPercent (), equalTo (100.0 ));
104+
105+ // training_percent == null, default applied
106+ classification = new Classification ("foo" , BOOSTED_TREE_PARAMS , "result" , 3 , null );
107+ assertThat (classification .getTrainingPercent (), equalTo (100.0 ));
108+ }
109+
72110 public void testFieldCardinalityLimitsIsNonNull () {
73111 assertThat (createTestInstance ().getFieldCardinalityLimits (), is (not (nullValue ())));
74112 }
0 commit comments