Skip to content

Commit 3091ec8

Browse files
committed
Add unit test for the validation of parameter.p
This is a follow-up of 61a581c
1 parent 4c12094 commit 3091ec8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/test/java/de/bwaldvogel/liblinear/LinearTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,25 @@ void testTrain_IllegalParameters_RegularizeBias() {
344344
assertThat(model.bias).isEqualTo(1.0);
345345
}
346346

347+
@Test
348+
void testTrain_IllegalParameters_P() throws Exception {
349+
Problem prob = createRandomProblem(2);
350+
Parameter param = new Parameter(L2R_L2LOSS_SVR, 10, 0.1);
351+
param.p = -1;
352+
353+
assertThatExceptionOfType(IllegalArgumentException.class)
354+
.isThrownBy(() -> Linear.train(prob, param))
355+
.withMessage("p < 0");
356+
357+
// It must not fail for solvers other than L2R_L2LOSS_SVR
358+
for (SolverType solverType : values()) {
359+
if (solverType != L2R_L2LOSS_SVR) {
360+
param.solverType = solverType;
361+
Linear.train(prob, param);
362+
}
363+
}
364+
}
365+
347366
@Test
348367
void testTrain_IllegalParameters_InitialSol() {
349368
Problem prob = createRandomProblem(2);

0 commit comments

Comments
 (0)