11import qtil.results.LimitResults
2- import qtil.testing.Qnit
32import Bugs
43
54module TestConfig implements LimitResultsConfigSig< Bug , BugField > {
@@ -13,134 +12,6 @@ module TestConfig implements LimitResultsConfigSig<Bug, BugField> {
1312
1413module Results = LimitResults< Bug , BugField , TestConfig > ;
1514
16- /** BugA has 1 field (X), which is fewer than maxResults=3 (default), so all results are shown. */
17- class TestBugAResultCount extends Test , Case {
18- override predicate run ( Qnit test ) {
19- if count ( BugField f , string msg | Results:: hasLimitedResult ( any ( Bug b | b = TBugA ( ) ) , f , msg ) ) =
20- 1
21- then test .pass ( "BugA: 1 result shown (fewer than maxResults)" )
22- else test .fail ( "BugA: wrong result count" )
23- }
24- }
25-
26- /** BugA shows field X with no suffix since total <= maxResults. */
27- class TestBugANoSuffix extends Test , Case {
28- override predicate run ( Qnit test ) {
29- if
30- exists ( BugField f , string msg |
31- Results:: hasLimitedResult ( any ( Bug b | b = TBugA ( ) ) , f , msg ) and
32- f .getFieldName ( ) = "X" and
33- msg = "BugA has field X"
34- )
35- then test .pass ( "BugA: correct message with no suffix" )
36- else test .fail ( "BugA: message incorrect" )
37- }
38- }
39-
40- /** BugB has 3 fields (A, B, C), exactly maxResults=3 (default), so all results are shown. */
41- class TestBugBResultCount extends Test , Case {
42- override predicate run ( Qnit test ) {
43- if count ( BugField f , string msg | Results:: hasLimitedResult ( any ( Bug b | b = TBugB ( ) ) , f , msg ) ) =
44- 3
45- then test .pass ( "BugB: 3 results shown (exactly maxResults)" )
46- else test .fail ( "BugB: wrong result count" )
47- }
48- }
49-
50- /** BugB shows all 3 fields with no suffix since total <= maxResults. */
51- class TestBugBNoSuffix extends Test , Case {
52- override predicate run ( Qnit test ) {
53- if
54- forall ( string fieldName |
55- fieldName = [ "A" , "B" , "C" ] and
56- exists ( BugField f |
57- f .getFieldName ( ) = fieldName and
58- f .getBugName ( ) = "BugB"
59- )
60- |
61- exists ( BugField f , string msg |
62- Results:: hasLimitedResult ( any ( Bug b | b = TBugB ( ) ) , f , msg ) and
63- f .getFieldName ( ) = fieldName and
64- msg = "BugB has field " + fieldName
65- )
66- )
67- then test .pass ( "BugB: all 3 results shown with no suffix" )
68- else test .fail ( "BugB: some results have wrong message or are missing" )
69- }
15+ query predicate problems ( Bug bug , string msg , BugField field , string fieldStr ) {
16+ Results:: problems ( bug , msg , field , fieldStr )
7017}
71-
72- /** BugC has 5 fields (A, B, C, D, E), which exceeds maxResults=3 (default), so only 3 are shown. */
73- class TestBugCResultCount extends Test , Case {
74- override predicate run ( Qnit test ) {
75- if count ( BugField f , string msg | Results:: hasLimitedResult ( any ( Bug b | b = TBugC ( ) ) , f , msg ) ) =
76- 3
77- then test .pass ( "BugC: 3 results shown (capped at maxResults)" )
78- else test .fail ( "BugC: wrong result count" )
79- }
80- }
81-
82- /**
83- * BugC shows only the first 3 fields alphabetically (A, B, C), not D or E, using the default
84- * placeholderString ordering (toString() = "BugC.A", "BugC.B", ...).
85- */
86- class TestBugCTopRanked extends Test , Case {
87- override predicate run ( Qnit test ) {
88- if
89- forall ( string fieldName | fieldName = [ "A" , "B" , "C" ] |
90- exists ( BugField f |
91- Results:: hasLimitedResult ( any ( Bug b | b = TBugC ( ) ) , f , _) and
92- f .getFieldName ( ) = fieldName and
93- f .getBugName ( ) = "BugC"
94- )
95- ) and
96- not exists ( BugField f |
97- Results:: hasLimitedResult ( any ( Bug b | b = TBugC ( ) ) , f , _) and
98- f .getFieldName ( ) = [ "D" , "E" ] and
99- f .getBugName ( ) = "BugC"
100- )
101- then test .pass ( "BugC: top 3 alphabetical fields shown, D and E omitted" )
102- else test .fail ( "BugC: wrong fields shown" )
103- }
104- }
105-
106- /** BugC shows a suffix " (and 2 more)" since 5 - 3 = 2 entities are omitted. */
107- class TestBugCSuffix extends Test , Case {
108- override predicate run ( Qnit test ) {
109- if
110- forall ( BugField f , string msg |
111- Results:: hasLimitedResult ( any ( Bug b | b = TBugC ( ) ) , f , msg )
112- |
113- msg .matches ( "% (and 2 more)" )
114- )
115- then test .pass ( "BugC: all shown results have ' (and 2 more)' suffix" )
116- else test .fail ( "BugC: some results have wrong suffix" )
117- }
118- }
119-
120- /**
121- * The `problems` query predicate returns (finding, msg, entity, entityStr) tuples, where
122- * entityStr is the default placeholderString (toString()).
123- */
124- class TestProblemsQueryPredicate extends Test , Case {
125- override predicate run ( Qnit test ) {
126- if
127- // BugC: 3 problems shown, each entityStr = BugField.toString() = "BugC.<field>"
128- count ( Bug b , string msg , BugField f , string fstr |
129- Results:: problems ( b , msg , f , fstr ) and b = TBugC ( )
130- ) = 3 and
131- forall ( Bug b , string msg , BugField f , string fstr |
132- Results:: problems ( b , msg , f , fstr ) and b = TBugC ( )
133- |
134- fstr = "BugC." + f .getFieldName ( )
135- ) and
136- // BugA: 1 problem, entityStr = "BugA.X"
137- exists ( Bug b , string msg , BugField f , string fstr |
138- Results:: problems ( b , msg , f , fstr ) and
139- b = TBugA ( ) and
140- fstr = "BugA.X"
141- )
142- then test .pass ( "problems query predicate returns correct results with entityStr = toString()" )
143- else test .fail ( "problems query predicate returned unexpected results" )
144- }
145- }
146-
0 commit comments