Skip to content

Commit fe28c97

Browse files
Extract AbstractCliArgEnumTest base class for CliArg enum tests (#180)
Consolidate the four identical @test methods (testGetArgValue, testEnumCount, testImplementsCliArg, testArgValueNonEmpty) shared by seven parameterized CliArg enum tests into a generic base class. Each concrete test now provides only its @Parameterized.Parameters data and a constructor. Adds ReasoningFormatTest (ReasoningFormat implemented CliArg but had no test). Net: -224 LOC across 7 refactored tests + 1 new test + 1 new base class. https://claude.ai/code/session_01LCtDfZEtDv3wsJwerCybiN Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3d09e29 commit fe28c97

9 files changed

Lines changed: 144 additions & 284 deletions
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SPDX-FileCopyrightText: 2026 Bernard Ladenthin <bernard.ladenthin@gmail.com>
2+
// SPDX-FileCopyrightText: 2023-2025 Konstantin Herud
3+
//
4+
// SPDX-License-Identifier: MIT
5+
6+
package net.ladenthin.llama.args;
7+
8+
import org.junit.Test;
9+
10+
import static org.junit.Assert.assertEquals;
11+
import static org.junit.Assert.assertFalse;
12+
import static org.junit.Assert.assertNotNull;
13+
import static org.junit.Assert.assertTrue;
14+
15+
/**
16+
* Shared parameterized assertions for enums implementing {@link CliArg}.
17+
*
18+
* <p>Subclasses declare {@code @RunWith(Parameterized.class)} and provide a
19+
* {@code @Parameterized.Parameters} data method returning
20+
* {@code (enumConstant, expectedArgValue, expectedEnumCount)} rows.
21+
*/
22+
public abstract class AbstractCliArgEnumTest<E extends Enum<E> & CliArg> {
23+
24+
private final E value;
25+
private final String expectedArgValue;
26+
private final int expectedEnumCount;
27+
28+
protected AbstractCliArgEnumTest(E value, String expectedArgValue, int expectedEnumCount) {
29+
this.value = value;
30+
this.expectedArgValue = expectedArgValue;
31+
this.expectedEnumCount = expectedEnumCount;
32+
}
33+
34+
@Test
35+
public void testGetArgValue() {
36+
assertEquals(expectedArgValue, value.getArgValue());
37+
}
38+
39+
@Test
40+
public void testEnumCount() {
41+
assertEquals(expectedEnumCount, value.getDeclaringClass().getEnumConstants().length);
42+
}
43+
44+
@Test
45+
public void testImplementsCliArg() {
46+
assertTrue(value instanceof CliArg);
47+
}
48+
49+
@Test
50+
public void testArgValueNonEmpty() {
51+
assertNotNull(value.getArgValue());
52+
assertFalse(value.getArgValue().isEmpty());
53+
}
54+
}

src/test/java/net/ladenthin/llama/args/CacheTypeTest.java

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,31 @@
55

66
package net.ladenthin.llama.args;
77

8-
import org.junit.Test;
98
import org.junit.runner.RunWith;
109
import org.junit.runners.Parameterized;
1110

1211
import java.util.Arrays;
1312
import java.util.Collection;
1413

15-
import static org.junit.Assert.*;
16-
1714
@RunWith(Parameterized.class)
18-
public class CacheTypeTest {
15+
public class CacheTypeTest extends AbstractCliArgEnumTest<CacheType> {
1916

2017
@Parameterized.Parameters(name = "{0} -> {1}")
2118
public static Collection<Object[]> data() {
2219
return Arrays.asList(new Object[][]{
23-
{CacheType.F32, "f32"},
24-
{CacheType.F16, "f16"},
25-
{CacheType.BF16, "bf16"},
26-
{CacheType.Q8_0, "q8_0"},
27-
{CacheType.Q4_0, "q4_0"},
28-
{CacheType.Q4_1, "q4_1"},
29-
{CacheType.IQ4_NL, "iq4_nl"},
30-
{CacheType.Q5_0, "q5_0"},
31-
{CacheType.Q5_1, "q5_1"},
20+
{CacheType.F32, "f32", 9},
21+
{CacheType.F16, "f16", 9},
22+
{CacheType.BF16, "bf16", 9},
23+
{CacheType.Q8_0, "q8_0", 9},
24+
{CacheType.Q4_0, "q4_0", 9},
25+
{CacheType.Q4_1, "q4_1", 9},
26+
{CacheType.IQ4_NL, "iq4_nl", 9},
27+
{CacheType.Q5_0, "q5_0", 9},
28+
{CacheType.Q5_1, "q5_1", 9},
3229
});
3330
}
3431

35-
private final CacheType cacheType;
36-
private final String expectedArgValue;
37-
38-
public CacheTypeTest(CacheType cacheType, String expectedArgValue) {
39-
this.cacheType = cacheType;
40-
this.expectedArgValue = expectedArgValue;
41-
}
42-
43-
@Test
44-
public void testGetArgValue() {
45-
assertEquals(expectedArgValue, cacheType.getArgValue());
46-
}
47-
48-
// ------------------------------------------------------------------
49-
// Structural invariants — tested separately from the per-value check
50-
// ------------------------------------------------------------------
51-
52-
@Test
53-
public void testEnumCount() {
54-
assertEquals(9, CacheType.values().length);
55-
}
56-
57-
@Test
58-
public void testImplementsCliArg() {
59-
assertTrue(cacheType instanceof CliArg);
60-
}
61-
62-
@Test
63-
public void testArgValueNonEmpty() {
64-
assertNotNull(cacheType.getArgValue());
65-
assertFalse(cacheType.getArgValue().isEmpty());
32+
public CacheTypeTest(CacheType value, String expectedArgValue, int expectedEnumCount) {
33+
super(value, expectedArgValue, expectedEnumCount);
6634
}
6735
}

src/test/java/net/ladenthin/llama/args/GpuSplitModeTest.java

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,25 @@
55

66
package net.ladenthin.llama.args;
77

8-
import org.junit.Test;
98
import org.junit.runner.RunWith;
109
import org.junit.runners.Parameterized;
1110

1211
import java.util.Arrays;
1312
import java.util.Collection;
1413

15-
import static org.junit.Assert.*;
16-
1714
@RunWith(Parameterized.class)
18-
public class GpuSplitModeTest {
15+
public class GpuSplitModeTest extends AbstractCliArgEnumTest<GpuSplitMode> {
1916

2017
@Parameterized.Parameters(name = "{0} -> {1}")
2118
public static Collection<Object[]> data() {
2219
return Arrays.asList(new Object[][]{
23-
{GpuSplitMode.NONE, "none"},
24-
{GpuSplitMode.LAYER, "layer"},
25-
{GpuSplitMode.ROW, "row"},
20+
{GpuSplitMode.NONE, "none", 3},
21+
{GpuSplitMode.LAYER, "layer", 3},
22+
{GpuSplitMode.ROW, "row", 3},
2623
});
2724
}
2825

29-
private final GpuSplitMode gpuSplitMode;
30-
private final String expectedArgValue;
31-
32-
public GpuSplitModeTest(GpuSplitMode gpuSplitMode, String expectedArgValue) {
33-
this.gpuSplitMode = gpuSplitMode;
34-
this.expectedArgValue = expectedArgValue;
35-
}
36-
37-
@Test
38-
public void testGetArgValue() {
39-
assertEquals(expectedArgValue, gpuSplitMode.getArgValue());
40-
}
41-
42-
// ------------------------------------------------------------------
43-
// Structural invariants
44-
// ------------------------------------------------------------------
45-
46-
@Test
47-
public void testEnumCount() {
48-
assertEquals(3, GpuSplitMode.values().length);
49-
}
50-
51-
@Test
52-
public void testImplementsCliArg() {
53-
assertTrue(gpuSplitMode instanceof CliArg);
54-
}
55-
56-
@Test
57-
public void testArgValueNonEmpty() {
58-
assertNotNull(gpuSplitMode.getArgValue());
59-
assertFalse(gpuSplitMode.getArgValue().isEmpty());
26+
public GpuSplitModeTest(GpuSplitMode value, String expectedArgValue, int expectedEnumCount) {
27+
super(value, expectedArgValue, expectedEnumCount);
6028
}
6129
}

src/test/java/net/ladenthin/llama/args/MiroStatTest.java

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,25 @@
55

66
package net.ladenthin.llama.args;
77

8-
import org.junit.Test;
98
import org.junit.runner.RunWith;
109
import org.junit.runners.Parameterized;
1110

1211
import java.util.Arrays;
1312
import java.util.Collection;
1413

15-
import static org.junit.Assert.*;
16-
1714
@RunWith(Parameterized.class)
18-
public class MiroStatTest {
15+
public class MiroStatTest extends AbstractCliArgEnumTest<MiroStat> {
1916

2017
@Parameterized.Parameters(name = "{0} -> {1}")
2118
public static Collection<Object[]> data() {
2219
return Arrays.asList(new Object[][]{
23-
{MiroStat.DISABLED, "0"},
24-
{MiroStat.V1, "1"},
25-
{MiroStat.V2, "2"},
20+
{MiroStat.DISABLED, "0", 3},
21+
{MiroStat.V1, "1", 3},
22+
{MiroStat.V2, "2", 3},
2623
});
2724
}
2825

29-
private final MiroStat miroStat;
30-
private final String expectedArgValue;
31-
32-
public MiroStatTest(MiroStat miroStat, String expectedArgValue) {
33-
this.miroStat = miroStat;
34-
this.expectedArgValue = expectedArgValue;
35-
}
36-
37-
@Test
38-
public void testGetArgValue() {
39-
assertEquals(expectedArgValue, miroStat.getArgValue());
40-
}
41-
42-
// ------------------------------------------------------------------
43-
// Structural invariants
44-
// ------------------------------------------------------------------
45-
46-
@Test
47-
public void testEnumCount() {
48-
assertEquals(3, MiroStat.values().length);
49-
}
50-
51-
@Test
52-
public void testImplementsCliArg() {
53-
assertTrue(miroStat instanceof CliArg);
54-
}
55-
56-
@Test
57-
public void testArgValueNonEmpty() {
58-
assertNotNull(miroStat.getArgValue());
59-
assertFalse(miroStat.getArgValue().isEmpty());
26+
public MiroStatTest(MiroStat value, String expectedArgValue, int expectedEnumCount) {
27+
super(value, expectedArgValue, expectedEnumCount);
6028
}
6129
}

src/test/java/net/ladenthin/llama/args/NumaStrategyTest.java

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,25 @@
55

66
package net.ladenthin.llama.args;
77

8-
import org.junit.Test;
98
import org.junit.runner.RunWith;
109
import org.junit.runners.Parameterized;
1110

1211
import java.util.Arrays;
1312
import java.util.Collection;
1413

15-
import static org.junit.Assert.*;
16-
1714
@RunWith(Parameterized.class)
18-
public class NumaStrategyTest {
15+
public class NumaStrategyTest extends AbstractCliArgEnumTest<NumaStrategy> {
1916

2017
@Parameterized.Parameters(name = "{0} -> {1}")
2118
public static Collection<Object[]> data() {
2219
return Arrays.asList(new Object[][]{
23-
{NumaStrategy.DISTRIBUTE, "distribute"},
24-
{NumaStrategy.ISOLATE, "isolate"},
25-
{NumaStrategy.NUMACTL, "numactl"},
20+
{NumaStrategy.DISTRIBUTE, "distribute", 3},
21+
{NumaStrategy.ISOLATE, "isolate", 3},
22+
{NumaStrategy.NUMACTL, "numactl", 3},
2623
});
2724
}
2825

29-
private final NumaStrategy numaStrategy;
30-
private final String expectedArgValue;
31-
32-
public NumaStrategyTest(NumaStrategy numaStrategy, String expectedArgValue) {
33-
this.numaStrategy = numaStrategy;
34-
this.expectedArgValue = expectedArgValue;
35-
}
36-
37-
@Test
38-
public void testGetArgValue() {
39-
assertEquals(expectedArgValue, numaStrategy.getArgValue());
40-
}
41-
42-
// ------------------------------------------------------------------
43-
// Structural invariants
44-
// ------------------------------------------------------------------
45-
46-
@Test
47-
public void testEnumCount() {
48-
assertEquals(3, NumaStrategy.values().length);
49-
}
50-
51-
@Test
52-
public void testImplementsCliArg() {
53-
assertTrue(numaStrategy instanceof CliArg);
54-
}
55-
56-
@Test
57-
public void testArgValueNonEmpty() {
58-
assertNotNull(numaStrategy.getArgValue());
59-
assertFalse(numaStrategy.getArgValue().isEmpty());
26+
public NumaStrategyTest(NumaStrategy value, String expectedArgValue, int expectedEnumCount) {
27+
super(value, expectedArgValue, expectedEnumCount);
6028
}
6129
}

src/test/java/net/ladenthin/llama/args/PoolingTypeTest.java

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,28 @@
55

66
package net.ladenthin.llama.args;
77

8-
import org.junit.Test;
98
import org.junit.runner.RunWith;
109
import org.junit.runners.Parameterized;
1110

1211
import java.util.Arrays;
1312
import java.util.Collection;
1413

15-
import static org.junit.Assert.*;
16-
1714
@RunWith(Parameterized.class)
18-
public class PoolingTypeTest {
15+
public class PoolingTypeTest extends AbstractCliArgEnumTest<PoolingType> {
1916

2017
@Parameterized.Parameters(name = "{0} -> {1}")
2118
public static Collection<Object[]> data() {
2219
return Arrays.asList(new Object[][]{
23-
{PoolingType.UNSPECIFIED, "unspecified"},
24-
{PoolingType.NONE, "none"},
25-
{PoolingType.MEAN, "mean"},
26-
{PoolingType.CLS, "cls"},
27-
{PoolingType.LAST, "last"},
28-
{PoolingType.RANK, "rank"},
20+
{PoolingType.UNSPECIFIED, "unspecified", 6},
21+
{PoolingType.NONE, "none", 6},
22+
{PoolingType.MEAN, "mean", 6},
23+
{PoolingType.CLS, "cls", 6},
24+
{PoolingType.LAST, "last", 6},
25+
{PoolingType.RANK, "rank", 6},
2926
});
3027
}
3128

32-
private final PoolingType poolingType;
33-
private final String expectedArgValue;
34-
35-
public PoolingTypeTest(PoolingType poolingType, String expectedArgValue) {
36-
this.poolingType = poolingType;
37-
this.expectedArgValue = expectedArgValue;
38-
}
39-
40-
@Test
41-
public void testGetArgValue() {
42-
assertEquals(expectedArgValue, poolingType.getArgValue());
43-
}
44-
45-
// ------------------------------------------------------------------
46-
// Structural invariants
47-
// ------------------------------------------------------------------
48-
49-
@Test
50-
public void testEnumCount() {
51-
assertEquals(6, PoolingType.values().length);
52-
}
53-
54-
@Test
55-
public void testImplementsCliArg() {
56-
assertTrue(poolingType instanceof CliArg);
57-
}
58-
59-
@Test
60-
public void testArgValueNonEmpty() {
61-
assertNotNull(poolingType.getArgValue());
62-
assertFalse(poolingType.getArgValue().isEmpty());
29+
public PoolingTypeTest(PoolingType value, String expectedArgValue, int expectedEnumCount) {
30+
super(value, expectedArgValue, expectedEnumCount);
6331
}
6432
}

0 commit comments

Comments
 (0)