|
| 1 | +package agents_engine.generation |
| 2 | + |
| 3 | +import kotlin.test.Test |
| 4 | +import kotlin.test.assertEquals |
| 5 | +import kotlin.test.assertNotNull |
| 6 | +import kotlin.test.assertNull |
| 7 | +import kotlin.test.assertTrue |
| 8 | + |
| 9 | +// Tests for #885 — coverage gaps in GenerableSupport identified by PIT NO_COVERAGE. |
| 10 | +// |
| 11 | +// Three areas: |
| 12 | +// 1. coerceToInt — Float input branches (lines 340-345) |
| 13 | +// 2. coerceToLong — Float input branches (lines 366-371) |
| 14 | +// 3. promptTypeName — List<T> recursion and KClass<*> simpleName fallback (lines 215-219) |
| 15 | +// |
| 16 | +// Reuses IntBox / LongBox fixtures from CoerceValueOverflowTest (in the same |
| 17 | +// package and source set). |
| 18 | + |
| 19 | +class GenerableSupportCoverageTest { |
| 20 | + |
| 21 | + // coerceToInt — Float input |
| 22 | + |
| 23 | + @Test |
| 24 | + fun `Int field accepts in-range whole-number Float`() { |
| 25 | + val r = IntBox::class.constructFromMap(mapOf("n" to 42.0f)) |
| 26 | + assertNotNull(r) |
| 27 | + assertEquals(42, r!!.n) |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + fun `Int field rejects fractional Float`() { |
| 32 | + assertNull(IntBox::class.constructFromMap(mapOf("n" to 1.5f))) |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + fun `Int field rejects out-of-range Float`() { |
| 37 | + // 1e10 > Int.MAX_VALUE (~2.1e9) |
| 38 | + assertNull(IntBox::class.constructFromMap(mapOf("n" to 1.0e10f))) |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + fun `Int field rejects NaN Float`() { |
| 43 | + assertNull(IntBox::class.constructFromMap(mapOf("n" to Float.NaN))) |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + fun `Int field rejects Infinity Float`() { |
| 48 | + assertNull(IntBox::class.constructFromMap(mapOf("n" to Float.POSITIVE_INFINITY))) |
| 49 | + assertNull(IntBox::class.constructFromMap(mapOf("n" to Float.NEGATIVE_INFINITY))) |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + fun `Int field accepts Short input`() { |
| 54 | + val r = IntBox::class.constructFromMap(mapOf("n" to 7.toShort())) |
| 55 | + assertNotNull(r) |
| 56 | + assertEquals(7, r!!.n) |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + fun `Int field accepts Byte input`() { |
| 61 | + val r = IntBox::class.constructFromMap(mapOf("n" to 5.toByte())) |
| 62 | + assertNotNull(r) |
| 63 | + assertEquals(5, r!!.n) |
| 64 | + } |
| 65 | + |
| 66 | + // coerceToLong — Float input |
| 67 | + |
| 68 | + @Test |
| 69 | + fun `Long field accepts in-range whole-number Float`() { |
| 70 | + val r = LongBox::class.constructFromMap(mapOf("n" to 1000.0f)) |
| 71 | + assertNotNull(r) |
| 72 | + assertEquals(1000L, r!!.n) |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + fun `Long field rejects fractional Float`() { |
| 77 | + assertNull(LongBox::class.constructFromMap(mapOf("n" to 1.5f))) |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + fun `Long field rejects NaN Float`() { |
| 82 | + assertNull(LongBox::class.constructFromMap(mapOf("n" to Float.NaN))) |
| 83 | + } |
| 84 | + |
| 85 | + @Test |
| 86 | + fun `Long field rejects Infinity Float`() { |
| 87 | + assertNull(LongBox::class.constructFromMap(mapOf("n" to Float.POSITIVE_INFINITY))) |
| 88 | + assertNull(LongBox::class.constructFromMap(mapOf("n" to Float.NEGATIVE_INFINITY))) |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + fun `Long field accepts Short input`() { |
| 93 | + val r = LongBox::class.constructFromMap(mapOf("n" to 7.toShort())) |
| 94 | + assertNotNull(r) |
| 95 | + assertEquals(7L, r!!.n) |
| 96 | + } |
| 97 | + |
| 98 | + @Test |
| 99 | + fun `Long field accepts Byte input`() { |
| 100 | + val r = LongBox::class.constructFromMap(mapOf("n" to 5.toByte())) |
| 101 | + assertNotNull(r) |
| 102 | + assertEquals(5L, r!!.n) |
| 103 | + } |
| 104 | + |
| 105 | + // promptTypeName — List<T> branch and nested-Generable branch |
| 106 | + |
| 107 | + @Test |
| 108 | + fun `promptFragment renders List of primitives as List of T`() { |
| 109 | + // TaggedResult is from GenerableTest.kt: data class TaggedResult(@Guide val tags: List<String>, val count: Int) |
| 110 | + val out = TaggedResult::class.promptFragment() |
| 111 | + assertTrue( |
| 112 | + out.contains("<List<String>"), |
| 113 | + "List<String> should render as List<String> type name; got:\n$out", |
| 114 | + ) |
| 115 | + } |
| 116 | + |
| 117 | + @Test |
| 118 | + fun `promptFragment renders nested Generable as its simpleName`() { |
| 119 | + // NestedResult is from GenerableTest.kt: data class NestedResult(@Guide val inner: ScoreResult, val label: String) |
| 120 | + val out = NestedResult::class.promptFragment() |
| 121 | + assertTrue( |
| 122 | + out.contains("ScoreResult"), |
| 123 | + "Nested @Generable should render with its simpleName; got:\n$out", |
| 124 | + ) |
| 125 | + } |
| 126 | +} |
0 commit comments