Skip to content

Commit 5873d3e

Browse files
committed
feat(221): Comprehensive test refactoring
- Move SharedParsingTests.fs to FLPQ.TestUtilities/ParsingTestCases.fs with extended AcceptanceCase type and auto-generated cases from LanguageRegistry - Refactor GllTests.fs and RnglrTests.fs to use shared cases + direct registry access, eliminating all TestGrammars dependencies - Create CrossParserEquivalenceTests.fs consolidating all pairwise equivalence tests (GLL vs CYK, RNGLR vs CYK, GLL vs RNGLR, Vs DFA) - Fix broken GLL vs RNGLR and RNGLR vs CYK equivalence tests - Remove TestGrammars from CykTests, LLParserTests, LRParserTests, ValiantTests, StressTests, RsmToGrammarTests, EbnfParserTests - Consolidate string generators: add GenToArbitrary bridge in LanguageRegistry.fs, remove duplicated generators from Generators.fs - Delete TestGrammars.fs (replaced by direct LanguageRegistry access) - Add LanguageRegistry.findGrammar helper - Add xunit package to FLPQ.TestUtilities - 445 FLPQ.Languages.Tests pass, zero failures
1 parent e52c9f2 commit 5873d3e

16 files changed

Lines changed: 488 additions & 817 deletions
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
module CrossParserEquivalenceTests
2+
3+
open Xunit
4+
open FsCheck
5+
open FsCheck.Xunit
6+
open FLPQ.Languages
7+
open FLPQ.LinearAlgebra
8+
open FLPQ.TestUtilities
9+
10+
let private dyck1 = LanguageRegistry.Dyck1
11+
let private aplus = LanguageRegistry.APlus
12+
13+
module VsCyk =
14+
15+
[<Properties(Arbitrary = [| typeof<GenToArbitrary.AbString> |])>]
16+
module GllVsCyk =
17+
[<Property>]
18+
let ``GLL and CYK agree on Dyck1 grammar1`` (s: string) =
19+
let g = dyck1.Grammars[0].Grammar
20+
let input = TestHelpers.stringToTerminals s
21+
let gllAccepts = TestHelpers.accepts GLL.buildPathIndex PathIndex.isAccepted
22+
gllAccepts (TestHelpers.grammarToRsm g) input = TestHelpers.cykAccepts g input
23+
24+
[<Property>]
25+
let ``GLL and CYK agree on Dyck1 grammar2`` (s: string) =
26+
let g = dyck1.Grammars[1].Grammar
27+
let input = TestHelpers.stringToTerminals s
28+
let gllAccepts = TestHelpers.accepts GLL.buildPathIndex PathIndex.isAccepted
29+
gllAccepts (TestHelpers.grammarToRsm g) input = TestHelpers.cykAccepts g input
30+
31+
[<Properties(Arbitrary = [| typeof<GenToArbitrary.AString> |])>]
32+
module GllVsCykAplus =
33+
[<Property>]
34+
let ``GLL and CYK agree on APlus grammar3`` (s: string) =
35+
let g = aplus.Grammars[0].Grammar
36+
let input = TestHelpers.stringToTerminals s
37+
let gllAccepts = TestHelpers.accepts GLL.buildPathIndex PathIndex.isAccepted
38+
gllAccepts (TestHelpers.grammarToRsm g) input = TestHelpers.cykAccepts g input
39+
40+
[<Property>]
41+
let ``GLL and CYK agree on APlus grammar4`` (s: string) =
42+
let g = aplus.Grammars[1].Grammar
43+
let input = TestHelpers.stringToTerminals s
44+
let gllAccepts = TestHelpers.accepts GLL.buildPathIndex PathIndex.isAccepted
45+
gllAccepts (TestHelpers.grammarToRsm g) input = TestHelpers.cykAccepts g input
46+
47+
[<Properties(Arbitrary = [| typeof<GenToArbitrary.AbString> |])>]
48+
module RnglrVsCyk =
49+
[<Property>]
50+
let ``RNGLR and CYK agree on Dyck1 grammar1`` (s: string) =
51+
let g = dyck1.Grammars[0].Grammar
52+
let input = s.Replace(" ", "") |> TestHelpers.stringToTerminals
53+
let rnglrAccepts = TestHelpers.accepts Rnglr.buildPathIndex PathIndex.isAccepted
54+
rnglrAccepts (TestHelpers.grammarToRsm g) input = TestHelpers.cykAccepts g input
55+
56+
[<Properties(Arbitrary = [| typeof<GenToArbitrary.AString> |])>]
57+
module RnglrVsCykAplus =
58+
[<Property>]
59+
let ``RNGLR and CYK agree on APlus grammar3`` (s: string) =
60+
let g = aplus.Grammars[0].Grammar
61+
let input = s.Replace(" ", "") |> TestHelpers.stringToTerminals
62+
let rnglrAccepts = TestHelpers.accepts Rnglr.buildPathIndex PathIndex.isAccepted
63+
rnglrAccepts (TestHelpers.grammarToRsm g) input = TestHelpers.cykAccepts g input
64+
65+
module GllVsRnglr =
66+
67+
[<Properties(Arbitrary = [| typeof<GenToArbitrary.AbString> |])>]
68+
module Dyck1 =
69+
[<Property>]
70+
let ``GLL and RNGLR agree on Dyck1 grammar1`` (s: string) =
71+
let g = dyck1.Grammars[0].Grammar
72+
let input = s.Replace(" ", "") |> TestHelpers.stringToTerminals
73+
let gllAccepts = TestHelpers.accepts GLL.buildPathIndex PathIndex.isAccepted
74+
let rnglrAccepts = TestHelpers.accepts Rnglr.buildPathIndex PathIndex.isAccepted
75+
gllAccepts (TestHelpers.grammarToRsm g) input = rnglrAccepts (TestHelpers.grammarToRsm g) input
76+
77+
[<Properties(Arbitrary = [| typeof<GenToArbitrary.AString> |])>]
78+
module APlus =
79+
[<Property>]
80+
let ``GLL and RNGLR agree on APlus grammar3`` (s: string) =
81+
let g = aplus.Grammars[0].Grammar
82+
let input = s.Replace(" ", "") |> TestHelpers.stringToTerminals
83+
let gllAccepts = TestHelpers.accepts GLL.buildPathIndex PathIndex.isAccepted
84+
let rnglrAccepts = TestHelpers.accepts Rnglr.buildPathIndex PathIndex.isAccepted
85+
gllAccepts (TestHelpers.grammarToRsm g) input = rnglrAccepts (TestHelpers.grammarToRsm g) input
86+
87+
module VsDfa =
88+
89+
[<Properties(Arbitrary = [| typeof<GenToArbitrary.AbcxdString> |])>]
90+
module GllVsDfa =
91+
[<Property(MaxTest = 50)>]
92+
let ``S -> a* matches DFA`` (s: string) =
93+
ParsingTestCases.Runners.runRegexEquivalenceTests
94+
(TestHelpers.accepts GLL.buildPathIndex PathIndex.isAccepted)
95+
(fun c -> c = "a")
96+
"a *"
97+
s
98+
99+
[<Property(MaxTest = 50)>]
100+
let ``S -> a* a* matches DFA`` (s: string) =
101+
ParsingTestCases.Runners.runRegexEquivalenceTests
102+
(TestHelpers.accepts GLL.buildPathIndex PathIndex.isAccepted)
103+
(fun c -> c = "a")
104+
"a * a *"
105+
s
106+
107+
[<Property(MaxTest = 50)>]
108+
let ``S -> (a | b)* matches DFA`` (s: string) =
109+
ParsingTestCases.Runners.runRegexEquivalenceTests
110+
(TestHelpers.accepts GLL.buildPathIndex PathIndex.isAccepted)
111+
(fun c -> c = "a" || c = "b")
112+
"( a | b ) *"
113+
s
114+
115+
[<Property(MaxTest = 50)>]
116+
let ``S -> (a | b)* (a | c)* matches DFA`` (s: string) =
117+
ParsingTestCases.Runners.runRegexEquivalenceTests
118+
(TestHelpers.accepts GLL.buildPathIndex PathIndex.isAccepted)
119+
(fun c -> c = "a" || c = "b" || c = "c")
120+
"( a | b ) * ( a | c ) *"
121+
s
122+
123+
[<Properties(Arbitrary = [| typeof<GenToArbitrary.AString> |])>]
124+
module RnglrVsDfaA =
125+
[<Property(MaxTest = 50)>]
126+
let ``S -> a* matches DFA`` (s: string) =
127+
ParsingTestCases.Runners.runRegexEquivalenceTests
128+
(TestHelpers.accepts Rnglr.buildPathIndex PathIndex.isAccepted)
129+
(fun c -> c = "a")
130+
"a *"
131+
s
132+
133+
[<Property(MaxTest = 50)>]
134+
let ``S -> a* a* matches DFA`` (s: string) =
135+
ParsingTestCases.Runners.runRegexEquivalenceTests
136+
(TestHelpers.accepts Rnglr.buildPathIndex PathIndex.isAccepted)
137+
(fun c -> c = "a")
138+
"a * a *"
139+
s
140+
141+
[<Properties(Arbitrary = [| typeof<GenToArbitrary.AbString> |])>]
142+
module RnglrVsDfaAb =
143+
[<Property(MaxTest = 50)>]
144+
let ``S -> (a | b)* matches DFA`` (s: string) =
145+
ParsingTestCases.Runners.runRegexEquivalenceTests
146+
(TestHelpers.accepts Rnglr.buildPathIndex PathIndex.isAccepted)
147+
(fun c -> c = "a" || c = "b")
148+
"( a | b ) *"
149+
s
150+
151+
[<Property(MaxTest = 50)>]
152+
let ``S -> (a | b)* (a | c)* matches DFA`` (s: string) =
153+
ParsingTestCases.Runners.runRegexEquivalenceTests
154+
(TestHelpers.accepts Rnglr.buildPathIndex PathIndex.isAccepted)
155+
(fun c -> c = "a" || c = "b" || c = "c")
156+
"( a | b ) * ( a | c ) *"
157+
s

tests/FLPQ.Languages.Tests/CykTests.fs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,23 @@ open FLPQ.Languages
77
open FLPQ.LinearAlgebra
88
open FLPQ.TestUtilities
99

10-
open TestGrammars
11-
12-
open TestGrammars
10+
let private g (lang: Language) (name: string) = lang.Grammars |> List.find (fun g -> g.Name = name)
11+
12+
let private dyck1 = LanguageRegistry.Dyck1
13+
let private aplus = LanguageRegistry.APlus
14+
let private expr = LanguageRegistry.ArithExpr
15+
let private twoTrack = LanguageRegistry.TwoTrackDyck
16+
17+
let private grammar1 = (g dyck1 "grammar1").Grammar
18+
let private grammar2 = (g dyck1 "grammar2").Grammar
19+
let private grammar3 = (g aplus "grammar3").Grammar
20+
let private grammar4 = (g aplus "grammar4").Grammar
21+
let private grammar5 = (g aplus "grammar5").Grammar
22+
let private grammar6 = (g expr "grammar6").Grammar
23+
let private grammar7 = (g expr "grammar7").Grammar
24+
let private grammar8 = (g expr "grammar8").Grammar
25+
let private grammar9 = (g twoTrack "grammar9").Grammar
26+
let private grammar10 = (g twoTrack "grammar10").Grammar
1327

1428
module Grammar1Tests =
1529

@@ -38,7 +52,7 @@ module Grammar1Tests =
3852

3953
module Grammar2Tests =
4054

41-
[<Properties(Arbitrary = [| typeof<AbStringGenerators> |])>]
55+
[<Properties(Arbitrary = [| typeof<GenToArbitrary.AbString> |])>]
4256
module Properties =
4357

4458
[<Property>]
@@ -76,7 +90,7 @@ module Grammar3Tests =
7690

7791
module Grammar4Tests =
7892

79-
[<Properties(Arbitrary = [| typeof<AStringGenerators> |])>]
93+
[<Properties(Arbitrary = [| typeof<GenToArbitrary.AString> |])>]
8094
module Properties =
8195

8296
[<Property>]
@@ -89,7 +103,7 @@ module Grammar4Tests =
89103

90104
module Grammar5Tests =
91105

92-
[<Properties(Arbitrary = [| typeof<AStringGenerators> |])>]
106+
[<Properties(Arbitrary = [| typeof<GenToArbitrary.AString> |])>]
93107
module Properties =
94108

95109
[<Property>]
@@ -152,7 +166,7 @@ module Grammar6Tests =
152166

153167
module Grammar6PropertyTests =
154168

155-
[<Properties(Arbitrary = [| typeof<ExprStringGenerators> |])>]
169+
[<Properties(Arbitrary = [| typeof<GenToArbitrary.ExprString> |])>]
156170
module AgreementTests =
157171

158172
[<Property>]

tests/FLPQ.Languages.Tests/EbnfParserTests.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ open FsCheck.Xunit
55
open FLPQ.Languages
66
open FLPQ.LinearAlgebra
77

8-
open TestGrammars
98
open FLPQ.TestUtilities
109

1110
module EbnfParseTests =
@@ -257,7 +256,7 @@ F -> x
257256

258257
module EbnfPropertyTests =
259258

260-
[<Properties(Arbitrary = [| typeof<AStringGenerators> |])>]
259+
[<Properties(Arbitrary = [| typeof<GenToArbitrary.AString> |])>]
261260
module ParsingEquivalenceTests =
262261

263262
[<Property>]

tests/FLPQ.Languages.Tests/FLPQ.Languages.Tests.fsproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<Compile Include="TestGrammars.fs" />
109
<Compile Include="TokenizerTests.fs" />
1110
<Compile Include="GrammarTests.fs" />
1211
<Compile Include="CykTests.fs" />
@@ -19,7 +18,7 @@
1918
<Compile Include="LLParserTests.fs" />
2019
<Compile Include="LRParserTests.fs" />
2120
<Compile Include="StressTests.fs" />
22-
<Compile Include="SharedParsingTests.fs" />
21+
<Compile Include="CrossParserEquivalenceTests.fs" />
2322
<Compile Include="GllTests.fs" />
2423
<Compile Include="RnglrTests.fs" />
2524
</ItemGroup>

0 commit comments

Comments
 (0)