Skip to content

Commit 0f5ad69

Browse files
committed
fix sampler incompleteness and test
1 parent 13d4924 commit 0f5ad69

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/commonMain/kotlin/ai/hypergraph/kaliningraph/sampling/Samplers.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ class BigLFSR(primitivePoly: BigInteger, val start: BigInteger = BigInteger.ONE)
292292

293293
fun sequence() = sequence {
294294
var last = start
295+
yield(last)
295296
var next: BigInteger
296297
while (true) {
297298
val shiftedOutA1: Boolean = last.bitAt(0)

src/commonTest/kotlin/ai/hypergraph/kaliningraph/parsing/SetValiantTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ai.hypergraph.kaliningraph.parsing
33
import Grammars
44
import Grammars.toyArith
55
import ai.hypergraph.kaliningraph.*
6+
import ai.hypergraph.kaliningraph.types.*
67
import ai.hypergraph.kaliningraph.repair.vanillaS2PCFG
78
import ai.hypergraph.kaliningraph.tensor.seekFixpoint
89
import ai.hypergraph.kaliningraph.types.π2
@@ -15,6 +16,20 @@ import kotlin.time.*
1516
./gradlew jvmTest --tests "ai.hypergraph.kaliningraph.parsing.SetValiantTest"
1617
*/
1718
class SetValiantTest {
19+
/*
20+
./gradlew jvmTest --tests "ai.hypergraph.kaliningraph.parsing.SetValiantTest.testCompleteness"
21+
*/
22+
@Test
23+
fun testCompleteness() {
24+
val g = Grammars.toyArith
25+
val sols = g.enumSeq("_ + _".tokenizeByWhitespace()).toSet()
26+
27+
val all = g.terminals.filter { it.all { it.isLetterOrDigit() && it.code < 128 } }
28+
.toSet().let { it * it }.map { (a, b) -> "$a + $b" }.toSet()
29+
30+
assertEquals(all, sols)
31+
}
32+
1833
/*
1934
./gradlew jvmTest --tests "ai.hypergraph.kaliningraph.parsing.SetValiantTest.testStressRecognizer"
2035
*/

0 commit comments

Comments
 (0)