From 0f5ad6951c85a1b151e943d6e6811e9c1de0c5d9 Mon Sep 17 00:00:00 2001 From: breandan Date: Sun, 15 Dec 2024 19:50:52 -0500 Subject: [PATCH] fix sampler incompleteness and test --- .../hypergraph/kaliningraph/sampling/Samplers.kt | 1 + .../kaliningraph/parsing/SetValiantTest.kt | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/commonMain/kotlin/ai/hypergraph/kaliningraph/sampling/Samplers.kt b/src/commonMain/kotlin/ai/hypergraph/kaliningraph/sampling/Samplers.kt index 8b5fb0af..655dbdf1 100644 --- a/src/commonMain/kotlin/ai/hypergraph/kaliningraph/sampling/Samplers.kt +++ b/src/commonMain/kotlin/ai/hypergraph/kaliningraph/sampling/Samplers.kt @@ -292,6 +292,7 @@ class BigLFSR(primitivePoly: BigInteger, val start: BigInteger = BigInteger.ONE) fun sequence() = sequence { var last = start + yield(last) var next: BigInteger while (true) { val shiftedOutA1: Boolean = last.bitAt(0) diff --git a/src/commonTest/kotlin/ai/hypergraph/kaliningraph/parsing/SetValiantTest.kt b/src/commonTest/kotlin/ai/hypergraph/kaliningraph/parsing/SetValiantTest.kt index acf3a149..b5342c3e 100644 --- a/src/commonTest/kotlin/ai/hypergraph/kaliningraph/parsing/SetValiantTest.kt +++ b/src/commonTest/kotlin/ai/hypergraph/kaliningraph/parsing/SetValiantTest.kt @@ -3,6 +3,7 @@ package ai.hypergraph.kaliningraph.parsing import Grammars import Grammars.toyArith import ai.hypergraph.kaliningraph.* +import ai.hypergraph.kaliningraph.types.* import ai.hypergraph.kaliningraph.repair.vanillaS2PCFG import ai.hypergraph.kaliningraph.tensor.seekFixpoint import ai.hypergraph.kaliningraph.types.π2 @@ -15,6 +16,20 @@ import kotlin.time.* ./gradlew jvmTest --tests "ai.hypergraph.kaliningraph.parsing.SetValiantTest" */ class SetValiantTest { +/* +./gradlew jvmTest --tests "ai.hypergraph.kaliningraph.parsing.SetValiantTest.testCompleteness" +*/ + @Test + fun testCompleteness() { + val g = Grammars.toyArith + val sols = g.enumSeq("_ + _".tokenizeByWhitespace()).toSet() + + val all = g.terminals.filter { it.all { it.isLetterOrDigit() && it.code < 128 } } + .toSet().let { it * it }.map { (a, b) -> "$a + $b" }.toSet() + + assertEquals(all, sols) + } + /* ./gradlew jvmTest --tests "ai.hypergraph.kaliningraph.parsing.SetValiantTest.testStressRecognizer" */